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 COMPHELPER_OPROPERTYBAG_HXX 25 #define COMPHELPER_OPROPERTYBAG_HXX 26 27 /** === begin UNO includes === **/ 28 #include <com/sun/star/lang/XInitialization.hpp> 29 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 30 #include <com/sun/star/lang/XServiceInfo.hpp> 31 #include <com/sun/star/util/XModifiable.hpp> 32 #include <com/sun/star/beans/XPropertySet.hpp> 33 #include <com/sun/star/beans/XPropertyContainer.hpp> 34 #include <com/sun/star/beans/XPropertyAccess.hpp> 35 #include <com/sun/star/uno/XComponentContext.hpp> 36 #include <com/sun/star/container/XSet.hpp> 37 /** === end UNO includes === **/ 38 39 #include <cppuhelper/implbase6.hxx> 40 #include <comphelper/propstate.hxx> 41 #include <comphelper/broadcasthelper.hxx> 42 #include <comphelper/propertybag.hxx> 43 #include <comphelper/componentcontext.hxx> 44 #include <comphelper/uno3.hxx> 45 46 #include <map> 47 #include <set> 48 #include <memory> 49 50 //........................................................................ 51 namespace comphelper 52 { 53 //........................................................................ 54 55 struct SAL_DLLPRIVATE UnoTypeLess : public ::std::unary_function< ::com::sun::star::uno::Type, bool > 56 { operator ()comphelper::UnoTypeLess57 inline bool operator()( const ::com::sun::star::uno::Type& _rLHS, const ::com::sun::star::uno::Type& _rRHS ) const 58 { 59 return rtl_ustr_compare( 60 _rLHS.getTypeLibType()->pTypeName->buffer, 61 _rRHS.getTypeLibType()->pTypeName->buffer 62 ) < 0; 63 } 64 }; 65 66 typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any > MapInt2Any; 67 typedef ::std::set< ::com::sun::star::uno::Type, UnoTypeLess > TypeBag; 68 69 //==================================================================== 70 //= OPropertyBag 71 //==================================================================== 72 typedef ::cppu::WeakAggImplHelper6 < ::com::sun::star::beans::XPropertyContainer 73 , ::com::sun::star::beans::XPropertyAccess 74 , ::com::sun::star::util::XModifiable 75 , ::com::sun::star::lang::XServiceInfo 76 , ::com::sun::star::lang::XInitialization 77 , ::com::sun::star::container::XSet 78 > OPropertyBag_Base; 79 typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase; 80 81 class OPropertyBag :public ::comphelper::OMutexAndBroadcastHelper // must be before OPropertyBag_PBase 82 ,public OPropertyBag_PBase 83 ,public OPropertyBag_Base 84 ,public ::cppu::IEventNotificationHook 85 { 86 private: 87 ::comphelper::ComponentContext 88 m_aContext; 89 90 /// our IPropertyArrayHelper implementation 91 ::std::auto_ptr< ::cppu::OPropertyArrayHelper > 92 m_pArrayHelper; 93 ::comphelper::PropertyBag 94 m_aDynamicProperties; 95 /// set of allowed property types 96 TypeBag m_aAllowedTypes; 97 /// should we automatically add properties which are tried to set, if they don't exist previously? 98 bool m_bAutoAddProperties; 99 100 /// for notification 101 ::cppu::OInterfaceContainerHelper m_NotifyListeners; 102 /// modify flag 103 bool m_isModified; 104 105 public: 106 OPropertyBag( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext ); 107 108 // XServiceInfo - static versions 109 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException ); 110 static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException ); 111 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 112 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&); 113 114 protected: 115 virtual ~OPropertyBag(); 116 DECLARE_XINTERFACE() 117 DECLARE_XTYPEPROVIDER() 118 119 /** === begin UNO interface implementations == **/ 120 // XInitialization 121 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 122 123 // XServiceInfo 124 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 125 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 126 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 127 128 // XModifiable: 129 virtual ::sal_Bool SAL_CALL isModified( ) 130 throw (::com::sun::star::uno::RuntimeException); 131 virtual void SAL_CALL setModified( ::sal_Bool bModified ) 132 throw (::com::sun::star::beans::PropertyVetoException, 133 ::com::sun::star::uno::RuntimeException); 134 135 // XModifyBroadcaster 136 virtual void SAL_CALL addModifyListener( 137 const ::com::sun::star::uno::Reference< 138 ::com::sun::star::util::XModifyListener > & xListener) 139 throw (::com::sun::star::uno::RuntimeException); 140 virtual void SAL_CALL removeModifyListener( 141 const ::com::sun::star::uno::Reference< 142 ::com::sun::star::util::XModifyListener > & xListener) 143 throw (::com::sun::star::uno::RuntimeException); 144 145 // XPropertyContainer 146 virtual void SAL_CALL addProperty( const ::rtl::OUString& Name, ::sal_Int16 Attributes, const ::com::sun::star::uno::Any& DefaultValue ) throw (::com::sun::star::beans::PropertyExistException, ::com::sun::star::beans::IllegalTypeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 147 virtual void SAL_CALL removeProperty( const ::rtl::OUString& Name ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::NotRemoveableException, ::com::sun::star::uno::RuntimeException); 148 149 // XPropertyAccess 150 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues( ) throw (::com::sun::star::uno::RuntimeException); 151 virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 152 153 // XPropertySet 154 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 155 156 // XSet 157 virtual ::sal_Bool SAL_CALL has( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::uno::RuntimeException); 158 virtual void SAL_CALL insert( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 159 virtual void SAL_CALL remove( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 160 161 // XEnumerationAccess (base of XSet) 162 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw (::com::sun::star::uno::RuntimeException); 163 164 // XElementAccess (basf of XEnumerationAccess 165 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException); 166 virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException); 167 /** === UNO interface implementations == **/ 168 169 // XPropertyState 170 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 _nHandle ) const; 171 172 // OPropertyStateHelper 173 virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle( sal_Int32 _nHandle ); 174 175 // OPropertySetHelper 176 virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 177 virtual sal_Bool SAL_CALL convertFastPropertyValue( ::com::sun::star::uno::Any & rConvertedValue, ::com::sun::star::uno::Any & rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::lang::IllegalArgumentException); 178 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception); 179 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 180 181 // IEventNotificationHook 182 virtual void fireEvents( 183 sal_Int32 * pnHandles, 184 sal_Int32 nCount, 185 sal_Bool bVetoable, 186 bool bIgnoreRuntimeExceptionsWhileFiring); 187 188 void SAL_CALL setModifiedImpl( ::sal_Bool bModified, 189 bool bIgnoreRuntimeExceptionsWhileFiring); 190 191 private: 192 /** finds a free property handle 193 @precond 194 our mutex is locked 195 */ 196 sal_Int32 findFreeHandle() const; 197 198 /** implements the setPropertyValues method 199 @param _rProps 200 the property values to set 201 202 @throws PropertyVetoException 203 if the XMultiPropertySet::setPropertyValues call does so 204 205 @throws ::com::sun::star::lang::IllegalArgumentException 206 if the XMultiPropertySet::setPropertyValues call does so 207 208 @throws ::com::sun::star::lang::WrappedTargetException 209 if the XMultiPropertySet::setPropertyValues call does so 210 211 @throws ::com::sun::star::uno::RuntimeException 212 if the XMultiPropertySet::setPropertyValues call does so 213 214 @throws ::com::sun::star::beans::UnknownPropertyException 215 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg> 216 was set to <FALSE/> 217 218 @throws ::com::sun::star::lang::WrappedTargetException 219 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed 220 above 221 */ 222 void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps ); 223 224 private: 225 OPropertyBag(); // never implemented 226 OPropertyBag( const OPropertyBag& ); // never implemented 227 OPropertyBag& operator=( const OPropertyBag& ); // never implemented 228 protected: 229 using ::cppu::OPropertySetHelper::getPropertyValues; 230 using ::cppu::OPropertySetHelper::setPropertyValues; 231 using ::cppu::OPropertySetHelper::getFastPropertyValue; 232 }; 233 234 //........................................................................ 235 } // namespace comphelper 236 //........................................................................ 237 238 #endif // COMPHELPER_OPROPERTYBAG_HXX 239