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.hxx,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 #ifndef __FRAMEWORK_CLASSES_PROPERTYSETHELPER_HXX_
32 #define __FRAMEWORK_CLASSES_PROPERTYSETHELPER_HXX_
34 //_________________________________________________________________________________________________________________
37 #include <threadhelp/threadhelpbase.hxx>
38 #include <threadhelp/transactionbase.hxx>
39 #include <macros/debug.hxx>
43 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/XPropertySetInfo.hpp>
48 #include <com/sun/star/beans/PropertyExistException.hpp>
49 #include <com/sun/star/beans/UnknownPropertyException.hpp>
51 //_________________________________________________________________________________________________________________
54 #include <cppuhelper/weakref.hxx>
56 //_________________________________________________________________________________________________________________
61 //_________________________________________________________________________________________________________________
63 /** supports the API XPropertySet and XPropertySetInfo.
65 * It must be used as baseclass. The internal list of supported
66 * properties can be changed everytimes so dynamic property set's
69 * Further the derived and this base class share the same lock.
70 * So it's possible to be threadsafe if it's needed.
72 class PropertySetHelper
: public css::beans::XPropertySet
73 , public css::beans::XPropertySetInfo
75 //-------------------------------------------------------------------------
79 typedef BaseHash
< css::beans::Property
> TPropInfoHash
;
81 //-------------------------------------------------------------------------
85 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
87 PropertySetHelper::TPropInfoHash m_lProps
;
89 ListenerHash m_lSimpleChangeListener
;
90 ListenerHash m_lVetoChangeListener
;
92 sal_Bool m_bReleaseLockOnCall
;
94 // hold it weak ... otherwhise this helper has to be "killed" explicitly .-)
95 css::uno::WeakReference
< css::uno::XInterface
> m_xBroadcaster
;
98 TransactionManager
& m_rTransactionManager
;
100 //-------------------------------------------------------------------------
101 /* native interface */
104 //---------------------------------------------------------------------
105 /** initialize new instance of this helper.
108 * points to an uno service manager, which is used internaly to create own
109 * needed uno services.
111 * @param pExternalLock
112 * this helper must be used as a baseclass ...
113 * but then it should synchronize its own calls
114 * with the same lock then it's superclass uses.
116 * @param pExternalTransactionManager
117 * this helper must be used as a baseclass ...
118 * but then it should synchronize its own calls
119 * with the same transaction manager then it's superclass.
121 * @param bReleaseLockOnCall
122 * see member m_bReleaseLockOnCall
124 PropertySetHelper(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
125 LockHelper
* pExternalLock
,
126 TransactionManager
* pExternalTransactionManager
,
127 sal_Bool bReleaseLockOnCall
);
129 //---------------------------------------------------------------------
130 /** free all needed memory.
132 virtual ~PropertySetHelper();
134 //---------------------------------------------------------------------
135 /** set a new owner for this helper.
137 * This owner is used as source for all broadcasted events.
138 * Further we hold it weak, because we dont wish to be disposed() .-)
140 void impl_setPropertyChangeBroadcaster(const css::uno::Reference
< css::uno::XInterface
>& xBroadcaster
);
142 //---------------------------------------------------------------------
143 /** add a new property info to the set of supported ones.
146 * describes the new property.
148 * @throw [com::sun::star::beans::PropertyExistException]
149 * if a property with the same name already exists.
151 * Note: The consistence of the whole set of properties is not checked here.
152 * Means e.g. ... a handle which exists more then once is not detected.
153 * The owner of this class has to be sure, that every new property does
154 * not clash with any existing one.
156 virtual void SAL_CALL
impl_addPropertyInfo(const css::beans::Property
& aProperty
)
157 throw(css::beans::PropertyExistException
,
158 css::uno::Exception
);
160 //---------------------------------------------------------------------
161 /** remove an existing property info from the set of supported ones.
164 * the name of the property.
166 * @throw [com::sun::star::beans::UnknownPropertyException]
167 * if no property with the specified name exists.
169 virtual void SAL_CALL
impl_removePropertyInfo(const ::rtl::OUString
& sProperty
)
170 throw(css::beans::UnknownPropertyException
,
171 css::uno::Exception
);
173 //---------------------------------------------------------------------
174 /** mark the object as "useable for working" or "dead".
176 * This correspond to the lifetime handling implemented by the base class TransactionBase.
177 * There is no chance to reactive a "dead" object by calling impl_enablePropertySet()
180 virtual void SAL_CALL
impl_enablePropertySet();
181 virtual void SAL_CALL
impl_disablePropertySet();
183 //---------------------------------------------------------------------
186 virtual void SAL_CALL
impl_setPropertyValue(const ::rtl::OUString
& sProperty
,
188 const css::uno::Any
& aValue
) = 0;
190 virtual css::uno::Any SAL_CALL
impl_getPropertyValue(const ::rtl::OUString
& sProperty
,
191 sal_Int32 nHandle
) = 0;
193 //-------------------------------------------------------------------------
198 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo()
199 throw(css::uno::RuntimeException
);
201 virtual void SAL_CALL
setPropertyValue(const ::rtl::OUString
& sProperty
,
202 const css::uno::Any
& aValue
)
203 throw(css::beans::UnknownPropertyException
,
204 css::beans::PropertyVetoException
,
205 css::lang::IllegalArgumentException
,
206 css::lang::WrappedTargetException
,
207 css::uno::RuntimeException
);
209 virtual css::uno::Any SAL_CALL
getPropertyValue(const ::rtl::OUString
& sProperty
)
210 throw(css::beans::UnknownPropertyException
,
211 css::lang::WrappedTargetException
,
212 css::uno::RuntimeException
);
214 virtual void SAL_CALL
addPropertyChangeListener(const ::rtl::OUString
& sProperty
,
215 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
)
216 throw(css::beans::UnknownPropertyException
,
217 css::lang::WrappedTargetException
,
218 css::uno::RuntimeException
);
220 virtual void SAL_CALL
removePropertyChangeListener(const ::rtl::OUString
& sProperty
,
221 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
)
222 throw(css::beans::UnknownPropertyException
,
223 css::lang::WrappedTargetException
,
224 css::uno::RuntimeException
);
226 virtual void SAL_CALL
addVetoableChangeListener(const ::rtl::OUString
& sProperty
,
227 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& xListener
)
228 throw(css::beans::UnknownPropertyException
,
229 css::lang::WrappedTargetException
,
230 css::uno::RuntimeException
);
232 virtual void SAL_CALL
removeVetoableChangeListener(const ::rtl::OUString
& sProperty
,
233 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& xListener
)
234 throw(css::beans::UnknownPropertyException
,
235 css::lang::WrappedTargetException
,
236 css::uno::RuntimeException
);
239 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
getProperties()
240 throw(css::uno::RuntimeException
);
242 virtual css::beans::Property SAL_CALL
getPropertyByName(const ::rtl::OUString
& sName
)
243 throw(css::beans::UnknownPropertyException
,
244 css::uno::RuntimeException
);
246 virtual sal_Bool SAL_CALL
hasPropertyByName(const ::rtl::OUString
& sName
)
247 throw(css::uno::RuntimeException
);
249 //-------------------------------------------------------------------------
250 /* internal helper */
253 sal_Bool
impl_existsVeto(const css::beans::PropertyChangeEvent
& aEvent
);
255 void impl_notifyChangeListener(const css::beans::PropertyChangeEvent
& aEvent
);
258 } // namespace framework
260 #endif // #ifndef __FRAMEWORK_CLASSES_PROPERTYSETHELPER_HXX_