1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertyset.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "propertyset.hxx"
36 using ::rtl::OUString
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::lang
;
41 namespace comphelper
{
43 // -----------------------------------------------------------------------------
44 // FastPropertySetInfo
45 // -----------------------------------------------------------------------------
47 FastPropertySetInfo::FastPropertySetInfo()
51 // -----------------------------------------------------------------------------
53 FastPropertySetInfo::FastPropertySetInfo( const PropertyVector
& rProps
)
55 addProperties( rProps
);
58 // -----------------------------------------------------------------------------
60 FastPropertySetInfo::~FastPropertySetInfo()
64 // -----------------------------------------------------------------------------
66 void FastPropertySetInfo::addProperty( const Property
& rProperty
)
68 maProperties
.push_back( rProperty
);
69 maMap
[ rProperty
.Name
] = maProperties
.size() - 1;
72 // -----------------------------------------------------------------------------
74 void FastPropertySetInfo::addProperties( const PropertyVector
& rProps
)
76 sal_uInt32 nIndex
= maProperties
.size();
77 sal_uInt32 nCount
= rProps
.size();
78 maProperties
.resize( nIndex
+ nCount
);
79 PropertyVector::const_iterator
aIter( rProps
.begin() );
82 const Property
& rProperty
= (*aIter
++);
83 maProperties
[nIndex
] = rProperty
;
84 maMap
[ rProperty
.Name
] = nIndex
++;
88 // -----------------------------------------------------------------------------
90 const Property
& FastPropertySetInfo::getProperty( const OUString
& aName
) throw (UnknownPropertyException
)
92 PropertyMap::iterator
aIter( maMap
.find( aName
) );
93 if( aIter
== maMap
.end() )
94 throw UnknownPropertyException();
95 return maProperties
[(*aIter
).second
];
98 // -----------------------------------------------------------------------------
100 const Property
* FastPropertySetInfo::hasProperty( const OUString
& aName
)
102 PropertyMap::iterator
aIter( maMap
.find( aName
) );
103 if( aIter
== maMap
.end() )
106 return &maProperties
[(*aIter
).second
];
109 // -----------------------------------------------------------------------------
111 // -----------------------------------------------------------------------------
113 Sequence
< Property
> SAL_CALL
FastPropertySetInfo::getProperties() throw (RuntimeException
)
115 return Sequence
< Property
>( &maProperties
[0], maProperties
.size() );
118 // -----------------------------------------------------------------------------
120 Property SAL_CALL
FastPropertySetInfo::getPropertyByName( const OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
)
122 return getProperty( aName
);
125 // -----------------------------------------------------------------------------
127 sal_Bool SAL_CALL
FastPropertySetInfo::hasPropertyByName( const OUString
& aName
) throw (RuntimeException
)
129 return hasProperty( aName
) != 0 ? sal_True
: sal_False
;;
132 // -----------------------------------------------------------------------------
134 // -----------------------------------------------------------------------------
136 FastPropertySet::FastPropertySet( const rtl::Reference
< FastPropertySetInfo
>& xInfo
)
141 // -----------------------------------------------------------------------------
143 FastPropertySet::~FastPropertySet()
147 // -----------------------------------------------------------------------------
149 // -----------------------------------------------------------------------------
151 Reference
< XPropertySetInfo
> SAL_CALL
FastPropertySet::getPropertySetInfo( ) throw (RuntimeException
)
153 return Reference
< XPropertySetInfo
>( mxInfo
.get() );
156 // -----------------------------------------------------------------------------
158 void SAL_CALL
FastPropertySet::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
160 setFastPropertyValue( mxInfo
->getProperty( aPropertyName
).Handle
, aValue
);
163 // -----------------------------------------------------------------------------
165 Any SAL_CALL
FastPropertySet::getPropertyValue( const OUString
& aPropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
167 return getFastPropertyValue( mxInfo
->getProperty( aPropertyName
).Handle
);
170 // -----------------------------------------------------------------------------
172 void SAL_CALL
FastPropertySet::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
176 // -----------------------------------------------------------------------------
178 void SAL_CALL
FastPropertySet::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
182 // -----------------------------------------------------------------------------
184 void SAL_CALL
FastPropertySet::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
188 // -----------------------------------------------------------------------------
190 void SAL_CALL
FastPropertySet::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
194 // -----------------------------------------------------------------------------
196 // -----------------------------------------------------------------------------
198 void SAL_CALL
FastPropertySet::setPropertyValues( const Sequence
< OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw (PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
200 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
201 const Any
* pValues
= aValues
.getConstArray();
202 sal_Int32 nCount
= aPropertyNames
.getLength();
203 if( nCount
!= aValues
.getLength() )
204 throw IllegalArgumentException();
208 const Property
* pProperty
= mxInfo
->hasProperty( *pPropertyNames
++ );
211 setFastPropertyValue( pProperty
->Handle
, *pValues
);
213 catch( UnknownPropertyException
& )
220 // -----------------------------------------------------------------------------
222 Sequence
< Any
> SAL_CALL
FastPropertySet::getPropertyValues( const Sequence
< OUString
>& aPropertyNames
) throw (RuntimeException
)
224 sal_Int32 nCount
= aPropertyNames
.getLength();
225 Sequence
< Any
> aValues( nCount
);
227 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
228 Any
* pValues
= aValues
.getArray();
231 const Property
* pProperty
= mxInfo
->hasProperty( *pPropertyNames
++ );
234 *pValues
= getFastPropertyValue( pProperty
->Handle
);
236 catch( UnknownPropertyException
& )
244 // -----------------------------------------------------------------------------
246 void SAL_CALL
FastPropertySet::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
250 // -----------------------------------------------------------------------------
252 void SAL_CALL
FastPropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
256 // -----------------------------------------------------------------------------
258 void SAL_CALL
FastPropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)