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 :
28 : //........................................................................
29 : namespace pcr
30 : {
31 : //........................................................................
32 :
33 : using namespace ::com::sun::star::uno;
34 : using namespace ::com::sun::star::xsd;
35 : using namespace ::com::sun::star::beans;
36 :
37 : //====================================================================
38 : //= helper
39 : //====================================================================
40 : //--------------------------------------------------------------------
41 : template< typename INTERFACE, typename ARGUMENT >
42 : void setSave( INTERFACE* pObject, void ( SAL_CALL INTERFACE::*pSetter )( ARGUMENT ), ARGUMENT _rArg )
43 : {
44 : try
45 : {
46 : (pObject->*pSetter)( _rArg );
47 : }
48 : catch( const Exception& )
49 : {
50 : OSL_FAIL( "XSDDataType: setSave: caught an exception!" );
51 : }
52 : }
53 :
54 : //--------------------------------------------------------------------
55 : template< typename INTERFACE, typename ARGUMENT >
56 0 : ARGUMENT getSave( INTERFACE* pObject, ARGUMENT ( SAL_CALL INTERFACE::*pGetter )( ) )
57 : {
58 0 : ARGUMENT aReturn = ARGUMENT();
59 : try
60 : {
61 0 : aReturn = (pObject->*pGetter)( );
62 : }
63 0 : catch( const Exception& )
64 : {
65 : OSL_FAIL( "XSDDataType: getSave: caught an exception!" );
66 : }
67 0 : return aReturn;
68 : }
69 :
70 : template< typename FACETTYPE >
71 : FACETTYPE getFacet( const Reference< XPropertySet >& _rxFacets, const ::rtl::OUString& _rFacetName ) SAL_THROW(())
72 : {
73 : FACETTYPE aReturn;
74 : try
75 : {
76 : OSL_VERIFY( _rxFacets->getPropertyValue( _rFacetName ) >>= aReturn );
77 : }
78 : catch( const Exception& )
79 : {
80 : OSL_FAIL( "XSDDataType: getFacet: caught an exception!" );
81 : }
82 : return aReturn;
83 : }
84 :
85 : //====================================================================
86 : //= XSDDataType
87 : //====================================================================
88 : //--------------------------------------------------------------------
89 0 : XSDDataType::XSDDataType( const Reference< XDataType >& _rxDataType )
90 : :m_xDataType( _rxDataType )
91 0 : ,m_refCount( 0 )
92 : {
93 : DBG_ASSERT( m_xDataType.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
94 0 : if ( m_xDataType.is() )
95 0 : m_xFacetInfo = m_xDataType->getPropertySetInfo();
96 0 : }
97 :
98 : //--------------------------------------------------------------------
99 0 : oslInterlockedCount SAL_CALL XSDDataType::acquire()
100 : {
101 0 : return osl_atomic_increment( &m_refCount );
102 : }
103 :
104 : //--------------------------------------------------------------------
105 0 : oslInterlockedCount SAL_CALL XSDDataType::release()
106 : {
107 0 : if ( 0 == osl_atomic_decrement( &m_refCount ) )
108 : {
109 0 : delete this;
110 0 : return 0;
111 : }
112 0 : return m_refCount;
113 : }
114 :
115 : //--------------------------------------------------------------------
116 0 : XSDDataType::~XSDDataType()
117 : {
118 0 : }
119 :
120 : //--------------------------------------------------------------------
121 0 : sal_Int16 XSDDataType::classify() const SAL_THROW(())
122 : {
123 0 : sal_Int16 nTypeClass = DataTypeClass::STRING;
124 : try
125 : {
126 0 : if ( m_xDataType.is() )
127 0 : nTypeClass = m_xDataType->getTypeClass();
128 : }
129 0 : catch( const Exception& )
130 : {
131 : OSL_FAIL( "XSDDataType::classify: caught an exception!" );
132 : }
133 0 : return nTypeClass;
134 : }
135 :
136 : //--------------------------------------------------------------------
137 0 : bool XSDDataType::isBasicType() const SAL_THROW(())
138 : {
139 0 : return getSave( m_xDataType.get(), &XDataType::getIsBasic );
140 : }
141 :
142 : //--------------------------------------------------------------------
143 0 : ::rtl::OUString XSDDataType::getName() const SAL_THROW(())
144 : {
145 0 : return getSave( m_xDataType.get(), &XDataType::getName );
146 : }
147 :
148 : //--------------------------------------------------------------------
149 0 : void XSDDataType::setFacet( const ::rtl::OUString& _rFacetName, const Any& _rValue ) SAL_THROW(())
150 : {
151 : try
152 : {
153 0 : m_xDataType->setPropertyValue( _rFacetName, _rValue );
154 : }
155 0 : catch( const Exception& )
156 : {
157 : OSL_FAIL( "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
158 : }
159 0 : }
160 :
161 : //--------------------------------------------------------------------
162 0 : bool XSDDataType::hasFacet( const ::rtl::OUString& _rFacetName ) const SAL_THROW(())
163 : {
164 0 : bool bReturn = false;
165 : try
166 : {
167 0 : bReturn = m_xFacetInfo.is() && m_xFacetInfo->hasPropertyByName( _rFacetName );
168 : }
169 0 : catch( const Exception& )
170 : {
171 : OSL_FAIL( "XSDDataType::hasFacet: caught an exception!" );
172 : }
173 0 : return bReturn;
174 : }
175 : //--------------------------------------------------------------------
176 0 : Any XSDDataType::getFacet( const ::rtl::OUString& _rFacetName ) SAL_THROW(())
177 : {
178 0 : Any aReturn;
179 : try
180 : {
181 0 : aReturn = m_xDataType->getPropertyValue( _rFacetName );
182 : }
183 0 : catch( const Exception& )
184 : {
185 : OSL_FAIL( "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
186 : }
187 0 : return aReturn;
188 : }
189 :
190 : //--------------------------------------------------------------------
191 : namespace
192 : {
193 0 : void lcl_copyProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
194 : {
195 0 : Reference< XPropertySetInfo > xSourceInfo;
196 0 : if ( _rxSource.is() )
197 0 : xSourceInfo = _rxSource->getPropertySetInfo();
198 0 : Reference< XPropertySetInfo > xDestInfo;
199 0 : if ( _rxDest.is() )
200 0 : xDestInfo = _rxDest->getPropertySetInfo();
201 : OSL_ENSURE( xSourceInfo.is() && xDestInfo.is(), "lcl_copyProperties: invalid property set( info)s!" );
202 0 : if ( !xSourceInfo.is() || !xDestInfo.is() )
203 0 : return;
204 :
205 0 : Sequence< Property > aProperties( xSourceInfo->getProperties() );
206 0 : const Property* pProperties = aProperties.getConstArray();
207 0 : const Property* pPropertiesEnd = pProperties + aProperties.getLength();
208 0 : for ( ; pProperties != pPropertiesEnd; ++pProperties )
209 : {
210 0 : if ( xDestInfo->hasPropertyByName( pProperties->Name ) )
211 0 : _rxDest->setPropertyValue( pProperties->Name, _rxSource->getPropertyValue( pProperties->Name ) );
212 0 : }
213 : }
214 : }
215 :
216 : //--------------------------------------------------------------------
217 0 : void XSDDataType::copyFacetsFrom( const ::rtl::Reference< XSDDataType >& _pSourceType )
218 : {
219 : OSL_ENSURE( _pSourceType.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
220 0 : if ( !_pSourceType.is() )
221 0 : return;
222 :
223 : try
224 : {
225 0 : Reference< XPropertySet > xSource( _pSourceType->getUnoDataType(), UNO_QUERY );
226 0 : Reference< XPropertySet > xDest( getUnoDataType(), UNO_QUERY );
227 0 : lcl_copyProperties( xSource, xDest );
228 : }
229 0 : catch( const Exception& )
230 : {
231 : OSL_FAIL( "XSDDataType::copyFacetsFrom: caught an exception!" );
232 : }
233 : }
234 :
235 : //........................................................................
236 : } // namespace pcr
237 : //........................................................................
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|