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 .
21 #include "comphelper/propertysetinfo.hxx"
22 #include "comphelper/propertysethelper.hxx"
24 ///////////////////////////////////////////////////////////////////////
26 using namespace ::rtl
;
27 using namespace ::comphelper
;
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::lang
;
35 class PropertySetHelperImpl
38 PropertyMapEntry
* find( const OUString
& aName
) const throw();
40 PropertySetInfo
* mpInfo
;
44 PropertyMapEntry
* PropertySetHelperImpl::find( const OUString
& aName
) const throw()
46 PropertyMap::const_iterator aIter
= mpInfo
->getPropertyMap()->find( aName
);
48 if( mpInfo
->getPropertyMap()->end() != aIter
)
50 return (*aIter
).second
;
58 ///////////////////////////////////////////////////////////////////////
60 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
) throw()
62 mp
= new PropertySetHelperImpl
;
67 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo
* pInfo
, __sal_NoAcquire
) throw()
69 mp
= new PropertySetHelperImpl
;
73 PropertySetHelper::~PropertySetHelper() throw()
75 mp
->mpInfo
->release();
80 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException
)
85 void SAL_CALL
PropertySetHelper::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
87 PropertyMapEntry
* aEntries
[2];
88 aEntries
[0] = mp
->find( aPropertyName
);
90 if( NULL
== aEntries
[0] )
91 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
95 _setPropertyValues( (const PropertyMapEntry
**)aEntries
, &aValue
);
98 Any SAL_CALL
PropertySetHelper::getPropertyValue( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
100 PropertyMapEntry
* aEntries
[2];
101 aEntries
[0] = mp
->find( PropertyName
);
103 if( NULL
== aEntries
[0] )
104 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
109 _getPropertyValues( (const PropertyMapEntry
**)aEntries
, &aAny
);
114 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
119 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
124 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
129 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
135 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw(PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
137 const sal_Int32 nCount
= aPropertyNames
.getLength();
139 if( nCount
!= aValues
.getLength() )
140 throw IllegalArgumentException();
144 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
145 pEntries
[nCount
] = NULL
;
146 const OUString
* pNames
= aPropertyNames
.getConstArray();
148 sal_Bool bUnknown
= sal_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
, aValues
.getConstArray() );
162 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
166 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
) throw(RuntimeException
)
168 const sal_Int32 nCount
= aPropertyNames
.getLength();
170 Sequence
< Any
> aValues
;
173 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
174 pEntries
[nCount
] = NULL
;
175 const OUString
* pNames
= aPropertyNames
.getConstArray();
177 sal_Bool bUnknown
= sal_False
;
179 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
181 pEntries
[n
] = mp
->find( *pNames
);
182 bUnknown
= NULL
== pEntries
[n
];
187 aValues
.realloc(nCount
);
188 _getPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getArray() );
194 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
200 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
205 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
210 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw(RuntimeException
)
216 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
218 PropertyMapEntry
* aEntries
[2];
220 aEntries
[0] = mp
->find( PropertyName
);
221 if( aEntries
[0] == NULL
)
222 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
226 PropertyState aState
;
227 _getPropertyStates( (const PropertyMapEntry
**)aEntries
, &aState
);
232 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< ::rtl::OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
)
234 const sal_Int32 nCount
= aPropertyName
.getLength();
236 Sequence
< PropertyState
> aStates( nCount
);
240 const OUString
* pNames
= aPropertyName
.getConstArray();
242 sal_Bool bUnknown
= sal_False
;
244 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
247 for( n
= 0; !bUnknown
&& (n
< nCount
); n
++, pNames
++ )
249 pEntries
[n
] = mp
->find( *pNames
);
250 bUnknown
= NULL
== pEntries
[n
];
253 pEntries
[nCount
] = NULL
;
256 _getPropertyStates( (const PropertyMapEntry
**)pEntries
, aStates
.getArray() );
261 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
267 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
269 PropertyMapEntry
*pEntry
= mp
->find( PropertyName
);
271 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
273 _setPropertyToDefault( pEntry
);
276 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const ::rtl::OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
278 PropertyMapEntry
* pEntry
= mp
->find( aPropertyName
);
280 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
282 return _getPropertyDefault( pEntry
);
285 void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry
**, PropertyState
* ) throw(UnknownPropertyException
)
287 OSL_FAIL( "you have to implement this yourself!");
290 void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry
* ) throw(UnknownPropertyException
)
292 OSL_FAIL( "you have to implement this yourself!");
295 Any
PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry
* ) throw(UnknownPropertyException
, WrappedTargetException
)
297 OSL_FAIL( "you have to implement this yourself!");
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */