Update ooo320-m1
[ooovba.git] / comphelper / source / property / opropertybag.hxx
blob7bfd4e35556631f803056d4dc1ce46f79bfd1628
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: opropertybag.hxx,v $
10 * $Revision: 1.4.38.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef COMPHELPER_OPROPERTYBAG_HXX
32 #define COMPHELPER_OPROPERTYBAG_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/util/XModifiable.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/beans/XPropertyContainer.hpp>
41 #include <com/sun/star/beans/XPropertyAccess.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/container/XSet.hpp>
44 /** === end UNO includes === **/
46 #include <cppuhelper/implbase6.hxx>
47 #include <comphelper/propstate.hxx>
48 #include <comphelper/broadcasthelper.hxx>
49 #include <comphelper/propertybag.hxx>
50 #include <comphelper/componentcontext.hxx>
51 #include <comphelper/uno3.hxx>
53 #include <map>
54 #include <set>
55 #include <memory>
57 //........................................................................
58 namespace comphelper
60 //........................................................................
62 struct SAL_DLLPRIVATE UnoTypeLess : public ::std::unary_function< ::com::sun::star::uno::Type, bool >
64 inline bool operator()( const ::com::sun::star::uno::Type& _rLHS, const ::com::sun::star::uno::Type& _rRHS ) const
66 return rtl_ustr_compare(
67 _rLHS.getTypeLibType()->pTypeName->buffer,
68 _rRHS.getTypeLibType()->pTypeName->buffer
69 ) < 0;
73 typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any > MapInt2Any;
74 typedef ::std::set< ::com::sun::star::uno::Type, UnoTypeLess > TypeBag;
76 //====================================================================
77 //= OPropertyBag
78 //====================================================================
79 typedef ::cppu::WeakAggImplHelper6 < ::com::sun::star::beans::XPropertyContainer
80 , ::com::sun::star::beans::XPropertyAccess
81 , ::com::sun::star::util::XModifiable
82 , ::com::sun::star::lang::XServiceInfo
83 , ::com::sun::star::lang::XInitialization
84 , ::com::sun::star::container::XSet
85 > OPropertyBag_Base;
86 typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase;
88 class OPropertyBag :public ::comphelper::OMutexAndBroadcastHelper // must be before OPropertyBag_PBase
89 ,public OPropertyBag_PBase
90 ,public OPropertyBag_Base
91 ,public ::cppu::IEventNotificationHook
93 private:
94 ::comphelper::ComponentContext
95 m_aContext;
97 /// our IPropertyArrayHelper implementation
98 ::std::auto_ptr< ::cppu::OPropertyArrayHelper >
99 m_pArrayHelper;
100 ::comphelper::PropertyBag
101 m_aDynamicProperties;
102 /// set of allowed property types
103 TypeBag m_aAllowedTypes;
104 /// should we automatically add properties which are tried to set, if they don't exist previously?
105 bool m_bAutoAddProperties;
107 /// for notification
108 ::cppu::OInterfaceContainerHelper m_NotifyListeners;
109 /// modify flag
110 bool m_isModified;
112 public:
113 OPropertyBag( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
115 // XServiceInfo - static versions
116 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
117 static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
118 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
119 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
121 protected:
122 virtual ~OPropertyBag();
123 DECLARE_XINTERFACE()
124 DECLARE_XTYPEPROVIDER()
126 /** === begin UNO interface implementations == **/
127 // XInitialization
128 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);
130 // XServiceInfo
131 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
132 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
133 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
135 // XModifiable:
136 virtual ::sal_Bool SAL_CALL isModified( )
137 throw (::com::sun::star::uno::RuntimeException);
138 virtual void SAL_CALL setModified( ::sal_Bool bModified )
139 throw (::com::sun::star::beans::PropertyVetoException,
140 ::com::sun::star::uno::RuntimeException);
142 // XModifyBroadcaster
143 virtual void SAL_CALL addModifyListener(
144 const ::com::sun::star::uno::Reference<
145 ::com::sun::star::util::XModifyListener > & xListener)
146 throw (::com::sun::star::uno::RuntimeException);
147 virtual void SAL_CALL removeModifyListener(
148 const ::com::sun::star::uno::Reference<
149 ::com::sun::star::util::XModifyListener > & xListener)
150 throw (::com::sun::star::uno::RuntimeException);
152 // XPropertyContainer
153 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);
154 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);
156 // XPropertyAccess
157 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues( ) throw (::com::sun::star::uno::RuntimeException);
158 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);
160 // XPropertySet
161 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
163 // XSet
164 virtual ::sal_Bool SAL_CALL has( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::uno::RuntimeException);
165 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);
166 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);
168 // XEnumerationAccess (base of XSet)
169 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw (::com::sun::star::uno::RuntimeException);
171 // XElementAccess (basf of XEnumerationAccess
172 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException);
173 virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException);
174 /** === UNO interface implementations == **/
176 // XPropertyState
177 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 _nHandle ) const;
179 // OPropertyStateHelper
180 virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle( sal_Int32 _nHandle );
182 // OPropertySetHelper
183 virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
184 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);
185 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception);
186 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
188 // IEventNotificationHook
189 virtual void fireEvents(
190 sal_Int32 * pnHandles,
191 sal_Int32 nCount,
192 sal_Bool bVetoable,
193 bool bIgnoreRuntimeExceptionsWhileFiring);
195 void SAL_CALL setModifiedImpl( ::sal_Bool bModified,
196 bool bIgnoreRuntimeExceptionsWhileFiring);
198 private:
199 /** finds a free property handle
200 @precond
201 our mutex is locked
203 sal_Int32 findFreeHandle() const;
205 /** implements the setPropertyValues method
206 @param _rProps
207 the property values to set
209 @throws PropertyVetoException
210 if the XMultiPropertySet::setPropertyValues call does so
212 @throws ::com::sun::star::lang::IllegalArgumentException
213 if the XMultiPropertySet::setPropertyValues call does so
215 @throws ::com::sun::star::lang::WrappedTargetException
216 if the XMultiPropertySet::setPropertyValues call does so
218 @throws ::com::sun::star::uno::RuntimeException
219 if the XMultiPropertySet::setPropertyValues call does so
221 @throws ::com::sun::star::beans::UnknownPropertyException
222 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
223 was set to <FALSE/>
225 @throws ::com::sun::star::lang::WrappedTargetException
226 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
227 above
229 void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps );
231 private:
232 OPropertyBag(); // never implemented
233 OPropertyBag( const OPropertyBag& ); // never implemented
234 OPropertyBag& operator=( const OPropertyBag& ); // never implemented
235 protected:
236 using ::cppu::OPropertySetHelper::getPropertyValues;
237 using ::cppu::OPropertySetHelper::setPropertyValues;
238 using ::cppu::OPropertySetHelper::getFastPropertyValue;
241 //........................................................................
242 } // namespace comphelper
243 //........................................................................
245 #endif // COMPHELPER_OPROPERTYBAG_HXX