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