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