Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef COMPHELPER_OPROPERTYBAG_HXX
21 : #define COMPHELPER_OPROPERTYBAG_HXX
22 :
23 : #include <com/sun/star/lang/XInitialization.hpp>
24 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 : #include <com/sun/star/lang/XServiceInfo.hpp>
26 : #include <com/sun/star/util/XModifiable.hpp>
27 : #include <com/sun/star/beans/XPropertyBag.hpp>
28 : #include <com/sun/star/uno/XComponentContext.hpp>
29 : #include <com/sun/star/container/XSet.hpp>
30 :
31 : #include <boost/noncopyable.hpp>
32 : #include <cppuhelper/implbase5.hxx>
33 : #include <comphelper/propstate.hxx>
34 : #include <comphelper/broadcasthelper.hxx>
35 : #include <comphelper/propertybag.hxx>
36 : #include <comphelper/uno3.hxx>
37 :
38 : #include <map>
39 : #include <set>
40 : #include <memory>
41 :
42 :
43 : namespace comphelper
44 : {
45 :
46 :
47 : struct UnoTypeLess : public ::std::unary_function< ::com::sun::star::uno::Type, bool >
48 : {
49 0 : inline bool operator()( const ::com::sun::star::uno::Type& _rLHS, const ::com::sun::star::uno::Type& _rRHS ) const
50 : {
51 : return rtl_ustr_compare(
52 0 : _rLHS.getTypeLibType()->pTypeName->buffer,
53 0 : _rRHS.getTypeLibType()->pTypeName->buffer
54 0 : ) < 0;
55 : }
56 : };
57 :
58 : typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any > MapInt2Any;
59 : typedef ::std::set< ::com::sun::star::uno::Type, UnoTypeLess > TypeBag;
60 :
61 :
62 : //= OPropertyBag
63 :
64 : typedef ::cppu::WeakAggImplHelper5 < ::com::sun::star::beans::XPropertyBag
65 : , ::com::sun::star::util::XModifiable
66 : , ::com::sun::star::lang::XServiceInfo
67 : , ::com::sun::star::lang::XInitialization
68 : , ::com::sun::star::container::XSet
69 : > OPropertyBag_Base;
70 : typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase;
71 :
72 : class OPropertyBag :public ::comphelper::OMutexAndBroadcastHelper // must be before OPropertyBag_PBase
73 : ,public OPropertyBag_PBase
74 : ,public OPropertyBag_Base
75 : ,public ::cppu::IEventNotificationHook
76 : ,private boost::noncopyable
77 : {
78 : private:
79 : /// our IPropertyArrayHelper implementation
80 : ::std::auto_ptr< ::cppu::OPropertyArrayHelper >
81 : m_pArrayHelper;
82 : ::comphelper::PropertyBag
83 : m_aDynamicProperties;
84 : /// set of allowed property types
85 : TypeBag m_aAllowedTypes;
86 : /// should we automatically add properties which are tried to set, if they don't exist previously?
87 : bool m_bAutoAddProperties;
88 :
89 : /// for notification
90 : ::cppu::OInterfaceContainerHelper m_NotifyListeners;
91 : /// modify flag
92 : bool m_isModified;
93 :
94 : public:
95 : // XServiceInfo - static versions
96 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
97 : static OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
98 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
99 : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
100 :
101 : protected:
102 : OPropertyBag();
103 : virtual ~OPropertyBag();
104 : DECLARE_XINTERFACE()
105 : DECLARE_XTYPEPROVIDER()
106 :
107 : /** === begin UNO interface implementations == **/
108 : // XInitialization
109 : 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, std::exception) SAL_OVERRIDE;
110 :
111 : // XServiceInfo
112 : virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
114 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 :
116 : // XModifiable:
117 : virtual sal_Bool SAL_CALL isModified( )
118 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 : virtual void SAL_CALL setModified( sal_Bool bModified )
120 : throw (::com::sun::star::beans::PropertyVetoException,
121 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 :
123 : // XModifyBroadcaster
124 : virtual void SAL_CALL addModifyListener(
125 : const ::com::sun::star::uno::Reference<
126 : ::com::sun::star::util::XModifyListener > & xListener)
127 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 : virtual void SAL_CALL removeModifyListener(
129 : const ::com::sun::star::uno::Reference<
130 : ::com::sun::star::util::XModifyListener > & xListener)
131 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 :
133 : // XPropertyContainer
134 : virtual void SAL_CALL addProperty( const 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, std::exception) SAL_OVERRIDE;
135 : virtual void SAL_CALL removeProperty( const OUString& Name ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::NotRemoveableException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
136 :
137 : // XPropertyAccess
138 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 : 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, std::exception) SAL_OVERRIDE;
140 :
141 : // XPropertySet
142 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 0 : virtual void SAL_CALL setPropertyValue(const rtl::OUString& p1, const com::sun::star::uno::Any& p2) 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, std::exception) SAL_OVERRIDE
144 0 : { OPropertyBag_PBase::setPropertyValue(p1, p2); }
145 0 : virtual com::sun::star::uno::Any SAL_CALL getPropertyValue(const rtl::OUString& p1) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
146 0 : { return OPropertyBag_PBase::getPropertyValue(p1); }
147 0 : virtual void SAL_CALL addPropertyChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
148 0 : { OPropertyBag_PBase::addPropertyChangeListener(p1, p2); }
149 0 : virtual void SAL_CALL removePropertyChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
150 0 : { OPropertyBag_PBase::removePropertyChangeListener(p1, p2); }
151 0 : virtual void SAL_CALL addVetoableChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XVetoableChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
152 0 : { OPropertyBag_PBase::addVetoableChangeListener(p1, p2); }
153 0 : virtual void SAL_CALL removeVetoableChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XVetoableChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
154 0 : { OPropertyBag_PBase::removeVetoableChangeListener(p1, p2); }
155 :
156 : // XSet
157 : virtual sal_Bool SAL_CALL has( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
163 :
164 : // XElementAccess (basf of XEnumerationAccess
165 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 : virtual sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
167 : /** === UNO interface implementations == **/
168 :
169 : // XPropertyState
170 : virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 _nHandle ) const SAL_OVERRIDE;
171 :
172 : // OPropertyStateHelper
173 : virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle( sal_Int32 _nHandle ) SAL_OVERRIDE;
174 :
175 : // OPropertySetHelper
176 : virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const SAL_OVERRIDE;
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) SAL_OVERRIDE;
178 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
179 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
180 :
181 : // IEventNotificationHook
182 : virtual void fireEvents(
183 : sal_Int32 * pnHandles,
184 : sal_Int32 nCount,
185 : sal_Bool bVetoable,
186 : bool bIgnoreRuntimeExceptionsWhileFiring) SAL_OVERRIDE;
187 :
188 : void SAL_CALL setModifiedImpl( 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 : protected:
225 : using ::cppu::OPropertySetHelper::getPropertyValues;
226 : using ::cppu::OPropertySetHelper::setPropertyValues;
227 : using ::cppu::OPropertySetHelper::getFastPropertyValue;
228 : };
229 :
230 :
231 : } // namespace comphelper
232 :
233 :
234 : #endif // COMPHELPER_OPROPERTYBAG_HXX
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|