1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/propertysetinfo.hxx>
21 #include <comphelper/propertysethelper.hxx>
22 #include <osl/diagnose.h>
24 #include <boost/scoped_array.hpp>
26 using namespace ::comphelper
;
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::beans
;
30 using namespace ::com::sun::star::lang
;
34 class PropertySetHelperImpl
37 PropertyMapEntry
const * find( const OUString
& aName
) const throw();
39 PropertySetInfo
* mpInfo
;
43 PropertyMapEntry
const * PropertySetHelperImpl::find( const OUString
& aName
) const throw()
45 PropertyMap::const_iterator aIter
= mpInfo
->getPropertyMap().find( aName
);
47 if( mpInfo
->getPropertyMap().end() != aIter
)
49 return (*aIter
).second
;
59 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
) throw()
61 mp
= new PropertySetHelperImpl
;
66 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
, __sal_NoAcquire
) throw()
68 mp
= new PropertySetHelperImpl
;
72 PropertySetHelper::~PropertySetHelper() throw()
74 mp
->mpInfo
->release();
79 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
84 void SAL_CALL
PropertySetHelper::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
)
86 PropertyMapEntry
const * aEntries
[2];
87 aEntries
[0] = mp
->find( aPropertyName
);
89 if( NULL
== aEntries
[0] )
90 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
94 _setPropertyValues( (const PropertyMapEntry
**)aEntries
, &aValue
);
97 Any SAL_CALL
PropertySetHelper::getPropertyValue( const OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
99 PropertyMapEntry
const * aEntries
[2];
100 aEntries
[0] = mp
->find( PropertyName
);
102 if( NULL
== aEntries
[0] )
103 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
108 _getPropertyValues( (const PropertyMapEntry
**)aEntries
, &aAny
);
113 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
118 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
123 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
128 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
134 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rValues
)
135 throw (PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
)
137 const sal_Int32 nCount
= rPropertyNames
.getLength();
139 if( nCount
!= rValues
.getLength() )
140 throw IllegalArgumentException();
144 boost::scoped_array
<PropertyMapEntry
const *> pEntries(new PropertyMapEntry
const *[nCount
+1]);
145 pEntries
[nCount
] = NULL
;
146 const OUString
* pNames
= rPropertyNames
.getConstArray();
148 bool bUnknown
= false;
150 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
152 pEntries
[n
] = mp
->find( *pNames
);
153 bUnknown
= NULL
== pEntries
[n
];
157 _setPropertyValues( (const PropertyMapEntry
**)pEntries
.get(), rValues
.getConstArray() );
160 throw RuntimeException( *pNames
, static_cast< XPropertySet
* >( this ) );
164 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues(const Sequence
< OUString
>& rPropertyNames
)
165 throw (RuntimeException
, std::exception
)
167 const sal_Int32 nCount
= rPropertyNames
.getLength();
169 Sequence
< Any
> aValues
;
172 boost::scoped_array
<PropertyMapEntry
const *> pEntries(new PropertyMapEntry
const *[nCount
+1]);
173 pEntries
[nCount
] = NULL
;
174 const OUString
* pNames
= rPropertyNames
.getConstArray();
176 bool bUnknown
= false;
178 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
180 pEntries
[n
] = mp
->find( *pNames
);
181 bUnknown
= NULL
== pEntries
[n
];
186 aValues
.realloc(nCount
);
187 _getPropertyValues( (const PropertyMapEntry
**)pEntries
.get(), aValues
.getArray() );
191 throw RuntimeException( *pNames
, static_cast< XPropertySet
* >( this ) );
197 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
, std::exception
)
202 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
, std::exception
)
207 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
, std::exception
)
213 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
215 PropertyMapEntry
const * aEntries
[2];
217 aEntries
[0] = mp
->find( PropertyName
);
218 if( aEntries
[0] == NULL
)
219 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
223 PropertyState
aState(PropertyState_AMBIGUOUS_VALUE
);
224 _getPropertyStates( (const PropertyMapEntry
**)aEntries
, &aState
);
229 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
231 const sal_Int32 nCount
= aPropertyName
.getLength();
233 Sequence
< PropertyState
> aStates( nCount
);
237 const OUString
* pNames
= aPropertyName
.getConstArray();
239 bool bUnknown
= false;
241 boost::scoped_array
<PropertyMapEntry
const *> pEntries(new PropertyMapEntry
const *[nCount
+1]);
244 for( n
= 0; !bUnknown
&& (n
< nCount
); n
++, pNames
++ )
246 pEntries
[n
] = mp
->find( *pNames
);
247 bUnknown
= NULL
== pEntries
[n
];
250 pEntries
[nCount
] = NULL
;
253 _getPropertyStates( (const PropertyMapEntry
**)pEntries
.get(), aStates
.getArray() );
256 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
262 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
264 PropertyMapEntry
const *pEntry
= mp
->find( PropertyName
);
266 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
268 _setPropertyToDefault( pEntry
);
271 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
273 PropertyMapEntry
const * pEntry
= mp
->find( aPropertyName
);
275 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
277 return _getPropertyDefault( pEntry
);
280 void PropertySetHelper::_getPropertyStates(
281 const comphelper::PropertyMapEntry
**, PropertyState
*)
282 throw (UnknownPropertyException
, RuntimeException
)
284 OSL_FAIL( "you have to implement this yourself!");
288 PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry
*)
289 throw (UnknownPropertyException
, RuntimeException
)
291 OSL_FAIL( "you have to implement this yourself!");
294 Any
PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry
*)
295 throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
297 OSL_FAIL( "you have to implement this yourself!");
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */