1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_extensions.hxx" 26 #include "xsddatatypes.hxx" 27 #include "formstrings.hxx" 28 29 /** === begin UNO includes === **/ 30 #include <com/sun/star/xsd/DataTypeClass.hpp> 31 #include <com/sun/star/xsd/XDataType.hpp> 32 #include <com/sun/star/beans/XPropertySet.hpp> 33 /** === end UNO includes === **/ 34 #include <tools/debug.hxx> 35 36 //........................................................................ 37 namespace pcr 38 { 39 //........................................................................ 40 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::xsd; 43 using namespace ::com::sun::star::beans; 44 45 //==================================================================== 46 //= helper 47 //==================================================================== 48 //-------------------------------------------------------------------- 49 template< typename INTERFACE, typename ARGUMENT > setSave(INTERFACE * pObject,void (SAL_CALL INTERFACE::* pSetter)(ARGUMENT),ARGUMENT _rArg)50 void setSave( INTERFACE* pObject, void ( SAL_CALL INTERFACE::*pSetter )( ARGUMENT ), ARGUMENT _rArg ) 51 { 52 try 53 { 54 (pObject->*pSetter)( _rArg ); 55 } 56 catch( const Exception& ) 57 { 58 OSL_ENSURE( sal_False, "XSDDataType: setSave: caught an exception!" ); 59 } 60 } 61 62 //-------------------------------------------------------------------- 63 template< typename INTERFACE, typename ARGUMENT > getSave(INTERFACE * pObject,ARGUMENT (SAL_CALL INTERFACE::* pGetter)())64 ARGUMENT getSave( INTERFACE* pObject, ARGUMENT ( SAL_CALL INTERFACE::*pGetter )( ) ) 65 { 66 ARGUMENT aReturn = ARGUMENT(); 67 try 68 { 69 aReturn = (pObject->*pGetter)( ); 70 } 71 catch( const Exception& ) 72 { 73 OSL_ENSURE( sal_False, "XSDDataType: getSave: caught an exception!" ); 74 } 75 return aReturn; 76 } 77 78 template< typename FACETTYPE > getFacet(const Reference<XPropertySet> & _rxFacets,const::rtl::OUString & _rFacetName)79 FACETTYPE getFacet( const Reference< XPropertySet >& _rxFacets, const ::rtl::OUString& _rFacetName ) SAL_THROW(()) 80 { 81 FACETTYPE aReturn; 82 try 83 { 84 OSL_VERIFY( _rxFacets->getPropertyValue( _rFacetName ) >>= aReturn ); 85 } 86 catch( const Exception& ) 87 { 88 OSL_ENSURE( sal_False, "XSDDataType: getFacet: caught an exception!" ); 89 } 90 return aReturn; 91 } 92 93 //==================================================================== 94 //= XSDDataType 95 //==================================================================== 96 //-------------------------------------------------------------------- XSDDataType(const Reference<XDataType> & _rxDataType)97 XSDDataType::XSDDataType( const Reference< XDataType >& _rxDataType ) 98 :m_xDataType( _rxDataType ) 99 ,m_refCount( 0 ) 100 { 101 DBG_ASSERT( m_xDataType.is(), "XSDDataType::XSDDataType: invalid UNO object!" ); 102 if ( m_xDataType.is() ) 103 m_xFacetInfo = m_xDataType->getPropertySetInfo(); 104 } 105 106 //-------------------------------------------------------------------- acquire()107 oslInterlockedCount SAL_CALL XSDDataType::acquire() 108 { 109 return osl_incrementInterlockedCount( &m_refCount ); 110 } 111 112 //-------------------------------------------------------------------- release()113 oslInterlockedCount SAL_CALL XSDDataType::release() 114 { 115 if ( 0 == osl_decrementInterlockedCount( &m_refCount ) ) 116 { 117 delete this; 118 return 0; 119 } 120 return m_refCount; 121 } 122 123 //-------------------------------------------------------------------- ~XSDDataType()124 XSDDataType::~XSDDataType() 125 { 126 } 127 128 //-------------------------------------------------------------------- classify() const129 sal_Int16 XSDDataType::classify() const SAL_THROW(()) 130 { 131 sal_Int16 nTypeClass = DataTypeClass::STRING; 132 try 133 { 134 if ( m_xDataType.is() ) 135 nTypeClass = m_xDataType->getTypeClass(); 136 } 137 catch( const Exception& ) 138 { 139 OSL_ENSURE( sal_False, "XSDDataType::classify: caught an exception!" ); 140 } 141 return nTypeClass; 142 } 143 144 //-------------------------------------------------------------------- isBasicType() const145 bool XSDDataType::isBasicType() const SAL_THROW(()) 146 { 147 return getSave( m_xDataType.get(), &XDataType::getIsBasic ); 148 } 149 150 //-------------------------------------------------------------------- getName() const151 ::rtl::OUString XSDDataType::getName() const SAL_THROW(()) 152 { 153 return getSave( m_xDataType.get(), &XDataType::getName ); 154 } 155 156 //-------------------------------------------------------------------- setFacet(const::rtl::OUString & _rFacetName,const Any & _rValue)157 void XSDDataType::setFacet( const ::rtl::OUString& _rFacetName, const Any& _rValue ) SAL_THROW(()) 158 { 159 try 160 { 161 m_xDataType->setPropertyValue( _rFacetName, _rValue ); 162 } 163 catch( const Exception& ) 164 { 165 OSL_ENSURE( sal_False, "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" ); 166 } 167 } 168 169 //-------------------------------------------------------------------- hasFacet(const::rtl::OUString & _rFacetName) const170 bool XSDDataType::hasFacet( const ::rtl::OUString& _rFacetName ) const SAL_THROW(()) 171 { 172 bool bReturn = false; 173 try 174 { 175 bReturn = m_xFacetInfo.is() && m_xFacetInfo->hasPropertyByName( _rFacetName ); 176 } 177 catch( const Exception& ) 178 { 179 OSL_ENSURE( sal_False, "XSDDataType::hasFacet: caught an exception!" ); 180 } 181 return bReturn; 182 } 183 //-------------------------------------------------------------------- getFacet(const::rtl::OUString & _rFacetName)184 Any XSDDataType::getFacet( const ::rtl::OUString& _rFacetName ) SAL_THROW(()) 185 { 186 Any aReturn; 187 try 188 { 189 aReturn = m_xDataType->getPropertyValue( _rFacetName ); 190 } 191 catch( const Exception& ) 192 { 193 OSL_ENSURE( sal_False, "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" ); 194 } 195 return aReturn; 196 } 197 198 //-------------------------------------------------------------------- 199 namespace 200 { lcl_copyProperties(const Reference<XPropertySet> & _rxSource,const Reference<XPropertySet> & _rxDest)201 void lcl_copyProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest ) 202 { 203 Reference< XPropertySetInfo > xSourceInfo; 204 if ( _rxSource.is() ) 205 xSourceInfo = _rxSource->getPropertySetInfo(); 206 Reference< XPropertySetInfo > xDestInfo; 207 if ( _rxDest.is() ) 208 xDestInfo = _rxDest->getPropertySetInfo(); 209 OSL_ENSURE( xSourceInfo.is() && xDestInfo.is(), "lcl_copyProperties: invalid property set( info)s!" ); 210 if ( !xSourceInfo.is() || !xDestInfo.is() ) 211 return; 212 213 Sequence< Property > aProperties( xSourceInfo->getProperties() ); 214 const Property* pProperties = aProperties.getConstArray(); 215 const Property* pPropertiesEnd = pProperties + aProperties.getLength(); 216 for ( ; pProperties != pPropertiesEnd; ++pProperties ) 217 { 218 if ( xDestInfo->hasPropertyByName( pProperties->Name ) ) 219 _rxDest->setPropertyValue( pProperties->Name, _rxSource->getPropertyValue( pProperties->Name ) ); 220 } 221 } 222 } 223 224 //-------------------------------------------------------------------- copyFacetsFrom(const::rtl::Reference<XSDDataType> & _pSourceType)225 void XSDDataType::copyFacetsFrom( const ::rtl::Reference< XSDDataType >& _pSourceType ) 226 { 227 OSL_ENSURE( _pSourceType.is(), "XSDDataType::copyFacetsFrom: invalid source type!" ); 228 if ( !_pSourceType.is() ) 229 return; 230 231 try 232 { 233 Reference< XPropertySet > xSource( _pSourceType->getUnoDataType(), UNO_QUERY ); 234 Reference< XPropertySet > xDest( getUnoDataType(), UNO_QUERY ); 235 lcl_copyProperties( xSource, xDest ); 236 } 237 catch( const Exception& ) 238 { 239 OSL_ENSURE( sal_False, "XSDDataType::copyFacetsFrom: caught an exception!" ); 240 } 241 } 242 243 //........................................................................ 244 } // namespace pcr 245 //........................................................................ 246 247