1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef COMPHELPER_OPROPERTYBAG_HXX
29 #define COMPHELPER_OPROPERTYBAG_HXX
31 /** === begin UNO includes === **/
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/util/XModifiable.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/beans/XPropertyContainer.hpp>
38 #include <com/sun/star/beans/XPropertyAccess.hpp>
39 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <com/sun/star/container/XSet.hpp>
41 /** === end UNO includes === **/
43 #include <cppuhelper/implbase6.hxx>
44 #include <comphelper/propstate.hxx>
45 #include <comphelper/broadcasthelper.hxx>
46 #include <comphelper/propertybag.hxx>
47 #include <comphelper/componentcontext.hxx>
48 #include <comphelper/uno3.hxx>
54 //........................................................................
57 //........................................................................
59 struct SAL_DLLPRIVATE UnoTypeLess
: public ::std::unary_function
< ::com::sun::star::uno::Type
, bool >
61 inline bool operator()( const ::com::sun::star::uno::Type
& _rLHS
, const ::com::sun::star::uno::Type
& _rRHS
) const
63 return rtl_ustr_compare(
64 _rLHS
.getTypeLibType()->pTypeName
->buffer
,
65 _rRHS
.getTypeLibType()->pTypeName
->buffer
70 typedef ::std::map
< sal_Int32
, ::com::sun::star::uno::Any
> MapInt2Any
;
71 typedef ::std::set
< ::com::sun::star::uno::Type
, UnoTypeLess
> TypeBag
;
73 //====================================================================
75 //====================================================================
76 typedef ::cppu::WeakAggImplHelper6
< ::com::sun::star::beans::XPropertyContainer
77 , ::com::sun::star::beans::XPropertyAccess
78 , ::com::sun::star::util::XModifiable
79 , ::com::sun::star::lang::XServiceInfo
80 , ::com::sun::star::lang::XInitialization
81 , ::com::sun::star::container::XSet
83 typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase
;
85 class OPropertyBag
:public ::comphelper::OMutexAndBroadcastHelper
// must be before OPropertyBag_PBase
86 ,public OPropertyBag_PBase
87 ,public OPropertyBag_Base
88 ,public ::cppu::IEventNotificationHook
91 ::comphelper::ComponentContext
94 /// our IPropertyArrayHelper implementation
95 ::std::auto_ptr
< ::cppu::OPropertyArrayHelper
>
97 ::comphelper::PropertyBag
99 /// set of allowed property types
100 TypeBag m_aAllowedTypes
;
101 /// should we automatically add properties which are tried to set, if they don't exist previously?
102 bool m_bAutoAddProperties
;
105 ::cppu::OInterfaceContainerHelper m_NotifyListeners
;
110 OPropertyBag( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
112 // XServiceInfo - static versions
113 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException
);
114 static ::rtl::OUString
getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException
);
115 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
116 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
119 virtual ~OPropertyBag();
121 DECLARE_XTYPEPROVIDER()
123 /** === begin UNO interface implementations == **/
125 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
);
128 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
);
129 virtual ::sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
130 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
133 virtual ::sal_Bool SAL_CALL
isModified( )
134 throw (::com::sun::star::uno::RuntimeException
);
135 virtual void SAL_CALL
setModified( ::sal_Bool bModified
)
136 throw (::com::sun::star::beans::PropertyVetoException
,
137 ::com::sun::star::uno::RuntimeException
);
139 // XModifyBroadcaster
140 virtual void SAL_CALL
addModifyListener(
141 const ::com::sun::star::uno::Reference
<
142 ::com::sun::star::util::XModifyListener
> & xListener
)
143 throw (::com::sun::star::uno::RuntimeException
);
144 virtual void SAL_CALL
removeModifyListener(
145 const ::com::sun::star::uno::Reference
<
146 ::com::sun::star::util::XModifyListener
> & xListener
)
147 throw (::com::sun::star::uno::RuntimeException
);
149 // XPropertyContainer
150 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
);
151 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
);
154 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> SAL_CALL
getPropertyValues( ) throw (::com::sun::star::uno::RuntimeException
);
155 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
);
158 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
161 virtual ::sal_Bool SAL_CALL
has( const ::com::sun::star::uno::Any
& aElement
) throw (::com::sun::star::uno::RuntimeException
);
162 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
);
163 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
);
165 // XEnumerationAccess (base of XSet)
166 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw (::com::sun::star::uno::RuntimeException
);
168 // XElementAccess (basf of XEnumerationAccess
169 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw (::com::sun::star::uno::RuntimeException
);
170 virtual ::sal_Bool SAL_CALL
hasElements( ) throw (::com::sun::star::uno::RuntimeException
);
171 /** === UNO interface implementations == **/
174 virtual ::com::sun::star::uno::Any
getPropertyDefaultByHandle( sal_Int32 _nHandle
) const;
176 // OPropertyStateHelper
177 virtual ::com::sun::star::beans::PropertyState
getPropertyStateByHandle( sal_Int32 _nHandle
);
179 // OPropertySetHelper
180 virtual void SAL_CALL
getFastPropertyValue( ::com::sun::star::uno::Any
& rValue
, sal_Int32 nHandle
) const;
181 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
);
182 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
);
183 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
185 // IEventNotificationHook
186 virtual void fireEvents(
187 sal_Int32
* pnHandles
,
190 bool bIgnoreRuntimeExceptionsWhileFiring
);
192 void SAL_CALL
setModifiedImpl( ::sal_Bool bModified
,
193 bool bIgnoreRuntimeExceptionsWhileFiring
);
196 /** finds a free property handle
200 sal_Int32
findFreeHandle() const;
202 /** implements the setPropertyValues method
204 the property values to set
206 @throws PropertyVetoException
207 if the XMultiPropertySet::setPropertyValues call does so
209 @throws ::com::sun::star::lang::IllegalArgumentException
210 if the XMultiPropertySet::setPropertyValues call does so
212 @throws ::com::sun::star::lang::WrappedTargetException
213 if the XMultiPropertySet::setPropertyValues call does so
215 @throws ::com::sun::star::uno::RuntimeException
216 if the XMultiPropertySet::setPropertyValues call does so
218 @throws ::com::sun::star::beans::UnknownPropertyException
219 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
222 @throws ::com::sun::star::lang::WrappedTargetException
223 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
226 void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rProps
);
229 OPropertyBag(); // never implemented
230 OPropertyBag( const OPropertyBag
& ); // never implemented
231 OPropertyBag
& operator=( const OPropertyBag
& ); // never implemented
233 using ::cppu::OPropertySetHelper::getPropertyValues
;
234 using ::cppu::OPropertySetHelper::setPropertyValues
;
235 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
238 //........................................................................
239 } // namespace comphelper
240 //........................................................................
242 #endif // COMPHELPER_OPROPERTYBAG_HXX