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 :
22 : #include <vcl/svapp.hxx>
23 :
24 : #define WRONG_TYPE_EXCEPTION "Only XPropertSet allowed!"
25 :
26 : using namespace cppu;
27 : using namespace com::sun::star::uno;
28 : using namespace com::sun::star::container;
29 : using namespace com::sun::star::lang;
30 : using namespace com::sun::star::beans;
31 :
32 : namespace framework
33 : {
34 :
35 0 : PropertySetContainer::PropertySetContainer()
36 0 : : OWeakObject()
37 :
38 : {
39 0 : }
40 :
41 0 : PropertySetContainer::~PropertySetContainer()
42 : {
43 0 : }
44 :
45 : // XInterface
46 0 : void SAL_CALL PropertySetContainer::acquire() throw ()
47 : {
48 0 : OWeakObject::acquire();
49 0 : }
50 :
51 0 : void SAL_CALL PropertySetContainer::release() throw ()
52 : {
53 0 : OWeakObject::release();
54 0 : }
55 :
56 0 : Any SAL_CALL PropertySetContainer::queryInterface( const Type& rType )
57 : throw ( RuntimeException, std::exception )
58 : {
59 : Any a = ::cppu::queryInterface(
60 : rType ,
61 : (static_cast< XIndexContainer* >(this)),
62 : (static_cast< XIndexReplace* >(this)),
63 : (static_cast< XIndexAccess* >(this)),
64 0 : (static_cast< XElementAccess* >(this)) );
65 :
66 0 : if( a.hasValue() )
67 : {
68 0 : return a;
69 : }
70 :
71 0 : return OWeakObject::queryInterface( rType );
72 : }
73 :
74 : // XIndexContainer
75 0 : void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
76 : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
77 : {
78 0 : SolarMutexGuard g;
79 :
80 0 : sal_Int32 nSize = m_aPropertySetVector.size();
81 :
82 0 : if ( nSize >= Index )
83 : {
84 0 : Reference< XPropertySet > aPropertySetElement;
85 :
86 0 : if ( Element >>= aPropertySetElement )
87 : {
88 0 : if ( nSize == Index )
89 0 : m_aPropertySetVector.push_back( aPropertySetElement );
90 : else
91 : {
92 0 : PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
93 0 : aIter += Index;
94 0 : m_aPropertySetVector.insert( aIter, aPropertySetElement );
95 : }
96 : }
97 : else
98 : {
99 : throw IllegalArgumentException(
100 : OUString( WRONG_TYPE_EXCEPTION ),
101 0 : (OWeakObject *)this, 2 );
102 0 : }
103 : }
104 : else
105 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
106 0 : }
107 :
108 0 : void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 nIndex )
109 : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
110 : {
111 0 : SolarMutexGuard g;
112 :
113 0 : if ( (sal_Int32)m_aPropertySetVector.size() > nIndex )
114 : {
115 0 : m_aPropertySetVector.erase(m_aPropertySetVector.begin() + nIndex);
116 : }
117 : else
118 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
119 0 : }
120 :
121 : // XIndexReplace
122 0 : void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const ::com::sun::star::uno::Any& Element )
123 : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
124 : {
125 0 : if ( (sal_Int32)m_aPropertySetVector.size() > Index )
126 : {
127 0 : Reference< XPropertySet > aPropertySetElement;
128 :
129 0 : if ( Element >>= aPropertySetElement )
130 : {
131 0 : m_aPropertySetVector[ Index ] = aPropertySetElement;
132 : }
133 : else
134 : {
135 : throw IllegalArgumentException(
136 : OUString( WRONG_TYPE_EXCEPTION ),
137 0 : (OWeakObject *)this, 2 );
138 0 : }
139 : }
140 : else
141 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
142 0 : }
143 :
144 : // XIndexAccess
145 0 : sal_Int32 SAL_CALL PropertySetContainer::getCount()
146 : throw ( RuntimeException, std::exception )
147 : {
148 0 : SolarMutexGuard g;
149 :
150 0 : return m_aPropertySetVector.size();
151 : }
152 :
153 0 : Any SAL_CALL PropertySetContainer::getByIndex( sal_Int32 Index )
154 : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
155 : {
156 0 : SolarMutexGuard g;
157 :
158 0 : if ( (sal_Int32)m_aPropertySetVector.size() > Index )
159 : {
160 0 : Any a;
161 :
162 0 : a <<= m_aPropertySetVector[ Index ];
163 0 : return a;
164 : }
165 : else
166 0 : throw IndexOutOfBoundsException( OUString(), (OWeakObject *)this );
167 : }
168 :
169 : // XElementAccess
170 0 : sal_Bool SAL_CALL PropertySetContainer::hasElements()
171 : throw (::com::sun::star::uno::RuntimeException, std::exception)
172 : {
173 0 : SolarMutexGuard g;
174 :
175 0 : return !( m_aPropertySetVector.empty() );
176 : }
177 :
178 : }
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|