LCOV - code coverage report
Current view: top level - forms/source/xforms - datatyperepository.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 112 0.0 %
Date: 2012-08-25 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 262 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                 :            : 
      30                 :            : #include "datatyperepository.hxx"
      31                 :            : #include "datatypes.hxx"
      32                 :            : #include "frm_resource.hrc"
      33                 :            : #include "frm_resource.hxx"
      34                 :            : #include "frm_strings.hxx"
      35                 :            : #include "property.hrc"
      36                 :            : 
      37                 :            : #include <tools/debug.hxx>
      38                 :            : #include <comphelper/enumhelper.hxx>
      39                 :            : 
      40                 :            : #include <functional>
      41                 :            : #include <algorithm>
      42                 :            : #include <o3tl/compat_functional.hxx>
      43                 :            : 
      44                 :            : //........................................................................
      45                 :            : namespace xforms
      46                 :            : {
      47                 :            : //........................................................................
      48                 :            : 
      49                 :            :     using ::com::sun::star::uno::Reference;
      50                 :            :     using ::com::sun::star::uno::RuntimeException;
      51                 :            :     using ::com::sun::star::uno::Any;
      52                 :            :     using ::com::sun::star::uno::Type;
      53                 :            :     using ::com::sun::star::uno::makeAny;
      54                 :            :     using ::com::sun::star::uno::Sequence;
      55                 :            :     using ::com::sun::star::util::VetoException;
      56                 :            :     using ::com::sun::star::container::NoSuchElementException;
      57                 :            :     using ::com::sun::star::container::ElementExistException;
      58                 :            :     using ::com::sun::star::container::XEnumeration;
      59                 :            :     using ::com::sun::star::lang::WrappedTargetException;
      60                 :            :     using ::com::sun::star::xsd::XDataType;
      61                 :            :     using namespace frm;
      62                 :            : 
      63                 :            :     //====================================================================
      64                 :            :     //= ODataTypeRepository
      65                 :            :     //====================================================================
      66                 :            :     DBG_NAME( ODataTypeRepository )
      67                 :            :     //--------------------------------------------------------------------
      68 [ #  # ][ #  # ]:          0 :     ODataTypeRepository::ODataTypeRepository( )
      69                 :            :     {
      70                 :            :         DBG_CTOR( ODataTypeRepository, NULL );
      71                 :            : 
      72                 :            :         // insert some basic types
      73         [ #  # ]:          0 :         ::rtl::OUString sName( FRM_RES_STRING( RID_STR_DATATYPE_STRING ) );
      74 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OStringType( sName, ::com::sun::star::xsd::DataTypeClass::STRING );
                 [ #  # ]
      75                 :            : 
      76         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_URL );
      77 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OStringType( sName, ::com::sun::star::xsd::DataTypeClass::anyURI );
                 [ #  # ]
      78                 :            : 
      79         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_BOOLEAN );
      80 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OBooleanType( sName );
                 [ #  # ]
      81                 :            : 
      82         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_DECIMAL );
      83 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new ODecimalType( sName, ::com::sun::star::xsd::DataTypeClass::DECIMAL );
                 [ #  # ]
      84                 :            : 
      85         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_FLOAT );
      86 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new ODecimalType( sName, ::com::sun::star::xsd::DataTypeClass::FLOAT );
                 [ #  # ]
      87                 :            : 
      88         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_DOUBLE );
      89 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new ODecimalType( sName, ::com::sun::star::xsd::DataTypeClass::DOUBLE );
                 [ #  # ]
      90                 :            : 
      91         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_DATE );
      92 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new ODateType( sName );
                 [ #  # ]
      93                 :            : 
      94         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_TIME );
      95 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OTimeType( sName );
                 [ #  # ]
      96                 :            : 
      97         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_DATETIME );
      98 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new ODateTimeType( sName );
                 [ #  # ]
      99                 :            : 
     100         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_YEAR );
     101 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OShortIntegerType( sName, ::com::sun::star::xsd::DataTypeClass::gYear );
                 [ #  # ]
     102                 :            : 
     103         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_MONTH );
     104 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OShortIntegerType( sName, ::com::sun::star::xsd::DataTypeClass::gMonth );
                 [ #  # ]
     105                 :            : 
     106         [ #  # ]:          0 :         sName = FRM_RES_STRING( RID_STR_DATATYPE_DAY );
     107 [ #  # ][ #  # ]:          0 :         m_aRepository[ sName ] = new OShortIntegerType( sName, ::com::sun::star::xsd::DataTypeClass::gDay );
                 [ #  # ]
     108                 :          0 :     }
     109                 :            : 
     110                 :            :     //--------------------------------------------------------------------
     111         [ #  # ]:          0 :     ODataTypeRepository::~ODataTypeRepository( )
     112                 :            :     {
     113                 :            :         DBG_DTOR( ODataTypeRepository, NULL );
     114         [ #  # ]:          0 :     }
     115                 :            : 
     116                 :            :     //--------------------------------------------------------------------
     117                 :          0 :     ODataTypeRepository::Repository::iterator ODataTypeRepository::implLocate( const ::rtl::OUString& _rName, bool _bAllowMiss ) SAL_THROW( ( NoSuchElementException ) )
     118                 :            :     {
     119                 :          0 :         Repository::iterator aTypePos = m_aRepository.find( _rName );
     120 [ #  # ][ #  # ]:          0 :         if ( aTypePos == m_aRepository.end() && !_bAllowMiss )
         [ #  # ][ #  # ]
     121 [ #  # ][ #  # ]:          0 :             throw NoSuchElementException( ::rtl::OUString(), *this );
     122                 :            : 
     123                 :          0 :         return aTypePos;
     124                 :            :     }
     125                 :            : 
     126                 :            :     //--------------------------------------------------------------------
     127                 :          0 :     Reference< XDataType > SAL_CALL ODataTypeRepository::getBasicDataType( sal_Int16 dataTypeClass ) throw (NoSuchElementException, RuntimeException)
     128                 :            :     {
     129                 :          0 :         Reference< XDataType > xReturn;
     130                 :            : 
     131   [ #  #  #  # ]:          0 :         for ( Repository::const_iterator lookup = m_aRepository.begin();
                 [ #  # ]
     132 [ #  # ][ #  # ]:          0 :               ( lookup != m_aRepository.end() ) && ! xReturn.is();
     133                 :            :               ++lookup
     134                 :            :             )
     135                 :            :         {
     136 [ #  # ][ #  # ]:          0 :             if ( lookup->second->getIsBasic() && ( lookup->second->getTypeClass() == dataTypeClass ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     137 [ #  # ][ #  # ]:          0 :                 xReturn = lookup->second.get();
     138                 :            :         }
     139                 :            : 
     140         [ #  # ]:          0 :         if ( !xReturn.is() )
     141 [ #  # ][ #  # ]:          0 :             throw NoSuchElementException( ::rtl::OUString(), *this );
     142                 :            : 
     143                 :          0 :         return xReturn;
     144                 :            :     }
     145                 :            : 
     146                 :            :     //--------------------------------------------------------------------
     147                 :          0 :     Reference< XDataType > SAL_CALL ODataTypeRepository::cloneDataType( const ::rtl::OUString& sourceName, const ::rtl::OUString& newName ) throw (NoSuchElementException, ElementExistException, RuntimeException)
     148                 :            :     {
     149         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     150                 :            : 
     151         [ #  # ]:          0 :         Repository::iterator aTypePos = implLocate( newName, true );
     152         [ #  # ]:          0 :         if ( aTypePos != m_aRepository.end() )
     153 [ #  # ][ #  # ]:          0 :             throw ElementExistException( ::rtl::OUString(), *this );
     154                 :            : 
     155         [ #  # ]:          0 :         aTypePos = implLocate( sourceName );
     156         [ #  # ]:          0 :         OXSDDataType* pClone = aTypePos->second->clone( newName );
     157 [ #  # ][ #  # ]:          0 :         m_aRepository[ newName ] = pClone;
     158                 :            : 
     159 [ #  # ][ #  # ]:          0 :         return pClone;
                 [ #  # ]
     160                 :            :     }
     161                 :            : 
     162                 :            :     //--------------------------------------------------------------------
     163                 :          0 :     void SAL_CALL ODataTypeRepository::revokeDataType( const ::rtl::OUString& typeName ) throw (NoSuchElementException, VetoException, RuntimeException)
     164                 :            :     {
     165         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     166                 :            : 
     167         [ #  # ]:          0 :         Repository::iterator aTypePos = implLocate( typeName );
     168 [ #  # ][ #  # ]:          0 :         if ( aTypePos->second->getIsBasic() )
     169 [ #  # ][ #  # ]:          0 :             throw VetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "This is a built-in type and cannot be removed." ) ), *this );
                 [ #  # ]
     170                 :            :             // TODO: localize this error message
     171                 :            : 
     172 [ #  # ][ #  # ]:          0 :         m_aRepository.erase( aTypePos );
     173                 :          0 :     }
     174                 :            : 
     175                 :            :     //--------------------------------------------------------------------
     176                 :          0 :     Reference< XDataType > SAL_CALL ODataTypeRepository::getDataType( const ::rtl::OUString& typeName ) throw (NoSuchElementException, RuntimeException)
     177                 :            :     {
     178         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     179 [ #  # ][ #  # ]:          0 :         return implLocate( typeName, false )->second.get();
         [ #  # ][ #  # ]
     180                 :            :     }
     181                 :            : 
     182                 :            : 
     183                 :            :     //--------------------------------------------------------------------
     184                 :          0 :     Reference< XEnumeration > SAL_CALL ODataTypeRepository::createEnumeration(  ) throw (RuntimeException)
     185                 :            :     {
     186 [ #  # ][ #  # ]:          0 :         return new ::comphelper::OEnumerationByName( this );
                 [ #  # ]
     187                 :            :     }
     188                 :            : 
     189                 :            :     //--------------------------------------------------------------------
     190                 :          0 :     Any SAL_CALL ODataTypeRepository::getByName( const ::rtl::OUString& aName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException)
     191                 :            :     {
     192         [ #  # ]:          0 :         return makeAny( getDataType( aName ) );
     193                 :            :     }
     194                 :            : 
     195                 :            :     //--------------------------------------------------------------------
     196                 :          0 :     Sequence< ::rtl::OUString > SAL_CALL ODataTypeRepository::getElementNames(  ) throw (RuntimeException)
     197                 :            :     {
     198         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     199                 :            : 
     200         [ #  # ]:          0 :         Sequence< ::rtl::OUString > aNames( m_aRepository.size() );
     201                 :            :         ::std::transform(
     202                 :            :             m_aRepository.begin(),
     203                 :            :             m_aRepository.end(),
     204                 :            :             aNames.getArray(),
     205                 :            :             ::o3tl::select1st< Repository::value_type >()
     206 [ #  # ][ #  # ]:          0 :         );
     207         [ #  # ]:          0 :         return aNames;
     208                 :            :     }
     209                 :            : 
     210                 :            :     //--------------------------------------------------------------------
     211                 :          0 :     sal_Bool SAL_CALL ODataTypeRepository::hasByName( const ::rtl::OUString& aName ) throw (RuntimeException)
     212                 :            :     {
     213         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     214 [ #  # ][ #  # ]:          0 :         return m_aRepository.find( aName ) != m_aRepository.end();
     215                 :            :     }
     216                 :            : 
     217                 :            :     //--------------------------------------------------------------------
     218                 :          0 :     Type SAL_CALL ODataTypeRepository::getElementType(  ) throw (RuntimeException)
     219                 :            :     {
     220                 :          0 :         return ::getCppuType( static_cast< Reference< XDataType >* >( NULL ) );
     221                 :            :     }
     222                 :            : 
     223                 :            :     //--------------------------------------------------------------------
     224                 :          0 :     sal_Bool SAL_CALL ODataTypeRepository::hasElements(  ) throw (RuntimeException)
     225                 :            :     {
     226                 :          0 :         return !m_aRepository.empty();
     227                 :            :     }
     228                 :            : 
     229                 :            :     //--------------------------------------------------------------------
     230                 :            :     // type specific implementation of registerProperties, using explicit
     231                 :            :     // template instantiations
     232                 :            : 
     233                 :            :     template<>
     234                 :          0 :     void OValueLimitedType<com::sun::star::util::Date>::registerProperties()
     235                 :            :     {
     236                 :          0 :         OValueLimitedType_Base::registerProperties();
     237                 :            : 
     238         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_DATE, m_aMaxInclusive, ValueType );
     239         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_DATE, m_aMaxExclusive, ValueType );
     240         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_DATE, m_aMinInclusive, ValueType );
     241         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_DATE, m_aMinExclusive, ValueType );
     242                 :          0 :     }
     243                 :            : 
     244                 :            :     template<>
     245                 :          0 :     void OValueLimitedType<com::sun::star::util::Time>::registerProperties()
     246                 :            :     {
     247                 :          0 :         OValueLimitedType_Base::registerProperties();
     248                 :            : 
     249         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_TIME, m_aMaxInclusive, ValueType );
     250         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_TIME, m_aMaxExclusive, ValueType );
     251         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_TIME, m_aMinInclusive, ValueType );
     252         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_TIME, m_aMinExclusive, ValueType );
     253                 :          0 :     }
     254                 :            : 
     255                 :            :     template<>
     256                 :          0 :     void OValueLimitedType<com::sun::star::util::DateTime>::registerProperties()
     257                 :            :     {
     258                 :          0 :         OValueLimitedType_Base::registerProperties();
     259                 :            : 
     260         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_DATE_TIME, m_aMaxInclusive, ValueType );
     261         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_DATE_TIME, m_aMaxExclusive, ValueType );
     262         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_DATE_TIME, m_aMinInclusive, ValueType );
     263         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_DATE_TIME, m_aMinExclusive, ValueType );
     264                 :          0 :     }
     265                 :            : 
     266                 :            :     template<>
     267                 :          0 :     void OValueLimitedType<double>::registerProperties()
     268                 :            :     {
     269                 :          0 :         OValueLimitedType_Base::registerProperties();
     270                 :            : 
     271         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_DOUBLE, m_aMaxInclusive, ValueType );
     272         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_DOUBLE, m_aMaxExclusive, ValueType );
     273         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_DOUBLE, m_aMinInclusive, ValueType );
     274         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_DOUBLE, m_aMinExclusive, ValueType );
     275                 :          0 :     }
     276                 :            : 
     277                 :            :     template<>
     278                 :          0 :     void OValueLimitedType<sal_Int16>::registerProperties()
     279                 :            :     {
     280                 :          0 :         OValueLimitedType_Base::registerProperties();
     281                 :            : 
     282         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_INT, m_aMaxInclusive, ValueType );
     283         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_INT, m_aMaxExclusive, ValueType );
     284         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_INT, m_aMinInclusive, ValueType );
     285         [ #  # ]:          0 :         REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_INT, m_aMinExclusive, ValueType );
     286                 :          0 :     }
     287                 :            : //........................................................................
     288                 :            : } // namespace xforms
     289                 :            : //........................................................................
     290                 :            : 
     291                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10