LibreOffice Module chart2 (master) 1
WrappedPropertySet.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
22
24#include <sal/log.hxx>
25
26namespace chart
27{
28
29using namespace ::com::sun::star;
30using ::com::sun::star::uno::Reference;
31using ::com::sun::star::uno::Sequence;
32using ::com::sun::star::uno::Any;
33
35{
36}
38{
40}
41
43{
45}
46
48{
49 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
50
53
54 m_xInfo = nullptr;
55}
56
57//XPropertySet
59{
61 if( !xInfo.is() )
62 {
63 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
64 xInfo = m_xInfo;
65 if( !xInfo.is() )
66 {
68 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
69 m_xInfo = xInfo;
70 }
71 }
72 else
73 {
74 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
75 }
76 return m_xInfo;
77}
78
79void SAL_CALL WrappedPropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
80{
81 try
82 {
83 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
84 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
86 if( pWrappedProperty )
87 pWrappedProperty->setPropertyValue( rValue, xInnerPropertySet );
88 else if( xInnerPropertySet.is() )
89 xInnerPropertySet->setPropertyValue( rPropertyName, rValue );
90 else
91 {
92 SAL_WARN("chart2.tools", "found no inner property set to map to");
93 }
94 }
95 catch( const beans::UnknownPropertyException& )
96 {
97 throw;
98 }
99 catch( const beans::PropertyVetoException& )
100 {
101 throw;
102 }
103 catch( const lang::IllegalArgumentException& )
104 {
105 throw;
106 }
107 catch( const lang::WrappedTargetException& )
108 {
109 throw;
110 }
111 catch( const uno::RuntimeException& )
112 {
113 throw;
114 }
115 catch( const uno::Exception& ex )
116 {
117 css::uno::Any anyEx = cppu::getCaughtException();
118 TOOLS_WARN_EXCEPTION( "chart2", "invalid exception caught in WrappedPropertySet::setPropertyValue");
119 throw lang::WrappedTargetException( ex.Message, nullptr, anyEx );
120 }
121}
122Any SAL_CALL WrappedPropertySet::getPropertyValue( const OUString& rPropertyName )
123{
124 Any aRet;
125
126 try
127 {
128 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
129 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
131 if( pWrappedProperty )
132 aRet = pWrappedProperty->getPropertyValue( xInnerPropertySet );
133 else if( xInnerPropertySet.is() )
134 aRet = xInnerPropertySet->getPropertyValue( rPropertyName );
135 else
136 {
137 SAL_WARN("chart2.tools", "found no inner property set to map to");
138 }
139 }
140 catch( const beans::UnknownPropertyException& )
141 {
142 throw;
143 }
144 catch( const lang::WrappedTargetException& )
145 {
146 throw;
147 }
148 catch( const uno::RuntimeException& )
149 {
150 throw;
151 }
152 catch( const uno::Exception& ex )
153 {
154 css::uno::Any anyEx = cppu::getCaughtException();
155 TOOLS_WARN_EXCEPTION( "chart2", "invalid exception caught in WrappedPropertySet::setPropertyValue");
156 throw lang::WrappedTargetException( ex.Message, nullptr, anyEx );
157 }
158
159 return aRet;
160}
161
162void SAL_CALL WrappedPropertySet::addPropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener )
163{
165 if( xInnerPropertySet.is() )
166 {
167 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
168 if( pWrappedProperty )
169 xInnerPropertySet->addPropertyChangeListener( pWrappedProperty->getInnerName(), xListener );
170 else
171 xInnerPropertySet->addPropertyChangeListener( rPropertyName, xListener );
172 }
173}
174void SAL_CALL WrappedPropertySet::removePropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& aListener )
175{
177 if( xInnerPropertySet.is() )
178 {
179 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
180 if( pWrappedProperty )
181 xInnerPropertySet->removePropertyChangeListener( pWrappedProperty->getInnerName(), aListener );
182 else
183 xInnerPropertySet->removePropertyChangeListener( rPropertyName, aListener );
184 }
185}
186void SAL_CALL WrappedPropertySet::addVetoableChangeListener( const OUString& rPropertyName, const Reference< beans::XVetoableChangeListener >& aListener )
187{
189 if( xInnerPropertySet.is() )
190 {
191 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
192 if( pWrappedProperty )
193 xInnerPropertySet->addVetoableChangeListener( pWrappedProperty->getInnerName(), aListener );
194 else
195 xInnerPropertySet->addVetoableChangeListener( rPropertyName, aListener );
196 }
197}
198void SAL_CALL WrappedPropertySet::removeVetoableChangeListener( const OUString& rPropertyName, const Reference< beans::XVetoableChangeListener >& aListener )
199{
201 if( xInnerPropertySet.is() )
202 {
203 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
204 if( pWrappedProperty )
205 xInnerPropertySet->removeVetoableChangeListener( pWrappedProperty->getInnerName(), aListener );
206 else
207 xInnerPropertySet->removeVetoableChangeListener( rPropertyName, aListener );
208 }
209}
210
211//XMultiPropertySet
212void SAL_CALL WrappedPropertySet::setPropertyValues( const Sequence< OUString >& rNameSeq, const Sequence< Any >& rValueSeq )
213{
214 bool bUnknownProperty = false;
215 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
216 for(sal_Int32 nN=0; nN<nMinCount; nN++)
217 {
218 OUString aPropertyName( rNameSeq[nN] );
219 try
220 {
221 setPropertyValue( aPropertyName, rValueSeq[nN] );
222 }
223 catch( const beans::UnknownPropertyException& )
224 {
225 DBG_UNHANDLED_EXCEPTION("chart2");
226 bUnknownProperty = true;
227 }
228 }
229 //todo: store unknown properties elsewhere
230 OSL_ENSURE(!bUnknownProperty,"unknown property");
231// if( bUnknownProperty )
232// throw beans::UnknownPropertyException();
233}
235{
236 Sequence< Any > aRetSeq;
237 if( rNameSeq.hasElements() )
238 {
239 aRetSeq.realloc( rNameSeq.getLength() );
240 auto pRetSeq = aRetSeq.getArray();
241 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
242 {
243 try
244 {
245 OUString aPropertyName( rNameSeq[nN] );
246 pRetSeq[nN] = getPropertyValue( aPropertyName );
247 }
248 catch( const beans::UnknownPropertyException& )
249 {
250 DBG_UNHANDLED_EXCEPTION("chart2");
251 }
252 catch( const lang::WrappedTargetException& )
253 {
254 DBG_UNHANDLED_EXCEPTION("chart2");
255 }
256 }
257 }
258 return aRetSeq;
259}
261{
262 OSL_FAIL("not implemented yet");
263 //todo
264}
266{
267 OSL_FAIL("not implemented yet");
268 //todo
269}
271{
272 OSL_FAIL("not implemented yet");
273 //todo
274}
275
276//XPropertyState
277beans::PropertyState SAL_CALL WrappedPropertySet::getPropertyState( const OUString& rPropertyName )
278{
279 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
280
282 if( xInnerPropertyState.is() )
283 {
284 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
285 if( pWrappedProperty )
286 aState = pWrappedProperty->getPropertyState( xInnerPropertyState );
287 else
288 aState = xInnerPropertyState->getPropertyState( rPropertyName );
289 }
290 return aState;
291}
292
293const WrappedProperty* WrappedPropertySet::getWrappedProperty( const OUString& rOuterName )
294{
295 sal_Int32 nHandle = getInfoHelper().getHandleByName( rOuterName );
296 return getWrappedProperty( nHandle );
297}
298
300{
301 tWrappedPropertyMap::const_iterator aFound( getWrappedPropertyMap().find( nHandle ) );
302 if( aFound != getWrappedPropertyMap().end() )
303 return (*aFound).second.get();
304 return nullptr;
305}
306
308{
310 if( rNameSeq.hasElements() )
311 {
312 aRetSeq.realloc( rNameSeq.getLength() );
313 auto pRetSeq = aRetSeq.getArray();
314 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
315 {
316 OUString aPropertyName( rNameSeq[nN] );
317 pRetSeq[nN] = getPropertyState( aPropertyName );
318 }
319 }
320 return aRetSeq;
321}
322
323void SAL_CALL WrappedPropertySet::setPropertyToDefault( const OUString& rPropertyName )
324{
326 if( xInnerPropertyState.is() )
327 {
328 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
329 if( pWrappedProperty )
330 pWrappedProperty->setPropertyToDefault( xInnerPropertyState );
331 else
332 xInnerPropertyState->setPropertyToDefault( rPropertyName );
333 }
334}
335Any SAL_CALL WrappedPropertySet::getPropertyDefault( const OUString& rPropertyName )
336{
337 Any aRet;
339 if( xInnerPropertyState.is() )
340 {
341 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
342 if( pWrappedProperty )
343 aRet = pWrappedProperty->getPropertyDefault(xInnerPropertyState);
344 else
345 aRet = xInnerPropertyState->getPropertyDefault( rPropertyName );
346 }
347 return aRet;
348}
349
350//XMultiPropertyStates
352{
354 for(beans::Property const & prop : rPropSeq)
355 {
356 setPropertyToDefault( prop.Name );
357 }
358}
360{
361 for(OUString const & s : rNameSeq)
362 {
364 }
365}
367{
368 Sequence< Any > aRetSeq;
369 if( rNameSeq.hasElements() )
370 {
371 aRetSeq.realloc( rNameSeq.getLength() );
372 auto pRetSeq = aRetSeq.getArray();
373 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
374 {
375 OUString aPropertyName( rNameSeq[nN] );
376 pRetSeq[nN] = getPropertyDefault( aPropertyName );
377 }
378 }
379 return aRetSeq;
380}
381
383{
385 if(!p)
386 {
387 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
389 if(!p)
390 {
391 p = new ::cppu::OPropertyArrayHelper( getPropertySequence(), true );
392 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
394 }
395 }
396 else
397 {
398 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
399 }
401}
402
404{
406 if(!p)
407 {
408 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
409 p = m_pWrappedPropertyMap.get();
410 if(!p)
411 {
412 std::vector< std::unique_ptr<WrappedProperty> > aPropList( createWrappedProperties() );
414
415 for (auto & elem : aPropList)
416 {
417 sal_Int32 nHandle = getInfoHelper().getHandleByName( elem->getOuterName() );
418
419 if( nHandle == -1 )
420 {
421 OSL_FAIL( "missing property in property list" );
422 }
423 else if( p->find( nHandle ) != p->end() )
424 {
425 //duplicate Wrapped property
426 OSL_FAIL( "duplicate Wrapped property" );
427 }
428 else
429 (*p)[ nHandle ] = std::move(elem);
430 }
431
432 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
434 }
435 }
436 else
437 {
438 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
439 }
440 return *m_pWrappedPropertyMap;
441}
442
443} //namespace chart
444
445/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const css::uno::Sequence< css::beans::Property > & getPropertySequence()=0
give all the properties that should be visible to the outer side
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
virtual void SAL_CALL setPropertiesToDefault(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
virtual std::vector< std::unique_ptr< WrappedProperty > > createWrappedProperties()=0
give a list of all properties that need a special treatment; properties that are not in this list wil...
virtual void SAL_CALL setAllPropertiesToDefault() override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Sequence< css::uno::Any > &aValues) override
::cppu::IPropertyArrayHelper & getInfoHelper()
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
std::unique_ptr< tWrappedPropertyMap > m_pWrappedPropertyMap
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual void SAL_CALL firePropertiesChangeEvent(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
std::unique_ptr<::cppu::OPropertyArrayHelper > m_pPropertyArrayHelper
virtual ~WrappedPropertySet() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
SAL_DLLPRIVATE tWrappedPropertyMap & getWrappedPropertyMap()
const WrappedProperty * getWrappedProperty(const OUString &rOuterName)
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
SAL_DLLPRIVATE css::uno::Reference< css::beans::XPropertyState > getInnerPropertyState()
css::uno::Reference< css::beans::XPropertySetInfo > m_xInfo
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual css::uno::Reference< css::beans::XPropertySet > getInnerPropertySet()=0
virtual css::beans::PropertyState getPropertyState(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any getPropertyDefault(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any getPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const
virtual void setPropertyToDefault(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual void setPropertyValue(const css::uno::Any &rOuterValue, const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const
virtual OUString getInnerName() const
virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString &rPropertyName)=0
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
void * p
#define SAL_WARN(area, stream)
std::map< sal_Int32, std::unique_ptr< const WrappedProperty > > tWrappedPropertyMap
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
Any SAL_CALL getCaughtException()
end
sal_Int32 nHandle