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