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_unotools.hxx"
33 #include <tools/debug.hxx>
35 #include "unotools/propertysetinfo.hxx"
36 #include "unotools/propertysethelper.hxx"
38 ///////////////////////////////////////////////////////////////////////
40 using namespace ::utl
;
41 using namespace ::rtl
;
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::lang
;
49 class PropertySetHelperImpl
52 PropertyMapEntry
* find( const OUString
& aName
) const throw();
54 PropertySetInfo
* mpInfo
;
58 PropertyMapEntry
* PropertySetHelperImpl::find( const OUString
& aName
) const throw()
60 PropertyMap::const_iterator aIter
= mpInfo
->getPropertyMap()->find( aName
);
62 if( mpInfo
->getPropertyMap()->end() != aIter
)
64 return (*aIter
).second
;
72 ///////////////////////////////////////////////////////////////////////
74 PropertySetHelper::PropertySetHelper( utl::PropertySetInfo
* pInfo
) throw()
76 mp
= new PropertySetHelperImpl
;
81 PropertySetHelper::~PropertySetHelper() throw()
83 mp
->mpInfo
->release();
88 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException
)
93 void SAL_CALL
PropertySetHelper::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
95 PropertyMapEntry
* aEntries
[2];
96 aEntries
[0] = mp
->find( aPropertyName
);
98 if( NULL
== aEntries
[0] )
99 throw UnknownPropertyException();
103 _setPropertyValues( (const PropertyMapEntry
**)aEntries
, &aValue
);
106 Any SAL_CALL
PropertySetHelper::getPropertyValue( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
108 PropertyMapEntry
* aEntries
[2];
109 aEntries
[0] = mp
->find( PropertyName
);
111 if( NULL
== aEntries
[0] )
112 throw UnknownPropertyException();
117 _getPropertyValues( (const PropertyMapEntry
**)aEntries
, &aAny
);
122 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*xListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
127 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
132 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
137 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
143 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw(PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
145 const sal_Int32 nCount
= aPropertyNames
.getLength();
147 if( nCount
!= aValues
.getLength() )
148 throw IllegalArgumentException();
152 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
153 const OUString
* pNames
= aPropertyNames
.getConstArray();
155 sal_Bool bUnknown
= sal_False
;
157 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
159 pEntries
[n
] = mp
->find( *pNames
);
160 bUnknown
= NULL
== pEntries
[n
];
164 _setPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getConstArray() );
169 throw UnknownPropertyException();
173 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
) throw(RuntimeException
)
175 const sal_Int32 nCount
= aPropertyNames
.getLength();
177 Sequence
< Any
> aValues
;
180 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
181 const OUString
* pNames
= aPropertyNames
.getConstArray();
183 sal_Bool bUnknown
= sal_False
;
185 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
187 pEntries
[n
] = mp
->find( *pNames
);
188 bUnknown
= NULL
== pEntries
[n
];
192 _getPropertyValues( (const PropertyMapEntry
**)pEntries
, aValues
.getArray() );
197 throw UnknownPropertyException();
203 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>& /*aPropertyNames*/, const Reference
< XPropertiesChangeListener
>& /*xListener*/ ) throw(RuntimeException
)
208 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& /*xListener*/ ) throw(RuntimeException
)
213 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>& /*aPropertyNames*/, const Reference
< XPropertiesChangeListener
>& /*xListener*/ ) throw(RuntimeException
)
219 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
221 PropertyMapEntry
* aEntries
[2];
223 aEntries
[0] = mp
->find( PropertyName
);
224 if( aEntries
[0] == NULL
)
225 throw UnknownPropertyException();
229 PropertyState aState
;
230 _getPropertyStates( (const PropertyMapEntry
**)aEntries
, &aState
);
235 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< ::rtl::OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
)
237 const sal_Int32 nCount
= aPropertyName
.getLength();
239 Sequence
< PropertyState
> aStates( nCount
);
243 const OUString
* pNames
= aPropertyName
.getConstArray();
245 sal_Bool bUnknown
= sal_False
;
247 PropertyMapEntry
** pEntries
= new PropertyMapEntry
*[nCount
+1];
250 for( n
= 0; !bUnknown
&& (n
< nCount
); n
++, pNames
++ )
252 pEntries
[n
] = mp
->find( *pNames
);
253 bUnknown
= NULL
== pEntries
[n
];
256 pEntries
[nCount
] = NULL
;
259 _getPropertyStates( (const PropertyMapEntry
**)pEntries
, aStates
.getArray() );
264 throw UnknownPropertyException();
270 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const ::rtl::OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
272 PropertyMapEntry
*pEntry
= mp
->find( PropertyName
);
274 throw UnknownPropertyException();
276 _setPropertyToDefault( pEntry
);
279 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const ::rtl::OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
281 PropertyMapEntry
* pEntry
= mp
->find( aPropertyName
);
283 throw UnknownPropertyException();
285 return _getPropertyDefault( pEntry
);
288 void PropertySetHelper::_getPropertyStates( const utl::PropertyMapEntry
** /*ppEntries*/, PropertyState
* /*pStates*/ ) throw(UnknownPropertyException
)
290 DBG_ERROR( "you have to implement this yourself!" );
293 void PropertySetHelper::_setPropertyToDefault( const utl::PropertyMapEntry
* /*pEntry*/ ) throw(UnknownPropertyException
)
295 DBG_ERROR( "you have to implement this yourself!" );
298 Any
PropertySetHelper::_getPropertyDefault( const utl::PropertyMapEntry
* /*pEntry*/ ) throw(UnknownPropertyException
, WrappedTargetException
)
300 DBG_ERROR( "you have to implement this yourself!" );