xref: /aoo41x/main/svx/source/table/propertyset.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include "propertyset.hxx"
32 
33 using ::rtl::OUString;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::lang;
37 
38 namespace comphelper {
39 
40 // -----------------------------------------------------------------------------
41 // FastPropertySetInfo
42 // -----------------------------------------------------------------------------
43 
44 FastPropertySetInfo::FastPropertySetInfo()
45 {
46 }
47 
48 // -----------------------------------------------------------------------------
49 
50 FastPropertySetInfo::FastPropertySetInfo( const PropertyVector& rProps )
51 {
52 	addProperties( rProps );
53 }
54 
55 // -----------------------------------------------------------------------------
56 
57 FastPropertySetInfo::~FastPropertySetInfo()
58 {
59 }
60 
61 // -----------------------------------------------------------------------------
62 
63 void FastPropertySetInfo::addProperty( const Property& rProperty )
64 {
65 	maProperties.push_back( rProperty );
66 	maMap[ rProperty.Name ] = maProperties.size() - 1;
67 }
68 
69 // -----------------------------------------------------------------------------
70 
71 void FastPropertySetInfo::addProperties( const PropertyVector& rProps )
72 {
73 	sal_uInt32 nIndex = maProperties.size();
74 	sal_uInt32 nCount = rProps.size();
75 	maProperties.resize( nIndex + nCount );
76 	PropertyVector::const_iterator aIter( rProps.begin() );
77 	while( nCount-- )
78 	{
79 		const Property& rProperty = (*aIter++);
80 		maProperties[nIndex] = rProperty;
81 		maMap[ rProperty.Name ] = nIndex++;
82 	}
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 const Property& FastPropertySetInfo::getProperty( const OUString& aName ) throw (UnknownPropertyException )
88 {
89 	PropertyMap::iterator aIter( maMap.find( aName ) );
90 	if( aIter == maMap.end() )
91 		throw UnknownPropertyException();
92 	return maProperties[(*aIter).second];
93 }
94 
95 // -----------------------------------------------------------------------------
96 
97 const Property* FastPropertySetInfo::hasProperty( const OUString& aName )
98 {
99 	PropertyMap::iterator aIter( maMap.find( aName ) );
100 	if( aIter == maMap.end() )
101 		return 0;
102 	else
103 		return &maProperties[(*aIter).second];
104 }
105 
106 // -----------------------------------------------------------------------------
107 // XPropertySetInfo
108 // -----------------------------------------------------------------------------
109 
110 Sequence< Property > SAL_CALL FastPropertySetInfo::getProperties() throw (RuntimeException)
111 {
112 	return Sequence< Property >( &maProperties[0], maProperties.size() );
113 }
114 
115 // -----------------------------------------------------------------------------
116 
117 Property SAL_CALL FastPropertySetInfo::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
118 {
119 	return getProperty( aName );
120 }
121 
122 // -----------------------------------------------------------------------------
123 
124 sal_Bool SAL_CALL FastPropertySetInfo::hasPropertyByName( const OUString& aName ) throw (RuntimeException)
125 {
126 	return hasProperty( aName ) != 0 ? sal_True : sal_False;;
127 }
128 
129 // -----------------------------------------------------------------------------
130 // FastPropertySet
131 // -----------------------------------------------------------------------------
132 
133 FastPropertySet::FastPropertySet( const rtl::Reference< FastPropertySetInfo >& xInfo )
134 : mxInfo( xInfo )
135 {
136 }
137 
138 // -----------------------------------------------------------------------------
139 
140 FastPropertySet::~FastPropertySet()
141 {
142 }
143 
144 // -----------------------------------------------------------------------------
145 // XPropertySet
146 // -----------------------------------------------------------------------------
147 
148 Reference< XPropertySetInfo > SAL_CALL FastPropertySet::getPropertySetInfo(  ) throw (RuntimeException)
149 {
150 	return Reference< XPropertySetInfo >( mxInfo.get() );
151 }
152 
153 // -----------------------------------------------------------------------------
154 
155 void SAL_CALL FastPropertySet::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
156 {
157 	setFastPropertyValue( mxInfo->getProperty( aPropertyName ).Handle, aValue );
158 }
159 
160 // -----------------------------------------------------------------------------
161 
162 Any SAL_CALL FastPropertySet::getPropertyValue( const OUString& aPropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
163 {
164 	return getFastPropertyValue( mxInfo->getProperty( aPropertyName ).Handle );
165 }
166 
167 // -----------------------------------------------------------------------------
168 
169 void SAL_CALL FastPropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
170 {
171 }
172 
173 // -----------------------------------------------------------------------------
174 
175 void SAL_CALL FastPropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
176 {
177 }
178 
179 // -----------------------------------------------------------------------------
180 
181 void SAL_CALL FastPropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
182 {
183 }
184 
185 // -----------------------------------------------------------------------------
186 
187 void SAL_CALL FastPropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
188 {
189 }
190 
191 // -----------------------------------------------------------------------------
192 // XMultiPropertySet
193 // -----------------------------------------------------------------------------
194 
195 void SAL_CALL FastPropertySet::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
196 {
197 	const OUString* pPropertyNames = aPropertyNames.getConstArray();
198 	const Any* pValues = aValues.getConstArray();
199 	sal_Int32 nCount = aPropertyNames.getLength();
200 	if( nCount != aValues.getLength() )
201 		throw IllegalArgumentException();
202 
203 	while( nCount-- )
204 	{
205 		const Property* pProperty = mxInfo->hasProperty( *pPropertyNames++ );
206 		if( pProperty ) try
207 		{
208 			setFastPropertyValue( pProperty->Handle, *pValues );
209 		}
210 		catch( UnknownPropertyException& )
211 		{
212 		}
213 		pValues++;
214 	}
215 }
216 
217 // -----------------------------------------------------------------------------
218 
219 Sequence< Any > SAL_CALL FastPropertySet::getPropertyValues( const Sequence< OUString >& aPropertyNames ) throw (RuntimeException)
220 {
221 	sal_Int32 nCount = aPropertyNames.getLength();
222 	Sequence< Any > aValues( nCount );
223 
224 	const OUString* pPropertyNames = aPropertyNames.getConstArray();
225 	Any* pValues = aValues.getArray();
226 	while( nCount-- )
227 	{
228 		const Property* pProperty = mxInfo->hasProperty( *pPropertyNames++ );
229 		if( pProperty ) try
230 		{
231 			*pValues = getFastPropertyValue( pProperty->Handle );
232 		}
233 		catch( UnknownPropertyException& )
234 		{
235 		}
236 		pValues++;
237 	}
238 	return aValues;
239 }
240 
241 // -----------------------------------------------------------------------------
242 
243 void SAL_CALL FastPropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
244 {
245 }
246 
247 // -----------------------------------------------------------------------------
248 
249 void SAL_CALL FastPropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
250 {
251 }
252 
253 // -----------------------------------------------------------------------------
254 
255 void SAL_CALL FastPropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
256 {
257 }
258 
259 }
260