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/ChainablePropertySet.hxx>
21 #include <comphelper/ChainablePropertySetInfo.hxx>
22 #include <comphelper/solarmutex.hxx>
27 using namespace ::comphelper
;
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::lang
;
31 using namespace ::com::sun::star::beans
;
33 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo
* pInfo
, comphelper::SolarMutex
* pMutex
)
40 ChainablePropertySet::~ChainablePropertySet()
46 Reference
< XPropertySetInfo
> SAL_CALL
ChainablePropertySet::getPropertySetInfo( )
51 void SAL_CALL
ChainablePropertySet::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
53 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
54 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
56 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
58 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
60 if( aIter
== mxInfo
->maMap
.end())
61 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
64 _setSingleValue( *((*aIter
).second
), rValue
);
68 Any SAL_CALL
ChainablePropertySet::getPropertyValue( const OUString
& rPropertyName
)
70 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
71 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
73 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
75 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
77 if( aIter
== mxInfo
->maMap
.end())
78 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
82 _getSingleValue( *((*aIter
).second
), aAny
);
88 void SAL_CALL
ChainablePropertySet::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
93 void SAL_CALL
ChainablePropertySet::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
98 void SAL_CALL
ChainablePropertySet::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
103 void SAL_CALL
ChainablePropertySet::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
109 void SAL_CALL
ChainablePropertySet::setPropertyValues(const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rValues
)
111 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
112 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
114 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
116 const sal_Int32 nCount
= rPropertyNames
.getLength();
118 if( nCount
!= rValues
.getLength() )
119 throw IllegalArgumentException();
125 const Any
* pAny
= rValues
.getConstArray();
126 const OUString
* pString
= rPropertyNames
.getConstArray();
127 PropertyInfoHash::const_iterator aEnd
= mxInfo
->maMap
.end(), aIter
;
129 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
131 aIter
= mxInfo
->maMap
.find ( *pString
);
133 throw RuntimeException( *pString
, static_cast< XPropertySet
* >( this ) );
135 _setSingleValue ( *((*aIter
).second
), *pAny
);
142 Sequence
< Any
> SAL_CALL
ChainablePropertySet::getPropertyValues(const Sequence
< OUString
>& rPropertyNames
)
144 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
145 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
147 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
149 const sal_Int32 nCount
= rPropertyNames
.getLength();
151 Sequence
< Any
> aValues ( nCount
);
157 Any
* pAny
= aValues
.getArray();
158 const OUString
* pString
= rPropertyNames
.getConstArray();
159 PropertyInfoHash::const_iterator aEnd
= mxInfo
->maMap
.end(), aIter
;
161 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
163 aIter
= mxInfo
->maMap
.find ( *pString
);
165 throw RuntimeException( *pString
, static_cast< XPropertySet
* >( this ) );
167 _getSingleValue ( *((*aIter
).second
), *pAny
);
175 void SAL_CALL
ChainablePropertySet::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
180 void SAL_CALL
ChainablePropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
185 void SAL_CALL
ChainablePropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
191 PropertyState SAL_CALL
ChainablePropertySet::getPropertyState( const OUString
& PropertyName
)
193 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find( PropertyName
);
194 if( aIter
== mxInfo
->maMap
.end())
195 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
197 return PropertyState_AMBIGUOUS_VALUE
;
200 Sequence
< PropertyState
> SAL_CALL
ChainablePropertySet::getPropertyStates( const Sequence
< OUString
>& rPropertyNames
)
202 const sal_Int32 nCount
= rPropertyNames
.getLength();
204 Sequence
< PropertyState
> aStates( nCount
);
207 PropertyState
* pState
= aStates
.getArray();
208 const OUString
* pString
= rPropertyNames
.getConstArray();
209 PropertyInfoHash::const_iterator aEnd
= mxInfo
->maMap
.end(), aIter
;
211 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pState
)
213 aIter
= mxInfo
->maMap
.find ( *pString
);
215 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
221 void SAL_CALL
ChainablePropertySet::setPropertyToDefault( const OUString
& rPropertyName
)
223 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
225 if( aIter
== mxInfo
->maMap
.end())
226 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
229 Any SAL_CALL
ChainablePropertySet::getPropertyDefault( const OUString
& rPropertyName
)
231 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
233 if( aIter
== mxInfo
->maMap
.end())
234 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */