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