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

Generated by: LCOV version 1.10