Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <helper/propertysetcontainer.hxx>
21 : #include <threadhelp/resetableguard.hxx>
22 :
23 : #include <vcl/svapp.hxx>
24 :
25 : #define WRONG_TYPE_EXCEPTION "Only XPropertSet allowed!"
26 :
27 : using namespace cppu;
28 : using namespace com::sun::star::uno;
29 : using namespace com::sun::star::container;
30 : using namespace com::sun::star::lang;
31 : using namespace com::sun::star::beans;
32 :
33 : namespace framework
34 : {
35 :
36 0 : PropertySetContainer::PropertySetContainer()
37 0 : : ThreadHelpBase( &Application::GetSolarMutex() )
38 0 : , OWeakObject()
39 :
40 : {
41 0 : }
42 :
43 :
44 0 : PropertySetContainer::~PropertySetContainer()
45 : {
46 0 : }
47 :
48 :
49 : // XInterface
50 0 : void SAL_CALL PropertySetContainer::acquire() throw ()
51 : {
52 0 : OWeakObject::acquire();
53 0 : }
54 :
55 0 : void SAL_CALL PropertySetContainer::release() throw ()
56 : {
57 0 : OWeakObject::release();
58 0 : }
59 :
60 0 : Any SAL_CALL PropertySetContainer::queryInterface( const Type& rType )
61 : throw ( RuntimeException )
62 : {
63 : Any a = ::cppu::queryInterface(
64 : rType ,
65 : (static_cast< XIndexContainer* >(this)),
66 : (static_cast< XIndexReplace* >(this)),
67 : (static_cast< XIndexAccess* >(this)),
68 0 : (static_cast< XElementAccess* >(this)) );
69 :
70 0 : if( a.hasValue() )
71 : {
72 0 : return a;
73 : }
74 :
75 0 : return OWeakObject::queryInterface( rType );
76 : }
77 :
78 : // XIndexContainer
79 0 : void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
80 : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
81 : {
82 0 : ResetableGuard aGuard( m_aLock );
83 :
84 0 : sal_Int32 nSize = m_aPropertySetVector.size();
85 :
86 0 : if ( nSize >= Index )
87 : {
88 0 : Reference< XPropertySet > aPropertySetElement;
89 :
90 0 : if ( Element >>= aPropertySetElement )
91 : {
92 0 : if ( nSize == Index )
93 0 : m_aPropertySetVector.push_back( aPropertySetElement );
94 : else
95 : {
96 0 : PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
97 0 : aIter += Index;
98 0 : m_aPropertySetVector.insert( aIter, aPropertySetElement );
99 : }
100 : }
101 : else
102 : {
103 : throw IllegalArgumentException(
104 : OUString( WRONG_TYPE_EXCEPTION ),
105 0 : (OWeakObject *)this, 2 );
106 0 : }
107 : }
108 : else
109 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
110 0 : }
111 :
112 0 : void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 Index )
113 : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
114 : {
115 0 : ResetableGuard aGuard( m_aLock );
116 :
117 0 : if ( (sal_Int32)m_aPropertySetVector.size() > Index )
118 : {
119 0 : PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
120 0 : aIter += Index;
121 0 : m_aPropertySetVector.erase( aIter );
122 : }
123 : else
124 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
125 0 : }
126 :
127 : // XIndexReplace
128 0 : void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
129 : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
130 : {
131 0 : if ( (sal_Int32)m_aPropertySetVector.size() > Index )
132 : {
133 0 : Reference< XPropertySet > aPropertySetElement;
134 :
135 0 : if ( Element >>= aPropertySetElement )
136 : {
137 0 : m_aPropertySetVector[ Index ] = aPropertySetElement;
138 : }
139 : else
140 : {
141 : throw IllegalArgumentException(
142 : OUString( WRONG_TYPE_EXCEPTION ),
143 0 : (OWeakObject *)this, 2 );
144 0 : }
145 : }
146 : else
147 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
148 0 : }
149 :
150 : // XIndexAccess
151 0 : sal_Int32 SAL_CALL PropertySetContainer::getCount()
152 : throw ( RuntimeException )
153 : {
154 0 : ResetableGuard aGuard( m_aLock );
155 :
156 0 : return m_aPropertySetVector.size();
157 : }
158 :
159 0 : Any SAL_CALL PropertySetContainer::getByIndex( sal_Int32 Index )
160 : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
161 : {
162 0 : ResetableGuard aGuard( m_aLock );
163 :
164 0 : if ( (sal_Int32)m_aPropertySetVector.size() > Index )
165 : {
166 0 : Any a;
167 :
168 0 : a <<= m_aPropertySetVector[ Index ];
169 0 : return a;
170 : }
171 : else
172 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
173 : }
174 :
175 : // XElementAccess
176 0 : sal_Bool SAL_CALL PropertySetContainer::hasElements()
177 : throw (::com::sun::star::uno::RuntimeException)
178 : {
179 0 : ResetableGuard aGuard( m_aLock );
180 :
181 0 : return !( m_aPropertySetVector.empty() );
182 : }
183 :
184 411 : }
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|