xref: /trunk/main/framework/source/fwe/helper/propertysetcontainer.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 #include <helper/propertysetcontainer.hxx>
31 #include <threadhelp/resetableguard.hxx>
32 
33 #include <vcl/svapp.hxx>
34 
35 #define WRONG_TYPE_EXCEPTION    "Only XPropertSet allowed!"
36 
37 using namespace rtl;
38 using namespace vos;
39 using namespace cppu;
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::container;
42 using namespace com::sun::star::lang;
43 using namespace com::sun::star::beans;
44 
45 namespace framework
46 {
47 
48 PropertySetContainer::PropertySetContainer( const Reference< XMultiServiceFactory >& )
49         :   ThreadHelpBase( &Application::GetSolarMutex() )
50         ,   OWeakObject()
51 
52 {
53 }
54 
55 
56 PropertySetContainer::~PropertySetContainer()
57 {
58 }
59 
60 
61 // XInterface
62 void SAL_CALL PropertySetContainer::acquire() throw ()
63 {
64     OWeakObject::acquire();
65 }
66 
67 void SAL_CALL PropertySetContainer::release() throw ()
68 {
69     OWeakObject::release();
70 }
71 
72 Any SAL_CALL PropertySetContainer::queryInterface( const Type& rType )
73 throw ( RuntimeException )
74 {
75     Any a = ::cppu::queryInterface(
76                 rType ,
77                 SAL_STATIC_CAST( XIndexContainer*, this ),
78                 SAL_STATIC_CAST( XIndexReplace*, this ),
79                 SAL_STATIC_CAST( XIndexAccess*, this ),
80                 SAL_STATIC_CAST( XElementAccess*, this ) );
81 
82     if( a.hasValue() )
83     {
84         return a;
85     }
86 
87     return OWeakObject::queryInterface( rType );
88 }
89 
90 // XIndexContainer
91 void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
92     throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
93 {
94     ResetableGuard aGuard( m_aLock );
95 
96     sal_Int32 nSize = m_aPropertySetVector.size();
97 
98     if ( nSize >= Index )
99     {
100         Reference< XPropertySet > aPropertySetElement;
101 
102         if ( Element >>= aPropertySetElement )
103         {
104             if ( nSize == Index )
105                 m_aPropertySetVector.push_back( aPropertySetElement );
106             else
107             {
108                 PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
109                 aIter += Index;
110                 m_aPropertySetVector.insert( aIter, aPropertySetElement );
111             }
112         }
113         else
114         {
115             throw IllegalArgumentException(
116                 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
117                 (OWeakObject *)this, 2 );
118         }
119     }
120     else
121         throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
122 }
123 
124 void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 Index )
125     throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
126 {
127     ResetableGuard aGuard( m_aLock );
128 
129     if ( (sal_Int32)m_aPropertySetVector.size() > Index )
130     {
131         PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
132         aIter += Index;
133         m_aPropertySetVector.erase( aIter );
134     }
135     else
136         throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
137 }
138 
139 // XIndexReplace
140 void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
141     throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
142 {
143     if ( (sal_Int32)m_aPropertySetVector.size() > Index )
144     {
145         Reference< XPropertySet > aPropertySetElement;
146 
147         if ( Element >>= aPropertySetElement )
148         {
149             m_aPropertySetVector[ Index ] = aPropertySetElement;
150         }
151         else
152         {
153             throw IllegalArgumentException(
154                 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
155                 (OWeakObject *)this, 2 );
156         }
157     }
158     else
159         throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
160 }
161 
162 // XIndexAccess
163 sal_Int32 SAL_CALL PropertySetContainer::getCount()
164     throw ( RuntimeException )
165 {
166     ResetableGuard aGuard( m_aLock );
167 
168     return m_aPropertySetVector.size();
169 }
170 
171 Any SAL_CALL PropertySetContainer::getByIndex( sal_Int32 Index )
172     throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
173 {
174     ResetableGuard aGuard( m_aLock );
175 
176     if ( (sal_Int32)m_aPropertySetVector.size() > Index )
177     {
178         Any a;
179 
180         a <<= m_aPropertySetVector[ Index ];
181         return a;
182     }
183     else
184         throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
185 }
186 
187 // XElementAccess
188 sal_Bool SAL_CALL PropertySetContainer::hasElements()
189     throw (::com::sun::star::uno::RuntimeException)
190 {
191     ResetableGuard aGuard( m_aLock );
192 
193     return !( m_aPropertySetVector.empty() );
194 }
195 
196 }
197