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: propertysetcontainer.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_framework.hxx"
33 #include <helper/propertysetcontainer.hxx>
34 #include <threadhelp/resetableguard.hxx>
36 #include <vcl/svapp.hxx>
38 #define WRONG_TYPE_EXCEPTION "Only XPropertSet allowed!"
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::container
;
45 using namespace com::sun::star::lang
;
46 using namespace com::sun::star::beans
;
51 PropertySetContainer::PropertySetContainer( const Reference
< XMultiServiceFactory
>& )
52 : ThreadHelpBase( &Application::GetSolarMutex() )
59 PropertySetContainer::~PropertySetContainer()
65 void SAL_CALL
PropertySetContainer::acquire() throw ()
67 OWeakObject::acquire();
70 void SAL_CALL
PropertySetContainer::release() throw ()
72 OWeakObject::release();
75 Any SAL_CALL
PropertySetContainer::queryInterface( const Type
& rType
)
76 throw ( RuntimeException
)
78 Any a
= ::cppu::queryInterface(
80 SAL_STATIC_CAST( XIndexContainer
*, this ),
81 SAL_STATIC_CAST( XIndexReplace
*, this ),
82 SAL_STATIC_CAST( XIndexAccess
*, this ),
83 SAL_STATIC_CAST( XElementAccess
*, this ) );
90 return OWeakObject::queryInterface( rType
);
94 void SAL_CALL
PropertySetContainer::insertByIndex( sal_Int32 Index
, const ::com::sun::star::uno::Any
& Element
)
95 throw ( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
97 ResetableGuard
aGuard( m_aLock
);
99 sal_Int32 nSize
= m_aPropertySetVector
.size();
101 if ( nSize
>= Index
)
103 Reference
< XPropertySet
> aPropertySetElement
;
105 if ( Element
>>= aPropertySetElement
)
107 if ( nSize
== Index
)
108 m_aPropertySetVector
.push_back( aPropertySetElement
);
111 PropertySetVector::iterator aIter
= m_aPropertySetVector
.begin();
113 m_aPropertySetVector
.insert( aIter
, aPropertySetElement
);
118 throw IllegalArgumentException(
119 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION
)),
120 (OWeakObject
*)this, 2 );
124 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
127 void SAL_CALL
PropertySetContainer::removeByIndex( sal_Int32 Index
)
128 throw ( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
130 ResetableGuard
aGuard( m_aLock
);
132 if ( (sal_Int32
)m_aPropertySetVector
.size() > Index
)
134 PropertySetVector::iterator aIter
= m_aPropertySetVector
.begin();
136 m_aPropertySetVector
.erase( aIter
);
139 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
143 void SAL_CALL
PropertySetContainer::replaceByIndex( sal_Int32 Index
, const ::com::sun::star::uno::Any
& Element
)
144 throw ( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
146 if ( (sal_Int32
)m_aPropertySetVector
.size() > Index
)
148 Reference
< XPropertySet
> aPropertySetElement
;
150 if ( Element
>>= aPropertySetElement
)
152 m_aPropertySetVector
[ Index
] = aPropertySetElement
;
156 throw IllegalArgumentException(
157 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION
)),
158 (OWeakObject
*)this, 2 );
162 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
166 sal_Int32 SAL_CALL
PropertySetContainer::getCount()
167 throw ( RuntimeException
)
169 ResetableGuard
aGuard( m_aLock
);
171 return m_aPropertySetVector
.size();
174 Any SAL_CALL
PropertySetContainer::getByIndex( sal_Int32 Index
)
175 throw ( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
177 ResetableGuard
aGuard( m_aLock
);
179 if ( (sal_Int32
)m_aPropertySetVector
.size() > Index
)
183 a
<<= m_aPropertySetVector
[ Index
];
187 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
191 sal_Bool SAL_CALL
PropertySetContainer::hasElements()
192 throw (::com::sun::star::uno::RuntimeException
)
194 ResetableGuard
aGuard( m_aLock
);
196 return !( m_aPropertySetVector
.empty() );