LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - xsddatatypes.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 66 0.0 %
Date: 2012-08-25 Functions: 0 15 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xsddatatypes.hxx"
      30                 :            : #include "formstrings.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/xsd/DataTypeClass.hpp>
      33                 :            : #include <com/sun/star/xsd/XDataType.hpp>
      34                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      35                 :            : #include <tools/debug.hxx>
      36                 :            : 
      37                 :            : //........................................................................
      38                 :            : namespace pcr
      39                 :            : {
      40                 :            : //........................................................................
      41                 :            : 
      42                 :            :     using namespace ::com::sun::star::uno;
      43                 :            :     using namespace ::com::sun::star::xsd;
      44                 :            :     using namespace ::com::sun::star::beans;
      45                 :            : 
      46                 :            :     //====================================================================
      47                 :            :     //= helper
      48                 :            :     //====================================================================
      49                 :            :     //--------------------------------------------------------------------
      50                 :            :     template< typename INTERFACE, typename ARGUMENT >
      51                 :            :     void setSave( INTERFACE* pObject, void ( SAL_CALL INTERFACE::*pSetter )( ARGUMENT ), ARGUMENT _rArg )
      52                 :            :     {
      53                 :            :         try
      54                 :            :         {
      55                 :            :             (pObject->*pSetter)( _rArg );
      56                 :            :         }
      57                 :            :         catch( const Exception& )
      58                 :            :         {
      59                 :            :             OSL_FAIL( "XSDDataType: setSave: caught an exception!" );
      60                 :            :         }
      61                 :            :     }
      62                 :            : 
      63                 :            :     //--------------------------------------------------------------------
      64                 :            :     template< typename INTERFACE, typename ARGUMENT >
      65                 :          0 :     ARGUMENT getSave( INTERFACE* pObject, ARGUMENT ( SAL_CALL INTERFACE::*pGetter )( ) )
      66                 :            :     {
      67                 :          0 :         ARGUMENT aReturn = ARGUMENT();
      68                 :            :         try
      69                 :            :         {
      70                 :          0 :             aReturn = (pObject->*pGetter)( );
      71                 :            :         }
      72                 :          0 :         catch( const Exception& )
      73                 :            :         {
      74                 :            :             OSL_FAIL( "XSDDataType: getSave: caught an exception!" );
      75                 :            :         }
      76                 :          0 :         return aReturn;
      77                 :            :     }
      78                 :            : 
      79                 :            :     template< typename FACETTYPE >
      80                 :            :     FACETTYPE getFacet( const Reference< XPropertySet >& _rxFacets, const ::rtl::OUString& _rFacetName ) SAL_THROW(())
      81                 :            :     {
      82                 :            :         FACETTYPE aReturn;
      83                 :            :         try
      84                 :            :         {
      85                 :            :             OSL_VERIFY( _rxFacets->getPropertyValue( _rFacetName ) >>= aReturn );
      86                 :            :         }
      87                 :            :         catch( const Exception& )
      88                 :            :         {
      89                 :            :             OSL_FAIL( "XSDDataType: getFacet: caught an exception!" );
      90                 :            :         }
      91                 :            :         return aReturn;
      92                 :            :     }
      93                 :            : 
      94                 :            :     //====================================================================
      95                 :            :     //= XSDDataType
      96                 :            :     //====================================================================
      97                 :            :     //--------------------------------------------------------------------
      98                 :          0 :     XSDDataType::XSDDataType( const Reference< XDataType >& _rxDataType )
      99                 :            :         :m_xDataType( _rxDataType )
     100                 :          0 :         ,m_refCount( 0 )
     101                 :            :     {
     102                 :            :         DBG_ASSERT( m_xDataType.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
     103                 :          0 :         if ( m_xDataType.is() )
     104                 :          0 :             m_xFacetInfo = m_xDataType->getPropertySetInfo();
     105                 :          0 :     }
     106                 :            : 
     107                 :            :     //--------------------------------------------------------------------
     108                 :          0 :     oslInterlockedCount SAL_CALL XSDDataType::acquire()
     109                 :            :     {
     110                 :          0 :         return osl_incrementInterlockedCount( &m_refCount );
     111                 :            :     }
     112                 :            : 
     113                 :            :     //--------------------------------------------------------------------
     114                 :          0 :     oslInterlockedCount SAL_CALL XSDDataType::release()
     115                 :            :     {
     116                 :          0 :         if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
     117                 :            :         {
     118                 :          0 :            delete this;
     119                 :          0 :            return 0;
     120                 :            :         }
     121                 :          0 :         return m_refCount;
     122                 :            :     }
     123                 :            : 
     124                 :            :     //--------------------------------------------------------------------
     125                 :          0 :     XSDDataType::~XSDDataType()
     126                 :            :     {
     127                 :          0 :     }
     128                 :            : 
     129                 :            :     //--------------------------------------------------------------------
     130                 :          0 :     sal_Int16 XSDDataType::classify() const SAL_THROW(())
     131                 :            :     {
     132                 :          0 :         sal_Int16 nTypeClass = DataTypeClass::STRING;
     133                 :            :         try
     134                 :            :         {
     135                 :          0 :             if ( m_xDataType.is() )
     136                 :          0 :                 nTypeClass = m_xDataType->getTypeClass();
     137                 :            :         }
     138                 :          0 :         catch( const Exception& )
     139                 :            :         {
     140                 :            :             OSL_FAIL( "XSDDataType::classify: caught an exception!" );
     141                 :            :         }
     142                 :          0 :         return nTypeClass;
     143                 :            :     }
     144                 :            : 
     145                 :            :     //--------------------------------------------------------------------
     146                 :          0 :     bool XSDDataType::isBasicType() const SAL_THROW(())
     147                 :            :     {
     148                 :          0 :         return getSave( m_xDataType.get(), &XDataType::getIsBasic );
     149                 :            :     }
     150                 :            : 
     151                 :            :     //--------------------------------------------------------------------
     152                 :          0 :     ::rtl::OUString XSDDataType::getName() const SAL_THROW(())
     153                 :            :     {
     154                 :          0 :         return getSave( m_xDataType.get(), &XDataType::getName );
     155                 :            :     }
     156                 :            : 
     157                 :            :      //--------------------------------------------------------------------
     158                 :          0 :     void XSDDataType::setFacet( const ::rtl::OUString& _rFacetName, const Any& _rValue ) SAL_THROW(())
     159                 :            :     {
     160                 :            :         try
     161                 :            :         {
     162                 :          0 :             m_xDataType->setPropertyValue( _rFacetName, _rValue );
     163                 :            :         }
     164                 :          0 :         catch( const Exception& )
     165                 :            :         {
     166                 :            :             OSL_FAIL( "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
     167                 :            :         }
     168                 :          0 :     }
     169                 :            : 
     170                 :            :     //--------------------------------------------------------------------
     171                 :          0 :     bool XSDDataType::hasFacet( const ::rtl::OUString& _rFacetName ) const SAL_THROW(())
     172                 :            :     {
     173                 :          0 :         bool bReturn = false;
     174                 :            :         try
     175                 :            :         {
     176                 :          0 :             bReturn = m_xFacetInfo.is() && m_xFacetInfo->hasPropertyByName( _rFacetName );
     177                 :            :         }
     178                 :          0 :         catch( const Exception& )
     179                 :            :         {
     180                 :            :             OSL_FAIL( "XSDDataType::hasFacet: caught an exception!" );
     181                 :            :         }
     182                 :          0 :         return bReturn;
     183                 :            :     }
     184                 :            :     //--------------------------------------------------------------------
     185                 :          0 :     Any XSDDataType::getFacet( const ::rtl::OUString& _rFacetName ) SAL_THROW(())
     186                 :            :     {
     187                 :          0 :         Any aReturn;
     188                 :            :         try
     189                 :            :         {
     190                 :          0 :             aReturn = m_xDataType->getPropertyValue( _rFacetName );
     191                 :            :         }
     192                 :          0 :         catch( const Exception& )
     193                 :            :         {
     194                 :            :             OSL_FAIL( "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
     195                 :            :         }
     196                 :          0 :         return aReturn;
     197                 :            :     }
     198                 :            : 
     199                 :            :     //--------------------------------------------------------------------
     200                 :            :     namespace
     201                 :            :     {
     202                 :          0 :         void lcl_copyProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
     203                 :            :         {
     204                 :          0 :             Reference< XPropertySetInfo > xSourceInfo;
     205                 :          0 :             if ( _rxSource.is() )
     206                 :          0 :                 xSourceInfo = _rxSource->getPropertySetInfo();
     207                 :          0 :             Reference< XPropertySetInfo > xDestInfo;
     208                 :          0 :             if ( _rxDest.is() )
     209                 :          0 :                 xDestInfo = _rxDest->getPropertySetInfo();
     210                 :            :             OSL_ENSURE( xSourceInfo.is() && xDestInfo.is(), "lcl_copyProperties: invalid property set( info)s!" );
     211                 :          0 :             if ( !xSourceInfo.is() || !xDestInfo.is() )
     212                 :          0 :                 return;
     213                 :            : 
     214                 :          0 :             Sequence< Property > aProperties( xSourceInfo->getProperties() );
     215                 :          0 :             const Property* pProperties = aProperties.getConstArray();
     216                 :          0 :             const Property* pPropertiesEnd = pProperties + aProperties.getLength();
     217                 :          0 :             for ( ; pProperties != pPropertiesEnd; ++pProperties )
     218                 :            :             {
     219                 :          0 :                 if ( xDestInfo->hasPropertyByName( pProperties->Name ) )
     220                 :          0 :                     _rxDest->setPropertyValue( pProperties->Name, _rxSource->getPropertyValue( pProperties->Name ) );
     221                 :          0 :             }
     222                 :            :         }
     223                 :            :     }
     224                 :            : 
     225                 :            :     //--------------------------------------------------------------------
     226                 :          0 :     void XSDDataType::copyFacetsFrom( const ::rtl::Reference< XSDDataType >& _pSourceType )
     227                 :            :     {
     228                 :            :         OSL_ENSURE( _pSourceType.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
     229                 :          0 :         if ( !_pSourceType.is() )
     230                 :          0 :             return;
     231                 :            : 
     232                 :            :         try
     233                 :            :         {
     234                 :          0 :             Reference< XPropertySet > xSource( _pSourceType->getUnoDataType(), UNO_QUERY );
     235                 :          0 :             Reference< XPropertySet > xDest( getUnoDataType(), UNO_QUERY );
     236                 :          0 :             lcl_copyProperties( xSource, xDest );
     237                 :            :         }
     238                 :          0 :         catch( const Exception& )
     239                 :            :         {
     240                 :            :             OSL_FAIL( "XSDDataType::copyFacetsFrom: caught an exception!" );
     241                 :            :         }
     242                 :            :     }
     243                 :            : 
     244                 :            : //........................................................................
     245                 :            : } // namespace pcr
     246                 :            : //........................................................................
     247                 :            : 
     248                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10