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 : template< typename INTERFACE, typename ARGUMENT >
38 0 : ARGUMENT getSave( INTERFACE* pObject, ARGUMENT ( SAL_CALL INTERFACE::*pGetter )( ) )
39 : {
40 0 : ARGUMENT aReturn = ARGUMENT();
41 : try
42 : {
43 0 : aReturn = (pObject->*pGetter)( );
44 : }
45 0 : catch( const Exception& )
46 : {
47 : OSL_FAIL( "XSDDataType: getSave: caught an exception!" );
48 : }
49 0 : return aReturn;
50 : }
51 :
52 0 : XSDDataType::XSDDataType( const Reference< XDataType >& _rxDataType )
53 0 : :m_xDataType( _rxDataType )
54 : {
55 : DBG_ASSERT( m_xDataType.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
56 0 : if ( m_xDataType.is() )
57 0 : m_xFacetInfo = m_xDataType->getPropertySetInfo();
58 0 : }
59 :
60 :
61 0 : XSDDataType::~XSDDataType()
62 : {
63 0 : }
64 :
65 :
66 0 : sal_Int16 XSDDataType::classify() const
67 : {
68 0 : sal_Int16 nTypeClass = DataTypeClass::STRING;
69 : try
70 : {
71 0 : if ( m_xDataType.is() )
72 0 : nTypeClass = m_xDataType->getTypeClass();
73 : }
74 0 : catch( const Exception& )
75 : {
76 : OSL_FAIL( "XSDDataType::classify: caught an exception!" );
77 : }
78 0 : return nTypeClass;
79 : }
80 :
81 :
82 0 : bool XSDDataType::isBasicType() const
83 : {
84 0 : return getSave( m_xDataType.get(), &XDataType::getIsBasic );
85 : }
86 :
87 :
88 0 : OUString XSDDataType::getName() const
89 : {
90 0 : return getSave( m_xDataType.get(), &XDataType::getName );
91 : }
92 :
93 :
94 0 : void XSDDataType::setFacet( const OUString& _rFacetName, const Any& _rValue )
95 : {
96 : try
97 : {
98 0 : m_xDataType->setPropertyValue( _rFacetName, _rValue );
99 : }
100 0 : catch( const Exception& )
101 : {
102 : OSL_FAIL( "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
103 : }
104 0 : }
105 :
106 :
107 0 : bool XSDDataType::hasFacet( const OUString& _rFacetName ) const
108 : {
109 0 : bool bReturn = false;
110 : try
111 : {
112 0 : bReturn = m_xFacetInfo.is() && m_xFacetInfo->hasPropertyByName( _rFacetName );
113 : }
114 0 : catch( const Exception& )
115 : {
116 : OSL_FAIL( "XSDDataType::hasFacet: caught an exception!" );
117 : }
118 0 : return bReturn;
119 : }
120 :
121 0 : Any XSDDataType::getFacet( const OUString& _rFacetName )
122 : {
123 0 : Any aReturn;
124 : try
125 : {
126 0 : aReturn = m_xDataType->getPropertyValue( _rFacetName );
127 : }
128 0 : catch( const Exception& )
129 : {
130 : OSL_FAIL( "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
131 : }
132 0 : return aReturn;
133 : }
134 :
135 :
136 : namespace
137 : {
138 0 : void lcl_copyProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
139 : {
140 0 : Reference< XPropertySetInfo > xSourceInfo;
141 0 : if ( _rxSource.is() )
142 0 : xSourceInfo = _rxSource->getPropertySetInfo();
143 0 : Reference< XPropertySetInfo > xDestInfo;
144 0 : if ( _rxDest.is() )
145 0 : xDestInfo = _rxDest->getPropertySetInfo();
146 : OSL_ENSURE( xSourceInfo.is() && xDestInfo.is(), "lcl_copyProperties: invalid property set( info)s!" );
147 0 : if ( !xSourceInfo.is() || !xDestInfo.is() )
148 0 : return;
149 :
150 0 : Sequence< Property > aProperties( xSourceInfo->getProperties() );
151 0 : const Property* pProperties = aProperties.getConstArray();
152 0 : const Property* pPropertiesEnd = pProperties + aProperties.getLength();
153 0 : for ( ; pProperties != pPropertiesEnd; ++pProperties )
154 : {
155 0 : if ( xDestInfo->hasPropertyByName( pProperties->Name ) )
156 0 : _rxDest->setPropertyValue( pProperties->Name, _rxSource->getPropertyValue( pProperties->Name ) );
157 0 : }
158 : }
159 : }
160 :
161 :
162 0 : void XSDDataType::copyFacetsFrom( const ::rtl::Reference< XSDDataType >& _pSourceType )
163 : {
164 : OSL_ENSURE( _pSourceType.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
165 0 : if ( !_pSourceType.is() )
166 0 : return;
167 :
168 : try
169 : {
170 0 : Reference< XPropertySet > xSource( _pSourceType->getUnoDataType(), UNO_QUERY );
171 0 : Reference< XPropertySet > xDest( getUnoDataType(), UNO_QUERY );
172 0 : lcl_copyProperties( xSource, xDest );
173 : }
174 0 : catch( const Exception& )
175 : {
176 : OSL_FAIL( "XSDDataType::copyFacetsFrom: caught an exception!" );
177 : }
178 : }
179 :
180 :
181 : } // namespace pcr
182 :
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|