1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_CLASSES_PROPERTYSETHELPER_HXX_
29 #define __FRAMEWORK_CLASSES_PROPERTYSETHELPER_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 
34 #include <threadhelp/threadhelpbase.hxx>
35 #include <threadhelp/transactionbase.hxx>
36 #include <macros/debug.hxx>
37 #include <general.h>
38 #include <stdtypes.h>
39 
40 //_________________________________________________________________________________________________________________
41 //	interface includes
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/beans/XPropertySetInfo.hpp>
45 #include <com/sun/star/beans/PropertyExistException.hpp>
46 #include <com/sun/star/beans/UnknownPropertyException.hpp>
47 
48 //_________________________________________________________________________________________________________________
49 //	other includes
50 
51 #include <cppuhelper/weakref.hxx>
52 #include <fwidllapi.h>
53 
54 //_________________________________________________________________________________________________________________
55 //	namespace
56 
57 namespace framework{
58 
59 //_________________________________________________________________________________________________________________
60 
61 /** supports the API XPropertySet and XPropertySetInfo.
62  *
63  *  It must be used as baseclass. The internal list of supported
64  *  properties can be changed everytimes so dynamic property set's
65  *  can be implemented.
66  *
67  *  Further the derived and this base class share the same lock.
68  *  So it's possible to be threadsafe if it's needed.
69 */
70 class FWI_DLLPUBLIC PropertySetHelper : public css::beans::XPropertySet
71                         , public css::beans::XPropertySetInfo
72 {
73     //-------------------------------------------------------------------------
74     /* types */
75     protected:
76 
77         typedef BaseHash< css::beans::Property > TPropInfoHash;
78 
79     //-------------------------------------------------------------------------
80     /* member */
81     protected:
82 
83         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
84 
85         PropertySetHelper::TPropInfoHash m_lProps;
86 
87         ListenerHash m_lSimpleChangeListener;
88         ListenerHash m_lVetoChangeListener;
89 
90         sal_Bool m_bReleaseLockOnCall;
91 
92         // hold it weak ... otherwhise this helper has to be "killed" explicitly .-)
93         css::uno::WeakReference< css::uno::XInterface > m_xBroadcaster;
94 
95         LockHelper& m_rLock;
96         TransactionManager& m_rTransactionManager;
97 
98     //-------------------------------------------------------------------------
99     /* native interface */
100     public:
101 
102         //---------------------------------------------------------------------
103         /** initialize new instance of this helper.
104          *
105          *  @param  xSMGR
106          *          points to an uno service manager, which is used internaly to create own
107          *          needed uno services.
108          *
109          *  @param  pExternalLock
110          *          this helper must be used as a baseclass ...
111          *          but then it should synchronize its own calls
112          *          with the same lock then it's superclass uses.
113          *
114          *  @param  pExternalTransactionManager
115          *          this helper must be used as a baseclass ...
116          *          but then it should synchronize its own calls
117          *          with the same transaction manager then it's superclass.
118          *
119          *  @param  bReleaseLockOnCall
120          *          see member m_bReleaseLockOnCall
121          */
122         PropertySetHelper(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR                       ,
123                                 LockHelper*                                             pExternalLock               ,
124                                 TransactionManager*                                     pExternalTransactionManager ,
125                                 sal_Bool                                                bReleaseLockOnCall          );
126 
127         //---------------------------------------------------------------------
128         /** free all needed memory.
129          */
130         virtual ~PropertySetHelper();
131 
132         //---------------------------------------------------------------------
133         /** set a new owner for this helper.
134          *
135          *  This owner is used as source for all broadcasted events.
136          *  Further we hold it weak, because we dont wish to be disposed() .-)
137          */
138         void impl_setPropertyChangeBroadcaster(const css::uno::Reference< css::uno::XInterface >& xBroadcaster);
139 
140         //---------------------------------------------------------------------
141         /** add a new property info to the set of supported ones.
142          *
143          *  @param  aProperty
144          *          describes the new property.
145          *
146          *  @throw  [com::sun::star::beans::PropertyExistException]
147          *          if a property with the same name already exists.
148          *
149          *  Note:   The consistence of the whole set of properties is not checked here.
150          *          Means e.g. ... a handle which exists more then once is not detected.
151          *          The owner of this class has to be sure, that every new property does
152          *          not clash with any existing one.
153          */
154         virtual void SAL_CALL impl_addPropertyInfo(const css::beans::Property& aProperty)
155             throw(css::beans::PropertyExistException,
156                   css::uno::Exception               );
157 
158         //---------------------------------------------------------------------
159         /** remove an existing property info from the set of supported ones.
160          *
161          *  @param  sProperty
162          *          the name of the property.
163          *
164          *  @throw  [com::sun::star::beans::UnknownPropertyException]
165          *          if no property with the specified name exists.
166          */
167         virtual void SAL_CALL impl_removePropertyInfo(const ::rtl::OUString& sProperty)
168             throw(css::beans::UnknownPropertyException,
169                   css::uno::Exception                 );
170 
171         //---------------------------------------------------------------------
172         /** mark the object as "useable for working" or "dead".
173          *
174          *  This correspond to the lifetime handling implemented by the base class TransactionBase.
175          *  There is no chance to reactive a "dead" object by calling impl_enablePropertySet()
176          *  again!
177          */
178         virtual void SAL_CALL impl_enablePropertySet();
179         virtual void SAL_CALL impl_disablePropertySet();
180 
181         //---------------------------------------------------------------------
182         /**
183          */
184         virtual void SAL_CALL impl_setPropertyValue(const ::rtl::OUString& sProperty,
185                                                           sal_Int32        nHandle  ,
186                                                     const css::uno::Any&   aValue   ) = 0;
187 
188         virtual css::uno::Any SAL_CALL impl_getPropertyValue(const ::rtl::OUString& sProperty,
189                                                                    sal_Int32        nHandle  ) = 0;
190 
191     //-------------------------------------------------------------------------
192     /* uno interface */
193     public:
194 
195         // XPropertySet
196         virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
197             throw(css::uno::RuntimeException);
198 
199         virtual void SAL_CALL setPropertyValue(const ::rtl::OUString& sProperty,
200                                                const css::uno::Any&   aValue   )
201             throw(css::beans::UnknownPropertyException,
202                   css::beans::PropertyVetoException   ,
203                   css::lang::IllegalArgumentException ,
204                   css::lang::WrappedTargetException   ,
205                   css::uno::RuntimeException          );
206 
207         virtual css::uno::Any SAL_CALL getPropertyValue(const ::rtl::OUString& sProperty)
208             throw(css::beans::UnknownPropertyException,
209                   css::lang::WrappedTargetException   ,
210                   css::uno::RuntimeException          );
211 
212         virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString&                                            sProperty,
213                                                         const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
214             throw(css::beans::UnknownPropertyException,
215                   css::lang::WrappedTargetException   ,
216                   css::uno::RuntimeException          );
217 
218         virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString&                                            sProperty,
219                                                            const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
220             throw(css::beans::UnknownPropertyException,
221                   css::lang::WrappedTargetException   ,
222                   css::uno::RuntimeException          );
223 
224         virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString&                                            sProperty,
225                                                         const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
226             throw(css::beans::UnknownPropertyException,
227                   css::lang::WrappedTargetException   ,
228                   css::uno::RuntimeException          );
229 
230         virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString&                                            sProperty,
231                                                            const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
232             throw(css::beans::UnknownPropertyException,
233                   css::lang::WrappedTargetException   ,
234                   css::uno::RuntimeException          );
235 
236         // XPropertySetInfo
237         virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties()
238             throw(css::uno::RuntimeException);
239 
240         virtual css::beans::Property SAL_CALL getPropertyByName(const ::rtl::OUString& sName)
241             throw(css::beans::UnknownPropertyException,
242                   css::uno::RuntimeException          );
243 
244         virtual sal_Bool SAL_CALL hasPropertyByName(const ::rtl::OUString& sName)
245             throw(css::uno::RuntimeException);
246 
247     //-------------------------------------------------------------------------
248     /* internal helper */
249     private:
250 
251         sal_Bool impl_existsVeto(const css::beans::PropertyChangeEvent& aEvent);
252 
253         void impl_notifyChangeListener(const css::beans::PropertyChangeEvent& aEvent);
254 };
255 
256 } // namespace framework
257 
258 #endif // #ifndef __FRAMEWORK_CLASSES_PROPERTYSETHELPER_HXX_
259