LibreOffice Module comphelper (master)  1
ChainablePropertySet.cxx
Go to the documentation of this file.
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 
23 
24 
25 #include <memory>
26 
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;
32 
33 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, comphelper::SolarMutex* pMutex )
34  throw()
35 : mpMutex ( pMutex )
36 , mxInfo ( pInfo )
37 {
38 }
39 
40 ChainablePropertySet::~ChainablePropertySet()
41  throw()
42 {
43 }
44 
45 // XPropertySet
46 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
47 {
48  return mxInfo.get();
49 }
50 
51 void SAL_CALL ChainablePropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
52 {
53  // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
54  std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
55  if (mpMutex)
56  xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
57 
58  PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
59 
60  if( aIter == mxInfo->maMap.end())
61  throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
62 
63  _preSetValues();
64  _setSingleValue( *((*aIter).second), rValue );
65  _postSetValues();
66 }
67 
68 Any SAL_CALL ChainablePropertySet::getPropertyValue( const OUString& rPropertyName )
69 {
70  // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
71  std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
72  if (mpMutex)
73  xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
74 
75  PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
76 
77  if( aIter == mxInfo->maMap.end())
78  throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
79 
80  Any aAny;
81  _preGetValues ();
82  _getSingleValue( *((*aIter).second), aAny );
83  _postGetValues ();
84 
85  return aAny;
86 }
87 
88 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
89 {
90  // todo
91 }
92 
93 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
94 {
95  // todo
96 }
97 
98 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
99 {
100  // todo
101 }
102 
103 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
104 {
105  // todo
106 }
107 
108 // XMultiPropertySet
109 void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues)
110 {
111  // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
112  std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
113  if (mpMutex)
114  xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
115 
116  const sal_Int32 nCount = rPropertyNames.getLength();
117 
118  if( nCount != rValues.getLength() )
119  throw IllegalArgumentException();
120 
121  if( !nCount )
122  return;
123 
124  _preSetValues();
125 
126  const Any * pAny = rValues.getConstArray();
127  const OUString * pString = rPropertyNames.getConstArray();
128  PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
129 
130  for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
131  {
132  aIter = mxInfo->maMap.find ( *pString );
133  if ( aIter == aEnd )
134  throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
135 
136  _setSingleValue ( *((*aIter).second), *pAny );
137  }
138 
139  _postSetValues();
140 }
141 
142 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
143 {
144  // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
145  std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
146  if (mpMutex)
147  xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
148 
149  const sal_Int32 nCount = rPropertyNames.getLength();
150 
151  Sequence < Any > aValues ( nCount );
152 
153  if( nCount )
154  {
155  _preGetValues();
156 
157  Any * pAny = aValues.getArray();
158  const OUString * pString = rPropertyNames.getConstArray();
159  PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
160 
161  for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
162  {
163  aIter = mxInfo->maMap.find ( *pString );
164  if ( aIter == aEnd )
165  throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
166 
167  _getSingleValue ( *((*aIter).second), *pAny );
168  }
169 
170  _postGetValues();
171  }
172  return aValues;
173 }
174 
175 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
176 {
177  // todo
178 }
179 
180 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
181 {
182  // todo
183 }
184 
185 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
186 {
187  // todo
188 }
189 
190 // XPropertyState
191 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
192 {
193  PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find( PropertyName );
194  if( aIter == mxInfo->maMap.end())
195  throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
196 
197  return PropertyState_AMBIGUOUS_VALUE;
198 }
199 
200 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
201 {
202  const sal_Int32 nCount = rPropertyNames.getLength();
203 
204  Sequence< PropertyState > aStates( nCount );
205  if( nCount )
206  {
207  PropertyState * pState = aStates.getArray();
208  const OUString * pString = rPropertyNames.getConstArray();
209  PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
210 
211  for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
212  {
213  aIter = mxInfo->maMap.find ( *pString );
214  if ( aIter == aEnd )
215  throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
216  }
217  }
218  return aStates;
219 }
220 
221 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
222 {
223  PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
224 
225  if( aIter == mxInfo->maMap.end())
226  throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
227 }
228 
229 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
230 {
231  PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
232 
233  if( aIter == mxInfo->maMap.end())
234  throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
235  return Any();
236 }
237 
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int nCount
int i
SolarMutex, needed for VCL's Application::GetSolarMutex().
Definition: solarmutex.hxx:46