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 {
70 Any a = ::cppu::queryInterface(
71 rType ,
72 SAL_STATIC_CAST( XIndexContainer*, this ),
73 SAL_STATIC_CAST( XIndexReplace*, this ),
74 SAL_STATIC_CAST( XIndexAccess*, this ),
75 SAL_STATIC_CAST( XElementAccess*, this ) );
76
77 if( a.hasValue() )
78 {
79 return a;
80 }
81
82 return OWeakObject::queryInterface( rType );
83 }
84
85 // XIndexContainer
insertByIndex(sal_Int32 Index,const::com::sun::star::uno::Any & Element)86 void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
87 {
88 ResetableGuard aGuard( m_aLock );
89
90 sal_Int32 nSize = m_aPropertySetVector.size();
91
92 if ( nSize >= Index )
93 {
94 Reference< XPropertySet > aPropertySetElement;
95
96 if ( Element >>= aPropertySetElement )
97 {
98 if ( nSize == Index )
99 m_aPropertySetVector.push_back( aPropertySetElement );
100 else
101 {
102 PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
103 aIter += Index;
104 m_aPropertySetVector.insert( aIter, aPropertySetElement );
105 }
106 }
107 else
108 {
109 throw IllegalArgumentException(
110 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
111 (OWeakObject *)this, 2 );
112 }
113 }
114 else
115 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
116 }
117
removeByIndex(sal_Int32 Index)118 void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 Index )
119 {
120 ResetableGuard aGuard( m_aLock );
121
122 if ( (sal_Int32)m_aPropertySetVector.size() > Index )
123 {
124 PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
125 aIter += Index;
126 m_aPropertySetVector.erase( aIter );
127 }
128 else
129 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
130 }
131
132 // XIndexReplace
replaceByIndex(sal_Int32 Index,const::com::sun::star::uno::Any & Element)133 void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
134 {
135 if ( (sal_Int32)m_aPropertySetVector.size() > Index )
136 {
137 Reference< XPropertySet > aPropertySetElement;
138
139 if ( Element >>= aPropertySetElement )
140 {
141 m_aPropertySetVector[ Index ] = aPropertySetElement;
142 }
143 else
144 {
145 throw IllegalArgumentException(
146 OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
147 (OWeakObject *)this, 2 );
148 }
149 }
150 else
151 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
152 }
153
154 // XIndexAccess
getCount()155 sal_Int32 SAL_CALL PropertySetContainer::getCount()
156 {
157 ResetableGuard aGuard( m_aLock );
158
159 return m_aPropertySetVector.size();
160 }
161
getByIndex(sal_Int32 Index)162 Any SAL_CALL PropertySetContainer::getByIndex( sal_Int32 Index )
163 {
164 ResetableGuard aGuard( m_aLock );
165
166 if ( (sal_Int32)m_aPropertySetVector.size() > Index )
167 {
168 Any a;
169
170 a <<= m_aPropertySetVector[ Index ];
171 return a;
172 }
173 else
174 throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
175 }
176
177 // XElementAccess
hasElements()178 sal_Bool SAL_CALL PropertySetContainer::hasElements()
179 {
180 ResetableGuard aGuard( m_aLock );
181
182 return !( m_aPropertySetVector.empty() );
183 }
184
185 }
186