xref: /trunk/main/svx/source/table/propertyset.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include "propertyset.hxx"
28 
29 using ::rtl::OUString;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::beans;
32 using namespace ::com::sun::star::lang;
33 
34 namespace comphelper {
35 
36 // -----------------------------------------------------------------------------
37 // FastPropertySetInfo
38 // -----------------------------------------------------------------------------
39 
FastPropertySetInfo()40 FastPropertySetInfo::FastPropertySetInfo()
41 {
42 }
43 
44 // -----------------------------------------------------------------------------
45 
FastPropertySetInfo(const PropertyVector & rProps)46 FastPropertySetInfo::FastPropertySetInfo( const PropertyVector& rProps )
47 {
48 	addProperties( rProps );
49 }
50 
51 // -----------------------------------------------------------------------------
52 
~FastPropertySetInfo()53 FastPropertySetInfo::~FastPropertySetInfo()
54 {
55 }
56 
57 // -----------------------------------------------------------------------------
58 
addProperty(const Property & rProperty)59 void FastPropertySetInfo::addProperty( const Property& rProperty )
60 {
61 	maProperties.push_back( rProperty );
62 	maMap[ rProperty.Name ] = maProperties.size() - 1;
63 }
64 
65 // -----------------------------------------------------------------------------
66 
addProperties(const PropertyVector & rProps)67 void FastPropertySetInfo::addProperties( const PropertyVector& rProps )
68 {
69 	sal_uInt32 nIndex = maProperties.size();
70 	sal_uInt32 nCount = rProps.size();
71 	maProperties.resize( nIndex + nCount );
72 	PropertyVector::const_iterator aIter( rProps.begin() );
73 	while( nCount-- )
74 	{
75 		const Property& rProperty = (*aIter++);
76 		maProperties[nIndex] = rProperty;
77 		maMap[ rProperty.Name ] = nIndex++;
78 	}
79 }
80 
81 // -----------------------------------------------------------------------------
82 
getProperty(const OUString & aName)83 const Property& FastPropertySetInfo::getProperty( const OUString& aName ) throw (UnknownPropertyException )
84 {
85 	PropertyMap::iterator aIter( maMap.find( aName ) );
86 	if( aIter == maMap.end() )
87 		throw UnknownPropertyException();
88 	return maProperties[(*aIter).second];
89 }
90 
91 // -----------------------------------------------------------------------------
92 
hasProperty(const OUString & aName)93 const Property* FastPropertySetInfo::hasProperty( const OUString& aName )
94 {
95 	PropertyMap::iterator aIter( maMap.find( aName ) );
96 	if( aIter == maMap.end() )
97 		return 0;
98 	else
99 		return &maProperties[(*aIter).second];
100 }
101 
102 // -----------------------------------------------------------------------------
103 // XPropertySetInfo
104 // -----------------------------------------------------------------------------
105 
getProperties()106 Sequence< Property > SAL_CALL FastPropertySetInfo::getProperties() throw (RuntimeException)
107 {
108 	return Sequence< Property >( &maProperties[0], maProperties.size() );
109 }
110 
111 // -----------------------------------------------------------------------------
112 
getPropertyByName(const OUString & aName)113 Property SAL_CALL FastPropertySetInfo::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
114 {
115 	return getProperty( aName );
116 }
117 
118 // -----------------------------------------------------------------------------
119 
hasPropertyByName(const OUString & aName)120 sal_Bool SAL_CALL FastPropertySetInfo::hasPropertyByName( const OUString& aName ) throw (RuntimeException)
121 {
122 	return hasProperty( aName ) != 0 ? sal_True : sal_False;;
123 }
124 
125 // -----------------------------------------------------------------------------
126 // FastPropertySet
127 // -----------------------------------------------------------------------------
128 
FastPropertySet(const rtl::Reference<FastPropertySetInfo> & xInfo)129 FastPropertySet::FastPropertySet( const rtl::Reference< FastPropertySetInfo >& xInfo )
130 : mxInfo( xInfo )
131 {
132 }
133 
134 // -----------------------------------------------------------------------------
135 
~FastPropertySet()136 FastPropertySet::~FastPropertySet()
137 {
138 }
139 
140 // -----------------------------------------------------------------------------
141 // XPropertySet
142 // -----------------------------------------------------------------------------
143 
getPropertySetInfo()144 Reference< XPropertySetInfo > SAL_CALL FastPropertySet::getPropertySetInfo(  ) throw (RuntimeException)
145 {
146 	return Reference< XPropertySetInfo >( mxInfo.get() );
147 }
148 
149 // -----------------------------------------------------------------------------
150 
setPropertyValue(const OUString & aPropertyName,const Any & aValue)151 void SAL_CALL FastPropertySet::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
152 {
153 	setFastPropertyValue( mxInfo->getProperty( aPropertyName ).Handle, aValue );
154 }
155 
156 // -----------------------------------------------------------------------------
157 
getPropertyValue(const OUString & aPropertyName)158 Any SAL_CALL FastPropertySet::getPropertyValue( const OUString& aPropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
159 {
160 	return getFastPropertyValue( mxInfo->getProperty( aPropertyName ).Handle );
161 }
162 
163 // -----------------------------------------------------------------------------
164 
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)165 void SAL_CALL FastPropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
166 {
167 }
168 
169 // -----------------------------------------------------------------------------
170 
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)171 void SAL_CALL FastPropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
172 {
173 }
174 
175 // -----------------------------------------------------------------------------
176 
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)177 void SAL_CALL FastPropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
178 {
179 }
180 
181 // -----------------------------------------------------------------------------
182 
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)183 void SAL_CALL FastPropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
184 {
185 }
186 
187 // -----------------------------------------------------------------------------
188 // XMultiPropertySet
189 // -----------------------------------------------------------------------------
190 
setPropertyValues(const Sequence<OUString> & aPropertyNames,const Sequence<Any> & aValues)191 void SAL_CALL FastPropertySet::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
192 {
193 	const OUString* pPropertyNames = aPropertyNames.getConstArray();
194 	const Any* pValues = aValues.getConstArray();
195 	sal_Int32 nCount = aPropertyNames.getLength();
196 	if( nCount != aValues.getLength() )
197 		throw IllegalArgumentException();
198 
199 	while( nCount-- )
200 	{
201 		const Property* pProperty = mxInfo->hasProperty( *pPropertyNames++ );
202 		if( pProperty ) try
203 		{
204 			setFastPropertyValue( pProperty->Handle, *pValues );
205 		}
206 		catch( UnknownPropertyException& )
207 		{
208 		}
209 		pValues++;
210 	}
211 }
212 
213 // -----------------------------------------------------------------------------
214 
getPropertyValues(const Sequence<OUString> & aPropertyNames)215 Sequence< Any > SAL_CALL FastPropertySet::getPropertyValues( const Sequence< OUString >& aPropertyNames ) throw (RuntimeException)
216 {
217 	sal_Int32 nCount = aPropertyNames.getLength();
218 	Sequence< Any > aValues( nCount );
219 
220 	const OUString* pPropertyNames = aPropertyNames.getConstArray();
221 	Any* pValues = aValues.getArray();
222 	while( nCount-- )
223 	{
224 		const Property* pProperty = mxInfo->hasProperty( *pPropertyNames++ );
225 		if( pProperty ) try
226 		{
227 			*pValues = getFastPropertyValue( pProperty->Handle );
228 		}
229 		catch( UnknownPropertyException& )
230 		{
231 		}
232 		pValues++;
233 	}
234 	return aValues;
235 }
236 
237 // -----------------------------------------------------------------------------
238 
addPropertiesChangeListener(const Sequence<OUString> &,const Reference<XPropertiesChangeListener> &)239 void SAL_CALL FastPropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
240 {
241 }
242 
243 // -----------------------------------------------------------------------------
244 
removePropertiesChangeListener(const Reference<XPropertiesChangeListener> &)245 void SAL_CALL FastPropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
246 {
247 }
248 
249 // -----------------------------------------------------------------------------
250 
firePropertiesChangeEvent(const Sequence<OUString> &,const Reference<XPropertiesChangeListener> &)251 void SAL_CALL FastPropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
252 {
253 }
254 
255 }
256