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