1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: IndexedPropertyValuesContainer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
34 #include "comphelper_module.hxx"
36 #include <com/sun/star/container/XIndexContainer.hpp>
37 #include <com/sun/star/uno/Sequence.h>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <cppuhelper/implbase2.hxx>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
44 #ifndef __SGI_STL_VECTOR
48 using namespace com::sun::star
;
50 typedef std::vector
< uno::Sequence
< beans::PropertyValue
> > IndexedPropertyValues
;
52 class IndexedPropertyValuesContainer
: public cppu::WeakImplHelper2
< container::XIndexContainer
, lang::XServiceInfo
>
55 IndexedPropertyValuesContainer() throw();
56 virtual ~IndexedPropertyValuesContainer() throw();
59 virtual void SAL_CALL
insertByIndex( sal_Int32 nIndex
, const ::com::sun::star::uno::Any
& aElement
)
60 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::IndexOutOfBoundsException
,
61 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
62 virtual void SAL_CALL
removeByIndex( sal_Int32 nIndex
)
63 throw(::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::WrappedTargetException
,
64 ::com::sun::star::uno::RuntimeException
);
67 virtual void SAL_CALL
replaceByIndex( sal_Int32 nIndex
, const ::com::sun::star::uno::Any
& aElement
)
68 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::IndexOutOfBoundsException
,
69 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
72 virtual sal_Int32 SAL_CALL
getCount( )
73 throw(::com::sun::star::uno::RuntimeException
);
74 virtual ::com::sun::star::uno::Any SAL_CALL
getByIndex( sal_Int32 nIndex
)
75 throw(::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::WrappedTargetException
,
76 ::com::sun::star::uno::RuntimeException
);
79 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( )
80 throw(::com::sun::star::uno::RuntimeException
);
81 virtual sal_Bool SAL_CALL
hasElements( )
82 throw(::com::sun::star::uno::RuntimeException
);
85 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
86 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
87 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
89 // XServiceInfo - static versions (used for component registration)
90 static ::rtl::OUString SAL_CALL
getImplementationName_static();
91 static uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames_static();
92 static uno::Reference
< uno::XInterface
> SAL_CALL
Create( const uno::Reference
< uno::XComponentContext
>& );
95 IndexedPropertyValues maProperties
;
98 IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
102 IndexedPropertyValuesContainer::~IndexedPropertyValuesContainer() throw()
107 void SAL_CALL
IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex
, const ::com::sun::star::uno::Any
& aElement
)
108 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::IndexOutOfBoundsException
,
109 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
111 sal_Int32
nSize(maProperties
.size());
112 if ((nSize
>= nIndex
) && (nIndex
>= 0))
114 uno::Sequence
<beans::PropertyValue
> aProps
;
115 if (!(aElement
>>= aProps
))
116 throw lang::IllegalArgumentException();
118 maProperties
.push_back(aProps
);
121 IndexedPropertyValues::iterator aItr
;
122 if ((nIndex
* 2) < nSize
)
124 aItr
= maProperties
.begin();
134 aItr
= maProperties
.end();
135 sal_Int32
i(nSize
- 1);
142 maProperties
.insert(aItr
, aProps
);
146 throw lang::IndexOutOfBoundsException();
149 void SAL_CALL
IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex
)
150 throw(::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::WrappedTargetException
,
151 ::com::sun::star::uno::RuntimeException
)
153 sal_Int32
nSize(maProperties
.size());
154 if ((nIndex
< nSize
) && (nIndex
>= 0))
156 IndexedPropertyValues::iterator aItr
;
157 if ((nIndex
* 2) < nSize
)
159 aItr
= maProperties
.begin();
169 aItr
= maProperties
.end();
170 sal_Int32
i(nSize
- 1);
177 maProperties
.erase(aItr
);
180 throw lang::IndexOutOfBoundsException();
184 void SAL_CALL
IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex
, const ::com::sun::star::uno::Any
& aElement
)
185 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::IndexOutOfBoundsException
,
186 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
188 sal_Int32
nSize(maProperties
.size());
189 if ((nIndex
< nSize
) && (nIndex
>= 0))
191 uno::Sequence
<beans::PropertyValue
> aProps
;
192 if (!(aElement
>>= aProps
))
193 throw lang::IllegalArgumentException();
194 maProperties
[nIndex
] = aProps
;
197 throw lang::IndexOutOfBoundsException();
201 sal_Int32 SAL_CALL
IndexedPropertyValuesContainer::getCount( )
202 throw(::com::sun::star::uno::RuntimeException
)
204 return maProperties
.size();
207 ::com::sun::star::uno::Any SAL_CALL
IndexedPropertyValuesContainer::getByIndex( sal_Int32 nIndex
)
208 throw(::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::WrappedTargetException
,
209 ::com::sun::star::uno::RuntimeException
)
211 sal_Int32
nSize(maProperties
.size());
212 if (!((nIndex
< nSize
) && (nIndex
>= 0)))
213 throw lang::IndexOutOfBoundsException();
216 aAny
<<= maProperties
[nIndex
];
221 ::com::sun::star::uno::Type SAL_CALL
IndexedPropertyValuesContainer::getElementType( )
222 throw(::com::sun::star::uno::RuntimeException
)
224 return ::getCppuType((uno::Sequence
<beans::PropertyValue
> *)0);
227 sal_Bool SAL_CALL
IndexedPropertyValuesContainer::hasElements( )
228 throw(::com::sun::star::uno::RuntimeException
)
230 return !maProperties
.empty();
234 ::rtl::OUString SAL_CALL
IndexedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
)
236 return getImplementationName_static();
239 ::rtl::OUString SAL_CALL
IndexedPropertyValuesContainer::getImplementationName_static( )
241 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndexedPropertyValuesContainer" ) );
244 sal_Bool SAL_CALL
IndexedPropertyValuesContainer::supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
)
246 rtl::OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
247 return aServiceName
== ServiceName
;
250 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
IndexedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
252 return getSupportedServiceNames_static();
256 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
IndexedPropertyValuesContainer::getSupportedServiceNames_static( )
258 const rtl::OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) );
259 const uno::Sequence
< rtl::OUString
> aSeq( &aServiceName
, 1 );
264 uno::Reference
< uno::XInterface
> SAL_CALL
IndexedPropertyValuesContainer::Create(
265 const uno::Reference
< uno::XComponentContext
>&)
267 return (cppu::OWeakObject
*)new IndexedPropertyValuesContainer();
270 void createRegistryInfo_IndexedPropertyValuesContainer()
272 static ::comphelper::module::OAutoRegistration
< IndexedPropertyValuesContainer
> aAutoRegistration
;