1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include "propertyset.hxx"
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
;
37 namespace comphelper
{
39 // -----------------------------------------------------------------------------
40 // FastPropertySetInfo
41 // -----------------------------------------------------------------------------
43 FastPropertySetInfo::FastPropertySetInfo( const PropertyVector
& rProps
)
45 addProperties( rProps
);
48 // -----------------------------------------------------------------------------
50 FastPropertySetInfo::~FastPropertySetInfo()
54 // -----------------------------------------------------------------------------
56 void FastPropertySetInfo::addProperties( const PropertyVector
& rProps
)
58 sal_uInt32 nIndex
= maProperties
.size();
59 sal_uInt32 nCount
= rProps
.size();
60 maProperties
.resize( nIndex
+ nCount
);
61 PropertyVector::const_iterator
aIter( rProps
.begin() );
64 const Property
& rProperty
= (*aIter
++);
65 maProperties
[nIndex
] = rProperty
;
66 maMap
[ rProperty
.Name
] = nIndex
++;
70 // -----------------------------------------------------------------------------
72 const Property
& FastPropertySetInfo::getProperty( const OUString
& aName
) throw (UnknownPropertyException
)
74 PropertyMap::iterator
aIter( maMap
.find( aName
) );
75 if( aIter
== maMap
.end() )
76 throw UnknownPropertyException();
77 return maProperties
[(*aIter
).second
];
80 // -----------------------------------------------------------------------------
82 const Property
* FastPropertySetInfo::hasProperty( const OUString
& aName
)
84 PropertyMap::iterator
aIter( maMap
.find( aName
) );
85 if( aIter
== maMap
.end() )
88 return &maProperties
[(*aIter
).second
];
91 // -----------------------------------------------------------------------------
93 // -----------------------------------------------------------------------------
95 Sequence
< Property
> SAL_CALL
FastPropertySetInfo::getProperties() throw (RuntimeException
)
97 return Sequence
< Property
>( &maProperties
[0], maProperties
.size() );
100 // -----------------------------------------------------------------------------
102 Property SAL_CALL
FastPropertySetInfo::getPropertyByName( const OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
)
104 return getProperty( aName
);
107 // -----------------------------------------------------------------------------
109 sal_Bool SAL_CALL
FastPropertySetInfo::hasPropertyByName( const OUString
& aName
) throw (RuntimeException
)
111 return hasProperty( aName
) != 0 ? sal_True
: sal_False
;
114 // -----------------------------------------------------------------------------
116 // -----------------------------------------------------------------------------
118 FastPropertySet::FastPropertySet( const rtl::Reference
< FastPropertySetInfo
>& xInfo
)
123 // -----------------------------------------------------------------------------
125 FastPropertySet::~FastPropertySet()
129 // -----------------------------------------------------------------------------
131 // -----------------------------------------------------------------------------
133 Reference
< XPropertySetInfo
> SAL_CALL
FastPropertySet::getPropertySetInfo( ) throw (RuntimeException
)
135 return Reference
< XPropertySetInfo
>( mxInfo
.get() );
138 // -----------------------------------------------------------------------------
140 void SAL_CALL
FastPropertySet::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
142 setFastPropertyValue( mxInfo
->getProperty( aPropertyName
).Handle
, aValue
);
145 // -----------------------------------------------------------------------------
147 Any SAL_CALL
FastPropertySet::getPropertyValue( const OUString
& aPropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
149 return getFastPropertyValue( mxInfo
->getProperty( aPropertyName
).Handle
);
152 // -----------------------------------------------------------------------------
154 void SAL_CALL
FastPropertySet::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
158 // -----------------------------------------------------------------------------
160 void SAL_CALL
FastPropertySet::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
164 // -----------------------------------------------------------------------------
166 void SAL_CALL
FastPropertySet::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
170 // -----------------------------------------------------------------------------
172 void SAL_CALL
FastPropertySet::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
176 // -----------------------------------------------------------------------------
178 // -----------------------------------------------------------------------------
180 void SAL_CALL
FastPropertySet::setPropertyValues( const Sequence
< OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw (PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
182 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
183 const Any
* pValues
= aValues
.getConstArray();
184 sal_Int32 nCount
= aPropertyNames
.getLength();
185 if( nCount
!= aValues
.getLength() )
186 throw IllegalArgumentException();
190 const Property
* pProperty
= mxInfo
->hasProperty( *pPropertyNames
++ );
193 setFastPropertyValue( pProperty
->Handle
, *pValues
);
195 catch( UnknownPropertyException
& )
202 // -----------------------------------------------------------------------------
204 Sequence
< Any
> SAL_CALL
FastPropertySet::getPropertyValues( const Sequence
< OUString
>& aPropertyNames
) throw (RuntimeException
)
206 sal_Int32 nCount
= aPropertyNames
.getLength();
207 Sequence
< Any
> aValues( nCount
);
209 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
210 Any
* pValues
= aValues
.getArray();
213 const Property
* pProperty
= mxInfo
->hasProperty( *pPropertyNames
++ );
216 *pValues
= getFastPropertyValue( pProperty
->Handle
);
218 catch( UnknownPropertyException
& )
226 // -----------------------------------------------------------------------------
228 void SAL_CALL
FastPropertySet::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
232 // -----------------------------------------------------------------------------
234 void SAL_CALL
FastPropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
238 // -----------------------------------------------------------------------------
240 void SAL_CALL
FastPropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */