1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "xsddatatypes.hxx"
31 #include "formstrings.hxx"
33 /** === begin UNO includes === **/
34 #include <com/sun/star/xsd/DataTypeClass.hpp>
35 #include <com/sun/star/xsd/XDataType.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 /** === end UNO includes === **/
38 #include <tools/debug.hxx>
40 //........................................................................
43 //........................................................................
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::xsd
;
47 using namespace ::com::sun::star::beans
;
49 //====================================================================
51 //====================================================================
52 //--------------------------------------------------------------------
53 template< typename INTERFACE
, typename ARGUMENT
>
54 void setSave( INTERFACE
* pObject
, void ( SAL_CALL
INTERFACE::*pSetter
)( ARGUMENT
), ARGUMENT _rArg
)
58 (pObject
->*pSetter
)( _rArg
);
60 catch( const Exception
& )
62 OSL_ENSURE( sal_False
, "XSDDataType: setSave: caught an exception!" );
66 //--------------------------------------------------------------------
67 template< typename INTERFACE
, typename ARGUMENT
>
68 ARGUMENT
getSave( INTERFACE
* pObject
, ARGUMENT ( SAL_CALL
INTERFACE::*pGetter
)( ) )
70 ARGUMENT aReturn
= ARGUMENT();
73 aReturn
= (pObject
->*pGetter
)( );
75 catch( const Exception
& )
77 OSL_ENSURE( sal_False
, "XSDDataType: getSave: caught an exception!" );
82 template< typename FACETTYPE
>
83 FACETTYPE
getFacet( const Reference
< XPropertySet
>& _rxFacets
, const ::rtl::OUString
& _rFacetName
) SAL_THROW(())
88 OSL_VERIFY( _rxFacets
->getPropertyValue( _rFacetName
) >>= aReturn
);
90 catch( const Exception
& )
92 OSL_ENSURE( sal_False
, "XSDDataType: getFacet: caught an exception!" );
97 //====================================================================
99 //====================================================================
100 //--------------------------------------------------------------------
101 XSDDataType::XSDDataType( const Reference
< XDataType
>& _rxDataType
)
102 :m_xDataType( _rxDataType
)
105 DBG_ASSERT( m_xDataType
.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
106 if ( m_xDataType
.is() )
107 m_xFacetInfo
= m_xDataType
->getPropertySetInfo();
110 //--------------------------------------------------------------------
111 oslInterlockedCount SAL_CALL
XSDDataType::acquire()
113 return osl_incrementInterlockedCount( &m_refCount
);
116 //--------------------------------------------------------------------
117 oslInterlockedCount SAL_CALL
XSDDataType::release()
119 if ( 0 == osl_decrementInterlockedCount( &m_refCount
) )
127 //--------------------------------------------------------------------
128 XSDDataType::~XSDDataType()
132 //--------------------------------------------------------------------
133 sal_Int16
XSDDataType::classify() const SAL_THROW(())
135 sal_Int16 nTypeClass
= DataTypeClass::STRING
;
138 if ( m_xDataType
.is() )
139 nTypeClass
= m_xDataType
->getTypeClass();
141 catch( const Exception
& )
143 OSL_ENSURE( sal_False
, "XSDDataType::classify: caught an exception!" );
148 //--------------------------------------------------------------------
149 bool XSDDataType::isBasicType() const SAL_THROW(())
151 return getSave( m_xDataType
.get(), &XDataType::getIsBasic
);
154 //--------------------------------------------------------------------
155 ::rtl::OUString
XSDDataType::getName() const SAL_THROW(())
157 return getSave( m_xDataType
.get(), &XDataType::getName
);
160 //--------------------------------------------------------------------
161 void XSDDataType::setFacet( const ::rtl::OUString
& _rFacetName
, const Any
& _rValue
) SAL_THROW(())
165 m_xDataType
->setPropertyValue( _rFacetName
, _rValue
);
167 catch( const Exception
& )
169 OSL_ENSURE( sal_False
, "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
173 //--------------------------------------------------------------------
174 bool XSDDataType::hasFacet( const ::rtl::OUString
& _rFacetName
) const SAL_THROW(())
176 bool bReturn
= false;
179 bReturn
= m_xFacetInfo
.is() && m_xFacetInfo
->hasPropertyByName( _rFacetName
);
181 catch( const Exception
& )
183 OSL_ENSURE( sal_False
, "XSDDataType::hasFacet: caught an exception!" );
187 //--------------------------------------------------------------------
188 Any
XSDDataType::getFacet( const ::rtl::OUString
& _rFacetName
) SAL_THROW(())
193 aReturn
= m_xDataType
->getPropertyValue( _rFacetName
);
195 catch( const Exception
& )
197 OSL_ENSURE( sal_False
, "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
202 //--------------------------------------------------------------------
205 void lcl_copyProperties( const Reference
< XPropertySet
>& _rxSource
, const Reference
< XPropertySet
>& _rxDest
)
207 Reference
< XPropertySetInfo
> xSourceInfo
;
208 if ( _rxSource
.is() )
209 xSourceInfo
= _rxSource
->getPropertySetInfo();
210 Reference
< XPropertySetInfo
> xDestInfo
;
212 xDestInfo
= _rxDest
->getPropertySetInfo();
213 OSL_ENSURE( xSourceInfo
.is() && xDestInfo
.is(), "lcl_copyProperties: invalid property set( info)s!" );
214 if ( !xSourceInfo
.is() || !xDestInfo
.is() )
217 Sequence
< Property
> aProperties( xSourceInfo
->getProperties() );
218 const Property
* pProperties
= aProperties
.getConstArray();
219 const Property
* pPropertiesEnd
= pProperties
+ aProperties
.getLength();
220 for ( ; pProperties
!= pPropertiesEnd
; ++pProperties
)
222 if ( xDestInfo
->hasPropertyByName( pProperties
->Name
) )
223 _rxDest
->setPropertyValue( pProperties
->Name
, _rxSource
->getPropertyValue( pProperties
->Name
) );
228 //--------------------------------------------------------------------
229 void XSDDataType::copyFacetsFrom( const ::rtl::Reference
< XSDDataType
>& _pSourceType
)
231 OSL_ENSURE( _pSourceType
.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
232 if ( !_pSourceType
.is() )
237 Reference
< XPropertySet
> xSource( _pSourceType
->getUnoDataType(), UNO_QUERY
);
238 Reference
< XPropertySet
> xDest( getUnoDataType(), UNO_QUERY
);
239 lcl_copyProperties( xSource
, xDest
);
241 catch( const Exception
& )
243 OSL_ENSURE( sal_False
, "XSDDataType::copyFacetsFrom: caught an exception!" );
247 //........................................................................
249 //........................................................................