1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 #include "comphelper/propertysetinfo.hxx"
32 #include "comphelper/propertysethelper.hxx"
34 ///////////////////////////////////////////////////////////////////////
36 using namespace ::rtl
;
37 using namespace ::comphelper
;
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::lang
;
45 class PropertySetHelperImpl
48 PropertyMapEntry
* find( const OUString
& aName
) const throw();
50 PropertySetInfo
* mpInfo
;
54 PropertyMapEntry
* PropertySetHelperImpl::find( const OUString
& aName
) const throw()
56 PropertyMap::const_iterator aIter
= mpInfo
->getPropertyMap()->find( aName
);
58 if( mpInfo
->getPropertyMap()->end() != aIter
)
60 return (*aIter
).second
;
68 ///////////////////////////////////////////////////////////////////////
70 PropertySetHelper::PropertySetHelper( )
72 mp
= new PropertySetHelperImpl
;
73 mp
->mpInfo
= new PropertySetInfo
;
74 mp
->mpInfo
->acquire();
77 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
) throw()
79 mp
= new PropertySetHelperImpl
;
84 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
, __sal_NoAcquire
) throw()
86 mp
= new PropertySetHelperImpl
;
90 PropertySetHelper::~PropertySetHelper() throw()
92 mp
->mpInfo
->release();
96 void PropertySetHelper::setInfo( comphelper::PropertySetInfo
* pInfo
) throw()
98 OSL_ENSURE( pInfo
!= NULL
, "need pInfo" );
99 OSL_ENSURE( mp
->mpInfo
!= NULL
, "where's the old pInfo?" );
101 mp
->mpInfo
->release();
103 mp
->mpInfo
->acquire();
107 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException
)
112 void SAL_CALL
PropertySetHelper::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
114 PropertyMapEntry
* aEntries
[2];
115 aEntries
[0] = mp
->find( aPropertyName
);
117 if( NULL
== aEntries
[0] )
118 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
122 _setPropertyValues( (const PropertyMapEntry
**)aEntries
, &aValue
);
125 Any SAL_CALL
PropertySetHelper::getPropertyValue( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
127 PropertyMapEntry
* aEntries
[2];
128 aEntries
[0] = mp
->find( PropertyName
);
130 if( NULL
== aEntries
[0] )
131 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
136 _getPropertyValues( (const PropertyMapEntry
**)aEntries
, &aAny
);
141 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
146 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
151 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
156 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
162 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw(PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
164 const sal_Int32 nCount
= aPropertyNames
.getLength();
166 if( nCount
!= aValues
.getLength() )
167 throw IllegalArgumentException();
171 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
172 pEntries
[nCount
] = NULL
;
173 const OUString
* pNames
= aPropertyNames
.getConstArray();
175 sal_Bool bUnknown
= sal_False
;
177 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
179 pEntries
[n
] = mp
->find( *pNames
);
180 bUnknown
= NULL
== pEntries
[n
];
184 _setPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getConstArray() );
189 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
193 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
) throw(RuntimeException
)
195 const sal_Int32 nCount
= aPropertyNames
.getLength();
197 Sequence
< Any
> aValues
;
200 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
201 pEntries
[nCount
] = NULL
;
202 const OUString
* pNames
= aPropertyNames
.getConstArray();
204 sal_Bool bUnknown
= sal_False
;
206 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
208 pEntries
[n
] = mp
->find( *pNames
);
209 bUnknown
= NULL
== pEntries
[n
];
214 aValues
.realloc(nCount
);
215 _getPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getArray() );
221 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
227 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
232 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
237 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
243 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
245 PropertyMapEntry
* aEntries
[2];
247 aEntries
[0] = mp
->find( PropertyName
);
248 if( aEntries
[0] == NULL
)
249 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
253 PropertyState aState
;
254 _getPropertyStates( (const PropertyMapEntry
**)aEntries
, &aState
);
259 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< ::rtl::OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
)
261 const sal_Int32 nCount
= aPropertyName
.getLength();
263 Sequence
< PropertyState
> aStates( nCount
);
267 const OUString
* pNames
= aPropertyName
.getConstArray();
269 sal_Bool bUnknown
= sal_False
;
271 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
274 for( n
= 0; !bUnknown
&& (n
< nCount
); n
++, pNames
++ )
276 pEntries
[n
] = mp
->find( *pNames
);
277 bUnknown
= NULL
== pEntries
[n
];
280 pEntries
[nCount
] = NULL
;
283 _getPropertyStates( (const PropertyMapEntry
**)pEntries
, aStates
.getArray() );
288 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
294 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
296 PropertyMapEntry
*pEntry
= mp
->find( PropertyName
);
298 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
300 _setPropertyToDefault( pEntry
);
303 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const ::rtl::OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
305 PropertyMapEntry
* pEntry
= mp
->find( aPropertyName
);
307 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
309 return _getPropertyDefault( pEntry
);
312 void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry
**, PropertyState
* ) throw(UnknownPropertyException
)
314 OSL_ENSURE( sal_False
, "you have to implement this yourself!");
317 void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry
* ) throw(UnknownPropertyException
)
319 OSL_ENSURE( sal_False
, "you have to implement this yourself!");
322 Any
PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry
* ) throw(UnknownPropertyException
, WrappedTargetException
)
324 OSL_ENSURE( sal_False
, "you have to implement this yourself!");