1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/propertysetinfo.hxx>
21 #include <comphelper/propertysethelper.hxx>
22 #include <osl/diagnose.h>
23 #include <rtl/ref.hxx>
27 using namespace ::comphelper
;
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::lang
;
35 class PropertySetHelperImpl
38 PropertyMapEntry
const * find( const OUString
& aName
) const throw();
40 rtl::Reference
<PropertySetInfo
> mxInfo
;
44 PropertyMapEntry
const * PropertySetHelperImpl::find( const OUString
& aName
) const throw()
46 PropertyMap::const_iterator aIter
= mxInfo
->getPropertyMap().find( aName
);
48 if( mxInfo
->getPropertyMap().end() != aIter
)
50 return (*aIter
).second
;
59 PropertySetHelper::PropertySetHelper( rtl::Reference
<comphelper::PropertySetInfo
> const & xInfo
) throw()
60 : mpImpl(new PropertySetHelperImpl
)
62 mpImpl
->mxInfo
= xInfo
;
65 PropertySetHelper::~PropertySetHelper() throw()
70 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( )
72 return mpImpl
->mxInfo
.get();
75 void SAL_CALL
PropertySetHelper::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
)
77 PropertyMapEntry
const * aEntries
[2];
78 aEntries
[0] = mpImpl
->find( aPropertyName
);
80 if( nullptr == aEntries
[0] )
81 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
83 aEntries
[1] = nullptr;
85 _setPropertyValues( aEntries
, &aValue
);
88 Any SAL_CALL
PropertySetHelper::getPropertyValue( const OUString
& PropertyName
)
90 PropertyMapEntry
const * aEntries
[2];
91 aEntries
[0] = mpImpl
->find( PropertyName
);
93 if( nullptr == aEntries
[0] )
94 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
96 aEntries
[1] = nullptr;
99 _getPropertyValues( aEntries
, &aAny
);
104 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
109 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
114 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
119 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
125 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rValues
)
127 const sal_Int32 nCount
= rPropertyNames
.getLength();
129 if( nCount
!= rValues
.getLength() )
130 throw IllegalArgumentException();
134 std::unique_ptr
<PropertyMapEntry
const *[]> pEntries(new PropertyMapEntry
const *[nCount
+1]);
135 pEntries
[nCount
] = nullptr;
136 const OUString
* pNames
= rPropertyNames
.getConstArray();
138 bool bUnknown
= false;
140 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
142 pEntries
[n
] = mpImpl
->find( *pNames
);
143 bUnknown
= nullptr == pEntries
[n
];
147 _setPropertyValues( pEntries
.get(), rValues
.getConstArray() );
150 throw RuntimeException( *pNames
, static_cast< XPropertySet
* >( this ) );
154 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues(const Sequence
< OUString
>& rPropertyNames
)
156 const sal_Int32 nCount
= rPropertyNames
.getLength();
158 Sequence
< Any
> aValues
;
161 std::unique_ptr
<PropertyMapEntry
const *[]> pEntries(new PropertyMapEntry
const *[nCount
+1]);
162 pEntries
[nCount
] = nullptr;
163 const OUString
* pNames
= rPropertyNames
.getConstArray();
165 bool bUnknown
= false;
167 for( n
= 0; !bUnknown
&& ( n
< nCount
); n
++, pNames
++ )
169 pEntries
[n
] = mpImpl
->find( *pNames
);
170 bUnknown
= nullptr == pEntries
[n
];
175 aValues
.realloc(nCount
);
176 _getPropertyValues( pEntries
.get(), aValues
.getArray() );
180 throw RuntimeException( *pNames
, static_cast< XPropertySet
* >( this ) );
186 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
191 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
196 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
202 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const OUString
& PropertyName
)
204 PropertyMapEntry
const * aEntries
[2];
206 aEntries
[0] = mpImpl
->find( PropertyName
);
207 if( aEntries
[0] == nullptr )
208 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
210 aEntries
[1] = nullptr;
212 PropertyState
aState(PropertyState_AMBIGUOUS_VALUE
);
213 _getPropertyStates( aEntries
, &aState
);
218 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< OUString
>& aPropertyName
)
220 const sal_Int32 nCount
= aPropertyName
.getLength();
222 Sequence
< PropertyState
> aStates( nCount
);
226 const OUString
* pNames
= aPropertyName
.getConstArray();
228 bool bUnknown
= false;
230 std::unique_ptr
<PropertyMapEntry
const *[]> pEntries(new PropertyMapEntry
const *[nCount
+1]);
233 for( n
= 0; !bUnknown
&& (n
< nCount
); n
++, pNames
++ )
235 pEntries
[n
] = mpImpl
->find( *pNames
);
236 bUnknown
= nullptr == pEntries
[n
];
239 pEntries
[nCount
] = nullptr;
242 _getPropertyStates( pEntries
.get(), aStates
.getArray() );
245 throw UnknownPropertyException( *pNames
, static_cast< XPropertySet
* >( this ) );
251 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const OUString
& PropertyName
)
253 PropertyMapEntry
const *pEntry
= mpImpl
->find( PropertyName
);
254 if( nullptr == pEntry
)
255 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
257 _setPropertyToDefault( pEntry
);
260 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const OUString
& aPropertyName
)
262 PropertyMapEntry
const * pEntry
= mpImpl
->find( aPropertyName
);
263 if( nullptr == pEntry
)
264 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
266 return _getPropertyDefault( pEntry
);
269 void PropertySetHelper::_getPropertyStates(
270 const comphelper::PropertyMapEntry
**, PropertyState
*)
272 OSL_FAIL( "you have to implement this yourself!");
276 PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry
*)
278 OSL_FAIL( "you have to implement this yourself!");
281 Any
PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry
*)
283 OSL_FAIL( "you have to implement this yourself!");
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */