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