1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertysethelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
34 #include "comphelper/propertysetinfo.hxx"
35 #include "comphelper/propertysethelper.hxx"
37 ///////////////////////////////////////////////////////////////////////
39 using namespace ::rtl
;
40 using namespace ::comphelper
;
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::lang
;
48 class PropertySetHelperImpl
51 PropertyMapEntry
* find( const OUString
& aName
) const throw();
53 PropertySetInfo
* mpInfo
;
57 PropertyMapEntry
* PropertySetHelperImpl::find( const OUString
& aName
) const throw()
59 PropertyMap::const_iterator aIter
= mpInfo
->getPropertyMap()->find( aName
);
61 if( mpInfo
->getPropertyMap()->end() != aIter
)
63 return (*aIter
).second
;
71 ///////////////////////////////////////////////////////////////////////
73 PropertySetHelper::PropertySetHelper( )
75 mp
= new PropertySetHelperImpl
;
76 mp
->mpInfo
= new PropertySetInfo
;
77 mp
->mpInfo
->acquire();
80 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
) throw()
82 mp
= new PropertySetHelperImpl
;
87 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
, __sal_NoAcquire
) throw()
89 mp
= new PropertySetHelperImpl
;
93 PropertySetHelper::~PropertySetHelper() throw()
95 mp
->mpInfo
->release();
99 void PropertySetHelper::setInfo( comphelper::PropertySetInfo
* pInfo
) throw()
101 OSL_ENSURE( pInfo
!= NULL
, "need pInfo" );
102 OSL_ENSURE( mp
->mpInfo
!= NULL
, "where's the old pInfo?" );
104 mp
->mpInfo
->release();
106 mp
->mpInfo
->acquire();
110 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException
)
115 void SAL_CALL
PropertySetHelper::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
117 PropertyMapEntry
* aEntries
[2];
118 aEntries
[0] = mp
->find( aPropertyName
);
120 if( NULL
== aEntries
[0] )
121 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
125 _setPropertyValues( (const PropertyMapEntry
**)aEntries
, &aValue
);
128 Any SAL_CALL
PropertySetHelper::getPropertyValue( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
130 PropertyMapEntry
* aEntries
[2];
131 aEntries
[0] = mp
->find( PropertyName
);
133 if( NULL
== aEntries
[0] )
134 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
139 _getPropertyValues( (const PropertyMapEntry
**)aEntries
, &aAny
);
144 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
149 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
154 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
159 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
165 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw(PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
167 const sal_Int32 nCount
= aPropertyNames
.getLength();
169 if( nCount
!= aValues
.getLength() )
170 throw IllegalArgumentException();
174 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
175 pEntries
[nCount
] = NULL
;
176 const OUString
* pNames
= aPropertyNames
.getConstArray();
178 sal_Bool bUnknown
= sal_False
;
180 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
182 pEntries
[n
] = mp
->find( *pNames
);
183 bUnknown
= NULL
== pEntries
[n
];
187 _setPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getConstArray() );
192 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
196 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
) throw(RuntimeException
)
198 const sal_Int32 nCount
= aPropertyNames
.getLength();
200 Sequence
< Any
> aValues
;
203 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
204 pEntries
[nCount
] = NULL
;
205 const OUString
* pNames
= aPropertyNames
.getConstArray();
207 sal_Bool bUnknown
= sal_False
;
209 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
211 pEntries
[n
] = mp
->find( *pNames
);
212 bUnknown
= NULL
== pEntries
[n
];
217 aValues
.realloc(nCount
);
218 _getPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getArray() );
224 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
230 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
235 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
240 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
246 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
248 PropertyMapEntry
* aEntries
[2];
250 aEntries
[0] = mp
->find( PropertyName
);
251 if( aEntries
[0] == NULL
)
252 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
256 PropertyState aState
;
257 _getPropertyStates( (const PropertyMapEntry
**)aEntries
, &aState
);
262 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< ::rtl::OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
)
264 const sal_Int32 nCount
= aPropertyName
.getLength();
266 Sequence
< PropertyState
> aStates( nCount
);
270 const OUString
* pNames
= aPropertyName
.getConstArray();
272 sal_Bool bUnknown
= sal_False
;
274 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
277 for( n
= 0; !bUnknown
&& (n
< nCount
); n
++, pNames
++ )
279 pEntries
[n
] = mp
->find( *pNames
);
280 bUnknown
= NULL
== pEntries
[n
];
283 pEntries
[nCount
] = NULL
;
286 _getPropertyStates( (const PropertyMapEntry
**)pEntries
, aStates
.getArray() );
291 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
297 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
299 PropertyMapEntry
*pEntry
= mp
->find( PropertyName
);
301 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
303 _setPropertyToDefault( pEntry
);
306 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const ::rtl::OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
308 PropertyMapEntry
* pEntry
= mp
->find( aPropertyName
);
310 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
312 return _getPropertyDefault( pEntry
);
315 void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry
**, PropertyState
* ) throw(UnknownPropertyException
)
317 OSL_ENSURE( sal_False
, "you have to implement this yourself!");
320 void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry
* ) throw(UnknownPropertyException
)
322 OSL_ENSURE( sal_False
, "you have to implement this yourself!");
325 Any
PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry
* ) throw(UnknownPropertyException
, WrappedTargetException
)
327 OSL_ENSURE( sal_False
, "you have to implement this yourself!");