1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "propertybaghelper.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "property.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /** === begin UNO includes === **/
31cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/PropertyExistException.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/NotRemoveableException.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp>
36cdf0e10cSrcweir /** === end UNO includes === **/
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <tools/diagnose_ex.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <comphelper/sequence.hxx>
41cdf0e10cSrcweir #include <rtl/logfile.hxx>
42cdf0e10cSrcweir #include "rtl/instance.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #define NEW_HANDLE_BASE 10000
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //........................................................................
48cdf0e10cSrcweir namespace frm
49cdf0e10cSrcweir {
50cdf0e10cSrcweir //........................................................................
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	/** === begin UNO using === **/
53cdf0e10cSrcweir     using ::com::sun::star::lang::DisposedException;
54cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
55cdf0e10cSrcweir     using ::com::sun::star::beans::Property;
56cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
57cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyExistException;
58cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyValue;
59cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
60cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
61cdf0e10cSrcweir     using ::com::sun::star::beans::XMultiPropertySet;
62cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
63cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
64cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
65cdf0e10cSrcweir     using ::com::sun::star::beans::NotRemoveableException;
66cdf0e10cSrcweir     using ::com::sun::star::beans::UnknownPropertyException;
67cdf0e10cSrcweir 	/** === end UNO using === **/
68cdf0e10cSrcweir     namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	//====================================================================
71cdf0e10cSrcweir 	//= helper
72cdf0e10cSrcweir 	//====================================================================
73cdf0e10cSrcweir     namespace
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir     	//----------------------------------------------------------------
76cdf0e10cSrcweir         static ::comphelper::IPropertyInfoService& lcl_getPropertyInfos()
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir 	        static ConcreteInfoService s_aPropInfos;
79cdf0e10cSrcweir             return s_aPropInfos;
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	//====================================================================
84cdf0e10cSrcweir 	//= PropertyBagHelper
85cdf0e10cSrcweir 	//====================================================================
86cdf0e10cSrcweir 	//--------------------------------------------------------------------
87cdf0e10cSrcweir     PropertyBagHelper::PropertyBagHelper( IPropertyBagHelperContext& _rContext )
88cdf0e10cSrcweir         :m_rContext( _rContext )
89cdf0e10cSrcweir         ,m_pPropertyArrayHelper( NULL )
90cdf0e10cSrcweir         ,m_bDisposed( false )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::PropertyBagHelper" );
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	//--------------------------------------------------------------------
96cdf0e10cSrcweir     PropertyBagHelper::~PropertyBagHelper()
97cdf0e10cSrcweir     {
98cdf0e10cSrcweir         delete m_pPropertyArrayHelper, m_pPropertyArrayHelper = NULL;
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     //--------------------------------------------------------------------
102cdf0e10cSrcweir     void PropertyBagHelper::dispose()
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::dispose" );
105cdf0e10cSrcweir         m_bDisposed = true;
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     //--------------------------------------------------------------------
109cdf0e10cSrcweir     void PropertyBagHelper::impl_nts_checkDisposed_throw() const
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::impl_nts_checkDisposed_throw" );
112cdf0e10cSrcweir         if ( m_bDisposed )
113cdf0e10cSrcweir             throw DisposedException();
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     //--------------------------------------------------------------------
117cdf0e10cSrcweir     void PropertyBagHelper::impl_nts_invalidatePropertySetInfo()
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::impl_nts_invalidatePropertySetInfo" );
120cdf0e10cSrcweir         delete m_pPropertyArrayHelper, m_pPropertyArrayHelper = NULL;
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     //--------------------------------------------------------------------
124cdf0e10cSrcweir     sal_Int32 PropertyBagHelper::impl_findFreeHandle( const ::rtl::OUString& _rPropertyName )
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::impl_findFreeHandle" );
127cdf0e10cSrcweir         ::comphelper::OPropertyArrayAggregationHelper& rPropInfo( impl_ts_getArrayHelper() );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         // check the preferred handle
130cdf0e10cSrcweir         sal_Int32 nHandle = lcl_getPropertyInfos().getPreferedPropertyId( _rPropertyName );
131cdf0e10cSrcweir         if ( ( nHandle != -1 ) && rPropInfo.fillPropertyMembersByHandle( NULL, NULL, nHandle ) )
132cdf0e10cSrcweir             nHandle = -1;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         // seach a free handle in <math>F_1009</math>
135cdf0e10cSrcweir         if ( nHandle == -1 )
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir             sal_Int32 nPrime = 1009;
138cdf0e10cSrcweir             sal_Int32 nFactor = 11;
139cdf0e10cSrcweir             sal_Int32 nNum = nFactor;
140cdf0e10cSrcweir             while ( nNum != 1 )
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 if ( !rPropInfo.fillPropertyMembersByHandle( NULL, NULL, nNum + NEW_HANDLE_BASE ) )
143cdf0e10cSrcweir                 {
144cdf0e10cSrcweir                     // handle not used, yet
145cdf0e10cSrcweir                     nHandle = nNum + NEW_HANDLE_BASE;
146cdf0e10cSrcweir                     break;
147cdf0e10cSrcweir                 }
148cdf0e10cSrcweir                 nNum = ( nNum * nFactor ) % nPrime;
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         // search a free handle greater NEW_HANDLE_BASE
153cdf0e10cSrcweir         if ( nHandle == -1 )
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             nHandle = NEW_HANDLE_BASE + 1009;
156cdf0e10cSrcweir             while ( rPropInfo.fillPropertyMembersByHandle( NULL, NULL, nHandle ) )
157cdf0e10cSrcweir                 ++nHandle;
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         return nHandle;
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     //--------------------------------------------------------------------
164cdf0e10cSrcweir     ::comphelper::OPropertyArrayAggregationHelper& PropertyBagHelper::impl_ts_getArrayHelper() const
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::impl_ts_getArrayHelper" );
167cdf0e10cSrcweir         //::osl::MutexGuard aGuard( m_rContext.getMutex() );
168cdf0e10cSrcweir         OPropertyArrayAggregationHelper* p = m_pPropertyArrayHelper;
169cdf0e10cSrcweir         if ( !p )
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_rContext.getMutex() );
172cdf0e10cSrcweir             p = m_pPropertyArrayHelper;
173cdf0e10cSrcweir             if ( !p )
174cdf0e10cSrcweir             {
175cdf0e10cSrcweir                 // our own fixed and our aggregate's properties
176cdf0e10cSrcweir 	            Sequence< Property > aFixedProps;
177cdf0e10cSrcweir 	            Sequence< Property > aAggregateProps;
178cdf0e10cSrcweir                 m_rContext.describeFixedAndAggregateProperties( aFixedProps, aAggregateProps );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir                 // our dynamic properties
181cdf0e10cSrcweir                 Sequence< Property > aDynamicProps;
182cdf0e10cSrcweir                 m_aDynamicProperties.describeProperties( aDynamicProps );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir                 Sequence< Property > aOwnProps(
185cdf0e10cSrcweir                     ::comphelper::concatSequences( aFixedProps, aDynamicProps ) );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir                 p = new OPropertyArrayAggregationHelper( aOwnProps, aAggregateProps, &lcl_getPropertyInfos(), NEW_HANDLE_BASE );
188cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
189cdf0e10cSrcweir                 const_cast< PropertyBagHelper* >( this )->m_pPropertyArrayHelper = p;
190cdf0e10cSrcweir             }
191cdf0e10cSrcweir         } // if ( !p )
192cdf0e10cSrcweir         else
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir         return *p;
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     //--------------------------------------------------------------------
200cdf0e10cSrcweir     void PropertyBagHelper::addProperty( const ::rtl::OUString& _rName, ::sal_Int16 _nAttributes, const Any& _rInitialValue )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::addProperty" );
203cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_rContext.getMutex() );
204cdf0e10cSrcweir         impl_nts_checkDisposed_throw();
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         //----------------------------------------------
207cdf0e10cSrcweir         // check name sanity
208cdf0e10cSrcweir         ::comphelper::OPropertyArrayAggregationHelper& aPropInfo( impl_ts_getArrayHelper() );
209cdf0e10cSrcweir         if ( aPropInfo.hasPropertyByName( _rName ) )
210cdf0e10cSrcweir             throw PropertyExistException( _rName, m_rContext.getPropertiesInterface() );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         //----------------------------------------------
213cdf0e10cSrcweir         // normalize the REMOVEABLE attribute - the FormComponent service
214cdf0e10cSrcweir         // requires that all dynamic properties are REMOVEABLE
215cdf0e10cSrcweir         _nAttributes |= PropertyAttribute::REMOVEABLE;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         //----------------------------------------------
218cdf0e10cSrcweir         // find a free handle
219cdf0e10cSrcweir         sal_Int32 nHandle = impl_findFreeHandle( _rName );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         //----------------------------------------------
222cdf0e10cSrcweir         // register the property, and invalidate our property meta data
223cdf0e10cSrcweir         m_aDynamicProperties.addProperty( _rName, nHandle, _nAttributes, _rInitialValue );
224cdf0e10cSrcweir         impl_nts_invalidatePropertySetInfo();
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     //--------------------------------------------------------------------
228cdf0e10cSrcweir     void PropertyBagHelper::removeProperty( const ::rtl::OUString& _rName )
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::removeProperty" );
231cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_rContext.getMutex() );
232cdf0e10cSrcweir         impl_nts_checkDisposed_throw();
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         // check whether it's removeable at all
235cdf0e10cSrcweir         Reference< XMultiPropertySet > xMe( m_rContext.getPropertiesInterface(), UNO_QUERY_THROW );
236cdf0e10cSrcweir         Reference< XPropertySetInfo > xPSI( xMe->getPropertySetInfo(), UNO_QUERY_THROW );
237cdf0e10cSrcweir         Property aProperty( xPSI->getPropertyByName( _rName ) );
238cdf0e10cSrcweir         if ( ( aProperty.Attributes & PropertyAttribute::REMOVEABLE ) == 0 )
239cdf0e10cSrcweir             throw NotRemoveableException( _rName, xMe );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         m_aDynamicProperties.removeProperty( _rName );
242cdf0e10cSrcweir         impl_nts_invalidatePropertySetInfo();
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     //--------------------------------------------------------------------
246cdf0e10cSrcweir     namespace
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         //----------------------------------------------------------------
249cdf0e10cSrcweir         struct SelectNameOfProperty : public ::std::unary_function< Property, ::rtl::OUString >
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir             const ::rtl::OUString& operator()( const Property& _rProp ) const { return _rProp.Name; }
252cdf0e10cSrcweir         };
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         //----------------------------------------------------------------
255cdf0e10cSrcweir         struct SelectNameOfPropertyValue : public ::std::unary_function< PropertyValue, ::rtl::OUString >
256cdf0e10cSrcweir         {
257cdf0e10cSrcweir             const ::rtl::OUString& operator()( const PropertyValue& _rProp ) const { return _rProp.Name; }
258cdf0e10cSrcweir         };
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         //----------------------------------------------------------------
261cdf0e10cSrcweir         struct SelectValueOfPropertyValue : public ::std::unary_function< PropertyValue, Any >
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir             const Any& operator()( const PropertyValue& _rProp ) const { return _rProp.Value; }
264cdf0e10cSrcweir         };
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         //----------------------------------------------------------------
267cdf0e10cSrcweir         struct PropertyValueLessByName : public ::std::binary_function< PropertyValue, PropertyValue, bool >
268cdf0e10cSrcweir         {
269cdf0e10cSrcweir             bool operator()( const PropertyValue& _lhs, const PropertyValue _rhs ) const
270cdf0e10cSrcweir             {
271cdf0e10cSrcweir                 return _lhs.Name < _rhs.Name;
272cdf0e10cSrcweir             }
273cdf0e10cSrcweir         };
274cdf0e10cSrcweir     }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     //--------------------------------------------------------------------
277cdf0e10cSrcweir     Sequence< PropertyValue > PropertyBagHelper::getPropertyValues()
278cdf0e10cSrcweir     {
279cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::getPropertyValues" );
280cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_rContext.getMutex() );
281cdf0e10cSrcweir         impl_nts_checkDisposed_throw();
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         Reference< XMultiPropertySet > xMe( m_rContext.getPropertiesInterface(), UNO_QUERY_THROW );
284cdf0e10cSrcweir         Reference< XPropertySetInfo > xPSI( xMe->getPropertySetInfo(), UNO_QUERY_THROW );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         Sequence< Property > aProperties( xPSI->getProperties() );
287cdf0e10cSrcweir         Sequence< ::rtl::OUString > aPropertyNames( aProperties.getLength() );
288cdf0e10cSrcweir         ::std::transform( aProperties.getConstArray(), aProperties.getConstArray() + aProperties.getLength(),
289cdf0e10cSrcweir             aPropertyNames.getArray(), SelectNameOfProperty() );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         Sequence< Any > aValues;
292cdf0e10cSrcweir         try
293cdf0e10cSrcweir         {
294cdf0e10cSrcweir             aValues = xMe->getPropertyValues( aPropertyNames );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir             if ( aValues.getLength() != aPropertyNames.getLength() )
297cdf0e10cSrcweir                 throw RuntimeException();
298cdf0e10cSrcweir         }
299cdf0e10cSrcweir         catch( const RuntimeException& ) { throw; }
300cdf0e10cSrcweir         catch( const Exception& )
301cdf0e10cSrcweir         {
302cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir         Sequence< PropertyValue > aPropertyValues( aValues.getLength() );
305cdf0e10cSrcweir         PropertyValue* pPropertyValue = aPropertyValues.getArray();
306cdf0e10cSrcweir 
307cdf0e10cSrcweir         const ::rtl::OUString* pName = aPropertyNames.getConstArray();
308cdf0e10cSrcweir         const ::rtl::OUString* pNameEnd = aPropertyNames.getConstArray() + aPropertyNames.getLength();
309cdf0e10cSrcweir         const Any* pValue = aValues.getConstArray();
310cdf0e10cSrcweir         for ( ; pName != pNameEnd; ++pName, ++pValue, ++pPropertyValue )
311cdf0e10cSrcweir         {
312cdf0e10cSrcweir             pPropertyValue->Name = *pName;
313cdf0e10cSrcweir             pPropertyValue->Value = *pValue;
314cdf0e10cSrcweir         }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir         return aPropertyValues;
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     //--------------------------------------------------------------------
320cdf0e10cSrcweir     void PropertyBagHelper::setPropertyValues( const Sequence< PropertyValue >& _rProps )
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir         // RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "forms", "dev@dba.openoffice.org", "PropertyBagHelper::setPropertyValues" );
323cdf0e10cSrcweir         ::osl::ClearableMutexGuard aGuard( m_rContext.getMutex() );
324cdf0e10cSrcweir         impl_nts_checkDisposed_throw();
325cdf0e10cSrcweir 
326cdf0e10cSrcweir         sal_Int32 nPropertyValues = _rProps.getLength();
327cdf0e10cSrcweir 
328cdf0e10cSrcweir         // XMultiPropertySet::setPropertyValues expects its arguments to be sorted by name
329cdf0e10cSrcweir         // while XPropertyAccess::setPropertyValues doesn't. So first of all, sort.
330cdf0e10cSrcweir         Sequence< PropertyValue > aSortedProps( _rProps );
331cdf0e10cSrcweir         ::std::sort( aSortedProps.getArray(), aSortedProps.getArray() + nPropertyValues, PropertyValueLessByName() );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir         // also, XPropertyAccess::setPropertyValues is expected to throw an UnknownPropertyException
334cdf0e10cSrcweir         // for unsupported properties, while XMultiPropertySet::setPropertyValues is expected to ignore
335cdf0e10cSrcweir         // those. So, check for unsupported properties first.
336cdf0e10cSrcweir         ::comphelper::OPropertyArrayAggregationHelper& rArrayHelper( impl_ts_getArrayHelper() );
337cdf0e10cSrcweir         for (   const PropertyValue* pProperties = aSortedProps.getConstArray();
338cdf0e10cSrcweir                 pProperties != aSortedProps.getConstArray() + nPropertyValues;
339cdf0e10cSrcweir                 ++pProperties
340cdf0e10cSrcweir             )
341cdf0e10cSrcweir         {
342cdf0e10cSrcweir             if ( !rArrayHelper.hasPropertyByName( pProperties->Name ) )
343cdf0e10cSrcweir                 throw UnknownPropertyException( pProperties->Name, m_rContext.getPropertiesInterface() );
344cdf0e10cSrcweir         }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir         // Now finally split into a Name and a Value sequence, and forward to
347cdf0e10cSrcweir         // XMultiPropertySet::setPropertyValues
348cdf0e10cSrcweir         Sequence< ::rtl::OUString > aNames( nPropertyValues );
349cdf0e10cSrcweir         ::std::transform( aSortedProps.getConstArray(), aSortedProps.getConstArray() + nPropertyValues,
350cdf0e10cSrcweir             aNames.getArray(), SelectNameOfPropertyValue() );
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         Sequence< Any > aValues( nPropertyValues );
353cdf0e10cSrcweir         ::std::transform( aSortedProps.getConstArray(), aSortedProps.getConstArray() + nPropertyValues,
354cdf0e10cSrcweir             aValues.getArray(), SelectValueOfPropertyValue() );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir         Reference< XMultiPropertySet > xMe( m_rContext.getPropertiesInterface(), UNO_QUERY_THROW );
357cdf0e10cSrcweir 
358cdf0e10cSrcweir         aGuard.clear();
359cdf0e10cSrcweir         xMe->setPropertyValues( aNames, aValues );
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir //........................................................................
363cdf0e10cSrcweir } // namespace frm
364cdf0e10cSrcweir //........................................................................
365cdf0e10cSrcweir 
366