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); 110 static ::rtl::OUString getImplementationName_static(void); 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 ); 122 123 // XServiceInfo 124 virtual ::rtl::OUString SAL_CALL getImplementationName( ); 125 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 126 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ); 127 128 // XModifiable: 129 virtual ::sal_Bool SAL_CALL isModified( ); 130 virtual void SAL_CALL setModified( ::sal_Bool bModified ); 131 132 // XModifyBroadcaster 133 virtual void SAL_CALL addModifyListener( 134 const ::com::sun::star::uno::Reference< 135 ::com::sun::star::util::XModifyListener > & xListener); 136 virtual void SAL_CALL removeModifyListener( 137 const ::com::sun::star::uno::Reference< 138 ::com::sun::star::util::XModifyListener > & xListener); 139 140 // XPropertyContainer 141 virtual void SAL_CALL addProperty( const ::rtl::OUString& Name, ::sal_Int16 Attributes, const ::com::sun::star::uno::Any& DefaultValue ); 142 virtual void SAL_CALL removeProperty( const ::rtl::OUString& Name ); 143 144 // XPropertyAccess 145 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues( ); 146 virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ); 147 148 // XPropertySet 149 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ); 150 151 // XSet 152 virtual ::sal_Bool SAL_CALL has( const ::com::sun::star::uno::Any& aElement ); 153 virtual void SAL_CALL insert( const ::com::sun::star::uno::Any& aElement ); 154 virtual void SAL_CALL remove( const ::com::sun::star::uno::Any& aElement ); 155 156 // XEnumerationAccess (base of XSet) 157 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ); 158 159 // XElementAccess (basf of XEnumerationAccess 160 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ); 161 virtual ::sal_Bool SAL_CALL hasElements( ); 162 /** === UNO interface implementations == **/ 163 164 // XPropertyState 165 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 _nHandle ) const; 166 167 // OPropertyStateHelper 168 virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle( sal_Int32 _nHandle ); 169 170 // OPropertySetHelper 171 virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 172 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 ); 173 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ); 174 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 175 176 // IEventNotificationHook 177 virtual void fireEvents( 178 sal_Int32 * pnHandles, 179 sal_Int32 nCount, 180 sal_Bool bVetoable, 181 bool bIgnoreRuntimeExceptionsWhileFiring); 182 183 void SAL_CALL setModifiedImpl( ::sal_Bool bModified, 184 bool bIgnoreRuntimeExceptionsWhileFiring); 185 186 private: 187 /** finds a free property handle 188 @precond 189 our mutex is locked 190 */ 191 sal_Int32 findFreeHandle() const; 192 193 /** implements the setPropertyValues method 194 @param _rProps 195 the property values to set 196 197 @throws PropertyVetoException 198 if the XMultiPropertySet::setPropertyValues call does so 199 200 @throws ::com::sun::star::lang::IllegalArgumentException 201 if the XMultiPropertySet::setPropertyValues call does so 202 203 @throws ::com::sun::star::lang::WrappedTargetException 204 if the XMultiPropertySet::setPropertyValues call does so 205 206 @throws ::com::sun::star::uno::RuntimeException 207 if the XMultiPropertySet::setPropertyValues call does so 208 209 @throws ::com::sun::star::beans::UnknownPropertyException 210 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg> 211 was set to <FALSE/> 212 213 @throws ::com::sun::star::lang::WrappedTargetException 214 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed 215 above 216 */ 217 void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps ); 218 219 private: 220 OPropertyBag(); // never implemented 221 OPropertyBag( const OPropertyBag& ); // never implemented 222 OPropertyBag& operator=( const OPropertyBag& ); // never implemented 223 protected: 224 using ::cppu::OPropertySetHelper::getPropertyValues; 225 using ::cppu::OPropertySetHelper::setPropertyValues; 226 using ::cppu::OPropertySetHelper::getFastPropertyValue; 227 }; 228 229 //........................................................................ 230 } // namespace comphelper 231 //........................................................................ 232 233 #endif // COMPHELPER_OPROPERTYBAG_HXX 234