1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <helper/propertysetcontainer.hxx>
22 #include <cppuhelper/queryinterface.hxx>
23 #include <vcl/svapp.hxx>
25 #define WRONG_TYPE_EXCEPTION "Only XPropertSet allowed!"
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
;
36 PropertySetContainer::PropertySetContainer()
42 PropertySetContainer::~PropertySetContainer()
47 void SAL_CALL
PropertySetContainer::acquire() throw ()
49 OWeakObject::acquire();
52 void SAL_CALL
PropertySetContainer::release() throw ()
54 OWeakObject::release();
57 Any SAL_CALL
PropertySetContainer::queryInterface( const Type
& rType
)
58 throw ( RuntimeException
, std::exception
)
60 Any a
= ::cppu::queryInterface(
62 (static_cast< XIndexContainer
* >(this)),
63 (static_cast< XIndexReplace
* >(this)),
64 (static_cast< XIndexAccess
* >(this)),
65 (static_cast< XElementAccess
* >(this)) );
72 return OWeakObject::queryInterface( rType
);
76 void SAL_CALL
PropertySetContainer::insertByIndex( sal_Int32 Index
, const ::com::sun::star::uno::Any
& Element
)
77 throw ( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
81 sal_Int32 nSize
= m_aPropertySetVector
.size();
85 Reference
< XPropertySet
> aPropertySetElement
;
87 if ( Element
>>= aPropertySetElement
)
90 m_aPropertySetVector
.push_back( aPropertySetElement
);
93 PropertySetVector::iterator aIter
= m_aPropertySetVector
.begin();
95 m_aPropertySetVector
.insert( aIter
, aPropertySetElement
);
100 throw IllegalArgumentException(
101 WRONG_TYPE_EXCEPTION
,
102 (OWeakObject
*)this, 2 );
106 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
109 void SAL_CALL
PropertySetContainer::removeByIndex( sal_Int32 nIndex
)
110 throw ( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
114 if ( (sal_Int32
)m_aPropertySetVector
.size() > nIndex
)
116 m_aPropertySetVector
.erase(m_aPropertySetVector
.begin() + nIndex
);
119 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
123 void SAL_CALL
PropertySetContainer::replaceByIndex( sal_Int32 Index
, const ::com::sun::star::uno::Any
& Element
)
124 throw ( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
126 if ( (sal_Int32
)m_aPropertySetVector
.size() > Index
)
128 Reference
< XPropertySet
> aPropertySetElement
;
130 if ( Element
>>= aPropertySetElement
)
132 m_aPropertySetVector
[ Index
] = aPropertySetElement
;
136 throw IllegalArgumentException(
137 WRONG_TYPE_EXCEPTION
,
138 (OWeakObject
*)this, 2 );
142 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
146 sal_Int32 SAL_CALL
PropertySetContainer::getCount()
147 throw ( RuntimeException
, std::exception
)
151 return m_aPropertySetVector
.size();
154 Any SAL_CALL
PropertySetContainer::getByIndex( sal_Int32 Index
)
155 throw ( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
159 if ( (sal_Int32
)m_aPropertySetVector
.size() > Index
)
163 a
<<= m_aPropertySetVector
[ Index
];
167 throw IndexOutOfBoundsException( OUString(), (OWeakObject
*)this );
171 sal_Bool SAL_CALL
PropertySetContainer::hasElements()
172 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
176 return !( m_aPropertySetVector
.empty() );
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */