update dev300-m58
[ooovba.git] / framework / source / helper / propertysetcontainer.cxx
blob0d3bb857e9db72870c81f1bb2a59cf0dc6faa49a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertysetcontainer.cxx,v $
10 * $Revision: 1.5 $
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!"
40 using namespace rtl;
41 using namespace vos;
42 using namespace cppu;
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;
48 namespace framework
51 PropertySetContainer::PropertySetContainer( const Reference< XMultiServiceFactory >& )
52 : ThreadHelpBase( &Application::GetSolarMutex() )
53 , OWeakObject()
59 PropertySetContainer::~PropertySetContainer()
64 // XInterface
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(
79 rType ,
80 SAL_STATIC_CAST( XIndexContainer*, this ),
81 SAL_STATIC_CAST( XIndexReplace*, this ),
82 SAL_STATIC_CAST( XIndexAccess*, this ),
83 SAL_STATIC_CAST( XElementAccess*, this ) );
85 if( a.hasValue() )
87 return a;
90 return OWeakObject::queryInterface( rType );
93 // XIndexContainer
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 );
109 else
111 PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
112 aIter += Index;
113 m_aPropertySetVector.insert( aIter, aPropertySetElement );
116 else
118 throw IllegalArgumentException(
119 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
120 (OWeakObject *)this, 2 );
123 else
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();
135 aIter += Index;
136 m_aPropertySetVector.erase( aIter );
138 else
139 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
142 // XIndexReplace
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;
154 else
156 throw IllegalArgumentException(
157 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
158 (OWeakObject *)this, 2 );
161 else
162 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
165 // XIndexAccess
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 )
181 Any a;
183 a <<= m_aPropertySetVector[ Index ];
184 return a;
186 else
187 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
190 // XElementAccess
191 sal_Bool SAL_CALL PropertySetContainer::hasElements()
192 throw (::com::sun::star::uno::RuntimeException)
194 ResetableGuard aGuard( m_aLock );
196 return !( m_aPropertySetVector.empty() );