LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - xsddatatypes.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 59 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "xsddatatypes.hxx"
      21             : #include "formstrings.hxx"
      22             : 
      23             : #include <com/sun/star/xsd/DataTypeClass.hpp>
      24             : #include <com/sun/star/xsd/XDataType.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <tools/debug.hxx>
      27             : #include <osl/diagnose.h>
      28             : 
      29             : 
      30             : namespace pcr
      31             : {
      32             : 
      33             : 
      34             :     using namespace ::com::sun::star::uno;
      35             :     using namespace ::com::sun::star::xsd;
      36             :     using namespace ::com::sun::star::beans;
      37             : 
      38             :     template< typename INTERFACE, typename ARGUMENT >
      39           0 :     ARGUMENT getSave( INTERFACE* pObject, ARGUMENT ( SAL_CALL INTERFACE::*pGetter )( ) )
      40             :     {
      41           0 :         ARGUMENT aReturn = ARGUMENT();
      42             :         try
      43             :         {
      44           0 :             aReturn = (pObject->*pGetter)( );
      45             :         }
      46           0 :         catch( const Exception& )
      47             :         {
      48             :             OSL_FAIL( "XSDDataType: getSave: caught an exception!" );
      49             :         }
      50           0 :         return aReturn;
      51             :     }
      52             : 
      53           0 :     XSDDataType::XSDDataType( const Reference< XDataType >& _rxDataType )
      54           0 :         :m_xDataType( _rxDataType )
      55             :     {
      56             :         DBG_ASSERT( m_xDataType.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
      57           0 :         if ( m_xDataType.is() )
      58           0 :             m_xFacetInfo = m_xDataType->getPropertySetInfo();
      59           0 :     }
      60             : 
      61             : 
      62           0 :     XSDDataType::~XSDDataType()
      63             :     {
      64           0 :     }
      65             : 
      66             : 
      67           0 :     sal_Int16 XSDDataType::classify() const
      68             :     {
      69           0 :         sal_Int16 nTypeClass = DataTypeClass::STRING;
      70             :         try
      71             :         {
      72           0 :             if ( m_xDataType.is() )
      73           0 :                 nTypeClass = m_xDataType->getTypeClass();
      74             :         }
      75           0 :         catch( const Exception& )
      76             :         {
      77             :             OSL_FAIL( "XSDDataType::classify: caught an exception!" );
      78             :         }
      79           0 :         return nTypeClass;
      80             :     }
      81             : 
      82             : 
      83           0 :     bool XSDDataType::isBasicType() const
      84             :     {
      85           0 :         return getSave( m_xDataType.get(), &XDataType::getIsBasic );
      86             :     }
      87             : 
      88             : 
      89           0 :     OUString XSDDataType::getName() const
      90             :     {
      91           0 :         return getSave( m_xDataType.get(), &XDataType::getName );
      92             :     }
      93             : 
      94             : 
      95           0 :     void XSDDataType::setFacet( const OUString& _rFacetName, const Any& _rValue )
      96             :     {
      97             :         try
      98             :         {
      99           0 :             m_xDataType->setPropertyValue( _rFacetName, _rValue );
     100             :         }
     101           0 :         catch( const Exception& )
     102             :         {
     103             :             OSL_FAIL( "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
     104             :         }
     105           0 :     }
     106             : 
     107             : 
     108           0 :     bool XSDDataType::hasFacet( const OUString& _rFacetName ) const
     109             :     {
     110           0 :         bool bReturn = false;
     111             :         try
     112             :         {
     113           0 :             bReturn = m_xFacetInfo.is() && m_xFacetInfo->hasPropertyByName( _rFacetName );
     114             :         }
     115           0 :         catch( const Exception& )
     116             :         {
     117             :             OSL_FAIL( "XSDDataType::hasFacet: caught an exception!" );
     118             :         }
     119           0 :         return bReturn;
     120             :     }
     121             : 
     122           0 :     Any XSDDataType::getFacet( const OUString& _rFacetName )
     123             :     {
     124           0 :         Any aReturn;
     125             :         try
     126             :         {
     127           0 :             aReturn = m_xDataType->getPropertyValue( _rFacetName );
     128             :         }
     129           0 :         catch( const Exception& )
     130             :         {
     131             :             OSL_FAIL( "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
     132             :         }
     133           0 :         return aReturn;
     134             :     }
     135             : 
     136             : 
     137             :     namespace
     138             :     {
     139           0 :         void lcl_copyProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
     140             :         {
     141           0 :             Reference< XPropertySetInfo > xSourceInfo;
     142           0 :             if ( _rxSource.is() )
     143           0 :                 xSourceInfo = _rxSource->getPropertySetInfo();
     144           0 :             Reference< XPropertySetInfo > xDestInfo;
     145           0 :             if ( _rxDest.is() )
     146           0 :                 xDestInfo = _rxDest->getPropertySetInfo();
     147             :             OSL_ENSURE( xSourceInfo.is() && xDestInfo.is(), "lcl_copyProperties: invalid property set( info)s!" );
     148           0 :             if ( !xSourceInfo.is() || !xDestInfo.is() )
     149           0 :                 return;
     150             : 
     151           0 :             Sequence< Property > aProperties( xSourceInfo->getProperties() );
     152           0 :             const Property* pProperties = aProperties.getConstArray();
     153           0 :             const Property* pPropertiesEnd = pProperties + aProperties.getLength();
     154           0 :             for ( ; pProperties != pPropertiesEnd; ++pProperties )
     155             :             {
     156           0 :                 if ( xDestInfo->hasPropertyByName( pProperties->Name ) )
     157           0 :                     _rxDest->setPropertyValue( pProperties->Name, _rxSource->getPropertyValue( pProperties->Name ) );
     158           0 :             }
     159             :         }
     160             :     }
     161             : 
     162             : 
     163           0 :     void XSDDataType::copyFacetsFrom( const ::rtl::Reference< XSDDataType >& _pSourceType )
     164             :     {
     165             :         OSL_ENSURE( _pSourceType.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
     166           0 :         if ( !_pSourceType.is() )
     167           0 :             return;
     168             : 
     169             :         try
     170             :         {
     171           0 :             Reference< XPropertySet > xSource( _pSourceType->getUnoDataType(), UNO_QUERY );
     172           0 :             Reference< XPropertySet > xDest( getUnoDataType(), UNO_QUERY );
     173           0 :             lcl_copyProperties( xSource, xDest );
     174             :         }
     175           0 :         catch( const Exception& )
     176             :         {
     177             :             OSL_FAIL( "XSDDataType::copyFacetsFrom: caught an exception!" );
     178             :         }
     179             :     }
     180             : 
     181             : 
     182             : } // namespace pcr
     183             : 
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11