1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <helper/propertysetcontainer.hxx>
27cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #define WRONG_TYPE_EXCEPTION	"Only XPropertSet allowed!"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace rtl;
34cdf0e10cSrcweir using namespace vos;
35cdf0e10cSrcweir using namespace cppu;
36cdf0e10cSrcweir using namespace com::sun::star::uno;
37cdf0e10cSrcweir using namespace com::sun::star::container;
38cdf0e10cSrcweir using namespace com::sun::star::lang;
39cdf0e10cSrcweir using namespace com::sun::star::beans;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace framework
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 
PropertySetContainer(const Reference<XMultiServiceFactory> &)44cdf0e10cSrcweir PropertySetContainer::PropertySetContainer( const Reference< XMultiServiceFactory >& )
45cdf0e10cSrcweir 		:   ThreadHelpBase( &Application::GetSolarMutex() )
46cdf0e10cSrcweir 		,	OWeakObject()
47cdf0e10cSrcweir 
48cdf0e10cSrcweir {
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
~PropertySetContainer()52cdf0e10cSrcweir PropertySetContainer::~PropertySetContainer()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // XInterface
acquire()58cdf0e10cSrcweir void SAL_CALL PropertySetContainer::acquire() throw ()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	OWeakObject::acquire();
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
release()63cdf0e10cSrcweir void SAL_CALL PropertySetContainer::release() throw ()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	OWeakObject::release();
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
queryInterface(const Type & rType)68cdf0e10cSrcweir Any SAL_CALL PropertySetContainer::queryInterface( const Type& rType )
69cdf0e10cSrcweir throw ( RuntimeException )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	Any a = ::cppu::queryInterface(
72cdf0e10cSrcweir 				rType ,
73cdf0e10cSrcweir 				SAL_STATIC_CAST( XIndexContainer*, this ),
74cdf0e10cSrcweir 				SAL_STATIC_CAST( XIndexReplace*, this ),
75cdf0e10cSrcweir 				SAL_STATIC_CAST( XIndexAccess*, this ),
76cdf0e10cSrcweir 				SAL_STATIC_CAST( XElementAccess*, this ) );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	if( a.hasValue() )
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		return a;
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	return OWeakObject::queryInterface( rType );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir // XIndexContainer
insertByIndex(sal_Int32 Index,const::com::sun::star::uno::Any & Element)87cdf0e10cSrcweir void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
88cdf0e10cSrcweir 	throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	sal_Int32 nSize = m_aPropertySetVector.size();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	if ( nSize >= Index )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		Reference< XPropertySet > aPropertySetElement;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		if ( Element >>= aPropertySetElement )
99cdf0e10cSrcweir 		{
100cdf0e10cSrcweir 			if ( nSize == Index )
101cdf0e10cSrcweir 				m_aPropertySetVector.push_back( aPropertySetElement );
102cdf0e10cSrcweir 			else
103cdf0e10cSrcweir 			{
104cdf0e10cSrcweir 				PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
105cdf0e10cSrcweir 				aIter += Index;
106cdf0e10cSrcweir 				m_aPropertySetVector.insert( aIter, aPropertySetElement );
107cdf0e10cSrcweir 			}
108cdf0e10cSrcweir 		}
109cdf0e10cSrcweir 		else
110cdf0e10cSrcweir 		{
111cdf0e10cSrcweir 			throw IllegalArgumentException(
112cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
113cdf0e10cSrcweir 				(OWeakObject *)this, 2 );
114cdf0e10cSrcweir 		}
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 	else
117cdf0e10cSrcweir 		throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
removeByIndex(sal_Int32 Index)120cdf0e10cSrcweir void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 Index )
121cdf0e10cSrcweir 	throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	if ( (sal_Int32)m_aPropertySetVector.size() > Index )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
128cdf0e10cSrcweir 		aIter += Index;
129cdf0e10cSrcweir 		m_aPropertySetVector.erase( aIter );
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 	else
132cdf0e10cSrcweir 		throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir // XIndexReplace
replaceByIndex(sal_Int32 Index,const::com::sun::star::uno::Any & Element)136cdf0e10cSrcweir void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
137cdf0e10cSrcweir 	throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	if ( (sal_Int32)m_aPropertySetVector.size() > Index )
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		Reference< XPropertySet > aPropertySetElement;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		if ( Element >>= aPropertySetElement )
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			m_aPropertySetVector[ Index ] = aPropertySetElement;
146cdf0e10cSrcweir 		}
147cdf0e10cSrcweir 		else
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			throw IllegalArgumentException(
150cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
151cdf0e10cSrcweir 				(OWeakObject *)this, 2 );
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 	else
155cdf0e10cSrcweir 		throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // XIndexAccess
getCount()159cdf0e10cSrcweir sal_Int32 SAL_CALL PropertySetContainer::getCount()
160cdf0e10cSrcweir 	throw ( RuntimeException )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	return m_aPropertySetVector.size();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
getByIndex(sal_Int32 Index)167cdf0e10cSrcweir Any SAL_CALL PropertySetContainer::getByIndex( sal_Int32 Index )
168cdf0e10cSrcweir 	throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	if ( (sal_Int32)m_aPropertySetVector.size() > Index )
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		Any a;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		a <<= m_aPropertySetVector[ Index ];
177cdf0e10cSrcweir 		return a;
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 	else
180cdf0e10cSrcweir 		throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir // XElementAccess
hasElements()184cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetContainer::hasElements()
185cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	return !( m_aPropertySetVector.empty() );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir }
193