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>
28 using namespace ::comphelper
;
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::beans
;
34 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo
* pInfo
, comphelper::SolarMutex
* pMutex
)
41 ChainablePropertySet::~ChainablePropertySet()
47 Reference
< XPropertySetInfo
> SAL_CALL
ChainablePropertySet::getPropertySetInfo( )
52 void SAL_CALL
ChainablePropertySet::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
54 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
55 std::optional
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
57 xMutexGuard
.emplace( mpMutex
);
59 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
61 if( aIter
== mxInfo
->maMap
.end())
62 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
65 _setSingleValue( *((*aIter
).second
), rValue
);
69 Any SAL_CALL
ChainablePropertySet::getPropertyValue( const OUString
& rPropertyName
)
71 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
72 std::optional
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
74 xMutexGuard
.emplace( mpMutex
);
76 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
78 if( aIter
== mxInfo
->maMap
.end())
79 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
83 _getSingleValue( *((*aIter
).second
), aAny
);
89 void SAL_CALL
ChainablePropertySet::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
94 void SAL_CALL
ChainablePropertySet::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
99 void SAL_CALL
ChainablePropertySet::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
104 void SAL_CALL
ChainablePropertySet::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
110 void SAL_CALL
ChainablePropertySet::setPropertyValues(const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rValues
)
112 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
113 std::optional
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
115 xMutexGuard
.emplace( mpMutex
);
117 const sal_Int32 nCount
= rPropertyNames
.getLength();
119 if( nCount
!= rValues
.getLength() )
120 throw IllegalArgumentException(u
"lengths do not match"_ustr
, static_cast<cppu::OWeakObject
*>(this), -1);
127 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
129 auto aIter
= mxInfo
->maMap
.find(rPropertyNames
[i
]);
130 if (aIter
== mxInfo
->maMap
.end())
131 throw RuntimeException(rPropertyNames
[i
], static_cast<XPropertySet
*>(this));
133 _setSingleValue(*((*aIter
).second
), rValues
[i
]);
139 Sequence
< Any
> SAL_CALL
ChainablePropertySet::getPropertyValues(const Sequence
< OUString
>& rPropertyNames
)
141 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
142 std::optional
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
144 xMutexGuard
.emplace( mpMutex
);
146 const sal_Int32 nCount
= rPropertyNames
.getLength();
148 Sequence
< Any
> aValues ( nCount
);
154 Any
* pAny
= aValues
.getArray();
155 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
157 auto aIter
= mxInfo
->maMap
.find(rPropertyNames
[i
]);
158 if (aIter
== mxInfo
->maMap
.end())
159 throw RuntimeException(rPropertyNames
[i
], static_cast<XPropertySet
*>(this));
161 _getSingleValue(*((*aIter
).second
), pAny
[i
]);
169 void SAL_CALL
ChainablePropertySet::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
174 void SAL_CALL
ChainablePropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
179 void SAL_CALL
ChainablePropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
185 PropertyState SAL_CALL
ChainablePropertySet::getPropertyState( const OUString
& PropertyName
)
187 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find( PropertyName
);
188 if( aIter
== mxInfo
->maMap
.end())
189 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
191 return PropertyState_AMBIGUOUS_VALUE
;
194 Sequence
< PropertyState
> SAL_CALL
ChainablePropertySet::getPropertyStates( const Sequence
< OUString
>& rPropertyNames
)
196 const sal_Int32 nCount
= rPropertyNames
.getLength();
198 Sequence
< PropertyState
> aStates( nCount
);
201 PropertyState
* pState
= aStates
.getArray();
202 PropertyInfoHash::const_iterator aEnd
= mxInfo
->maMap
.end(), aIter
;
204 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
206 aIter
= mxInfo
->maMap
.find(rPropertyNames
[i
]);
208 throw UnknownPropertyException(rPropertyNames
[i
], static_cast<XPropertySet
*>(this));
210 pState
[i
] = PropertyState_AMBIGUOUS_VALUE
;
216 void SAL_CALL
ChainablePropertySet::setPropertyToDefault( const OUString
& rPropertyName
)
218 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
220 if( aIter
== mxInfo
->maMap
.end())
221 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
224 Any SAL_CALL
ChainablePropertySet::getPropertyDefault( const OUString
& rPropertyName
)
226 PropertyInfoHash::const_iterator aIter
= mxInfo
->maMap
.find ( rPropertyName
);
228 if( aIter
== mxInfo
->maMap
.end())
229 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */