1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xsddatatypes.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "xsddatatypes.hxx"
34 #include "formstrings.hxx"
36 /** === begin UNO includes === **/
37 #include <com/sun/star/xsd/DataTypeClass.hpp>
38 #include <com/sun/star/xsd/XDataType.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 /** === end UNO includes === **/
41 #include <tools/debug.hxx>
43 //........................................................................
46 //........................................................................
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::xsd
;
50 using namespace ::com::sun::star::beans
;
52 //====================================================================
54 //====================================================================
55 //--------------------------------------------------------------------
56 template< typename INTERFACE
, typename ARGUMENT
>
57 void setSave( INTERFACE
* pObject
, void ( SAL_CALL
INTERFACE::*pSetter
)( ARGUMENT
), ARGUMENT _rArg
)
61 (pObject
->*pSetter
)( _rArg
);
63 catch( const Exception
& )
65 OSL_ENSURE( sal_False
, "XSDDataType: setSave: caught an exception!" );
69 //--------------------------------------------------------------------
70 template< typename INTERFACE
, typename ARGUMENT
>
71 ARGUMENT
getSave( INTERFACE
* pObject
, ARGUMENT ( SAL_CALL
INTERFACE::*pGetter
)( ) )
73 ARGUMENT aReturn
= ARGUMENT();
76 aReturn
= (pObject
->*pGetter
)( );
78 catch( const Exception
& )
80 OSL_ENSURE( sal_False
, "XSDDataType: getSave: caught an exception!" );
85 template< typename FACETTYPE
>
86 FACETTYPE
getFacet( const Reference
< XPropertySet
>& _rxFacets
, const ::rtl::OUString
& _rFacetName
) SAL_THROW(())
91 OSL_VERIFY( _rxFacets
->getPropertyValue( _rFacetName
) >>= aReturn
);
93 catch( const Exception
& )
95 OSL_ENSURE( sal_False
, "XSDDataType: getFacet: caught an exception!" );
100 //====================================================================
102 //====================================================================
103 //--------------------------------------------------------------------
104 XSDDataType::XSDDataType( const Reference
< XDataType
>& _rxDataType
)
105 :m_xDataType( _rxDataType
)
108 DBG_ASSERT( m_xDataType
.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
109 if ( m_xDataType
.is() )
110 m_xFacetInfo
= m_xDataType
->getPropertySetInfo();
113 //--------------------------------------------------------------------
114 oslInterlockedCount SAL_CALL
XSDDataType::acquire()
116 return osl_incrementInterlockedCount( &m_refCount
);
119 //--------------------------------------------------------------------
120 oslInterlockedCount SAL_CALL
XSDDataType::release()
122 if ( 0 == osl_decrementInterlockedCount( &m_refCount
) )
130 //--------------------------------------------------------------------
131 XSDDataType::~XSDDataType()
135 //--------------------------------------------------------------------
136 sal_Int16
XSDDataType::classify() const SAL_THROW(())
138 sal_Int16 nTypeClass
= DataTypeClass::STRING
;
141 if ( m_xDataType
.is() )
142 nTypeClass
= m_xDataType
->getTypeClass();
144 catch( const Exception
& )
146 OSL_ENSURE( sal_False
, "XSDDataType::classify: caught an exception!" );
151 //--------------------------------------------------------------------
152 bool XSDDataType::isBasicType() const SAL_THROW(())
154 return getSave( m_xDataType
.get(), &XDataType::getIsBasic
);
157 //--------------------------------------------------------------------
158 ::rtl::OUString
XSDDataType::getName() const SAL_THROW(())
160 return getSave( m_xDataType
.get(), &XDataType::getName
);
163 //--------------------------------------------------------------------
164 void XSDDataType::setFacet( const ::rtl::OUString
& _rFacetName
, const Any
& _rValue
) SAL_THROW(())
168 m_xDataType
->setPropertyValue( _rFacetName
, _rValue
);
170 catch( const Exception
& )
172 OSL_ENSURE( sal_False
, "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
176 //--------------------------------------------------------------------
177 bool XSDDataType::hasFacet( const ::rtl::OUString
& _rFacetName
) const SAL_THROW(())
179 bool bReturn
= false;
182 bReturn
= m_xFacetInfo
.is() && m_xFacetInfo
->hasPropertyByName( _rFacetName
);
184 catch( const Exception
& )
186 OSL_ENSURE( sal_False
, "XSDDataType::hasFacet: caught an exception!" );
190 //--------------------------------------------------------------------
191 Any
XSDDataType::getFacet( const ::rtl::OUString
& _rFacetName
) SAL_THROW(())
196 aReturn
= m_xDataType
->getPropertyValue( _rFacetName
);
198 catch( const Exception
& )
200 OSL_ENSURE( sal_False
, "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
205 //--------------------------------------------------------------------
208 void lcl_copyProperties( const Reference
< XPropertySet
>& _rxSource
, const Reference
< XPropertySet
>& _rxDest
)
210 Reference
< XPropertySetInfo
> xSourceInfo
;
211 if ( _rxSource
.is() )
212 xSourceInfo
= _rxSource
->getPropertySetInfo();
213 Reference
< XPropertySetInfo
> xDestInfo
;
215 xDestInfo
= _rxDest
->getPropertySetInfo();
216 OSL_ENSURE( xSourceInfo
.is() && xDestInfo
.is(), "lcl_copyProperties: invalid property set( info)s!" );
217 if ( !xSourceInfo
.is() || !xDestInfo
.is() )
220 Sequence
< Property
> aProperties( xSourceInfo
->getProperties() );
221 const Property
* pProperties
= aProperties
.getConstArray();
222 const Property
* pPropertiesEnd
= pProperties
+ aProperties
.getLength();
223 for ( ; pProperties
!= pPropertiesEnd
; ++pProperties
)
225 if ( xDestInfo
->hasPropertyByName( pProperties
->Name
) )
226 _rxDest
->setPropertyValue( pProperties
->Name
, _rxSource
->getPropertyValue( pProperties
->Name
) );
231 //--------------------------------------------------------------------
232 void XSDDataType::copyFacetsFrom( const ::rtl::Reference
< XSDDataType
>& _pSourceType
)
234 OSL_ENSURE( _pSourceType
.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
235 if ( !_pSourceType
.is() )
240 Reference
< XPropertySet
> xSource( _pSourceType
->getUnoDataType(), UNO_QUERY
);
241 Reference
< XPropertySet
> xDest( getUnoDataType(), UNO_QUERY
);
242 lcl_copyProperties( xSource
, xDest
);
244 catch( const Exception
& )
246 OSL_ENSURE( sal_False
, "XSDDataType::copyFacetsFrom: caught an exception!" );
250 //........................................................................
252 //........................................................................