1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 #include "comphelper_module.hxx"
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/uno/Sequence.h>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <cppuhelper/implbase2.hxx>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <comphelper/stl_types.hxx>
45 using namespace com::sun::star
;
47 DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence
<beans::PropertyValue
>, NamedPropertyValues
);
49 class NamedPropertyValuesContainer
: public cppu::WeakImplHelper2
< container::XNameContainer
, lang::XServiceInfo
>
52 NamedPropertyValuesContainer() throw();
53 virtual ~NamedPropertyValuesContainer() throw();
56 virtual void SAL_CALL
insertByName( const ::rtl::OUString
& aName
, const ::com::sun::star::uno::Any
& aElement
)
57 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::ElementExistException
,
58 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
59 virtual void SAL_CALL
removeByName( const ::rtl::OUString
& Name
)
60 throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
,
61 ::com::sun::star::uno::RuntimeException
);
64 virtual void SAL_CALL
replaceByName( const ::rtl::OUString
& aName
, const ::com::sun::star::uno::Any
& aElement
)
65 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
,
66 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
69 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const ::rtl::OUString
& aName
)
70 throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
,
71 ::com::sun::star::uno::RuntimeException
);
72 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getElementNames( )
73 throw(::com::sun::star::uno::RuntimeException
);
74 virtual sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
)
75 throw(::com::sun::star::uno::RuntimeException
);
78 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( )
79 throw(::com::sun::star::uno::RuntimeException
);
80 virtual sal_Bool SAL_CALL
hasElements( )
81 throw(::com::sun::star::uno::RuntimeException
);
84 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
85 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
86 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
88 // XServiceInfo - static versions (used for component registration)
89 static ::rtl::OUString SAL_CALL
getImplementationName_static();
90 static uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames_static();
91 static uno::Reference
< uno::XInterface
> SAL_CALL
Create( const uno::Reference
< uno::XComponentContext
>& );
94 NamedPropertyValues maProperties
;
97 NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
101 NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw()
106 void SAL_CALL
NamedPropertyValuesContainer::insertByName( const rtl::OUString
& aName
, const uno::Any
& aElement
)
107 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::ElementExistException
,
108 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
110 if( maProperties
.find( aName
) != maProperties
.end() )
111 throw container::ElementExistException();
113 uno::Sequence
<beans::PropertyValue
> aProps
;
114 if( !(aElement
>>= aProps
) )
115 throw lang::IllegalArgumentException();
117 maProperties
.insert( NamedPropertyValues::value_type(aName
,aProps
) );
120 void SAL_CALL
NamedPropertyValuesContainer::removeByName( const ::rtl::OUString
& Name
)
121 throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
,
122 ::com::sun::star::uno::RuntimeException
)
124 NamedPropertyValues::iterator aIter
= maProperties
.find( Name
);
125 if( aIter
== maProperties
.end() )
126 throw container::NoSuchElementException();
128 maProperties
.erase( aIter
);
132 void SAL_CALL
NamedPropertyValuesContainer::replaceByName( const ::rtl::OUString
& aName
, const ::com::sun::star::uno::Any
& aElement
)
133 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
,
134 ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
136 NamedPropertyValues::iterator aIter
= maProperties
.find( aName
);
137 if( aIter
== maProperties
.end() )
138 throw container::NoSuchElementException();
140 uno::Sequence
<beans::PropertyValue
> aProps
;
141 if( !(aElement
>>= aProps
) )
142 throw lang::IllegalArgumentException();
144 (*aIter
).second
= aProps
;
148 ::com::sun::star::uno::Any SAL_CALL
NamedPropertyValuesContainer::getByName( const ::rtl::OUString
& aName
)
149 throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
,
150 ::com::sun::star::uno::RuntimeException
)
152 NamedPropertyValues::iterator aIter
= maProperties
.find( aName
);
153 if( aIter
== maProperties
.end() )
154 throw container::NoSuchElementException();
158 aElement
<<= (*aIter
).second
;
163 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
NamedPropertyValuesContainer::getElementNames( )
164 throw(::com::sun::star::uno::RuntimeException
)
166 NamedPropertyValues::iterator aIter
= maProperties
.begin();
167 const NamedPropertyValues::iterator aEnd
= maProperties
.end();
169 uno::Sequence
< rtl::OUString
> aNames( maProperties
.size() );
170 rtl::OUString
* pNames
= aNames
.getArray();
172 while( aIter
!= aEnd
)
174 *pNames
++ = (*aIter
++).first
;
180 sal_Bool SAL_CALL
NamedPropertyValuesContainer::hasByName( const ::rtl::OUString
& aName
)
181 throw(::com::sun::star::uno::RuntimeException
)
183 NamedPropertyValues::iterator aIter
= maProperties
.find( aName
);
184 return aIter
!= maProperties
.end();
188 ::com::sun::star::uno::Type SAL_CALL
NamedPropertyValuesContainer::getElementType( )
189 throw(::com::sun::star::uno::RuntimeException
)
191 return ::getCppuType((uno::Sequence
<beans::PropertyValue
> *)0);
194 sal_Bool SAL_CALL
NamedPropertyValuesContainer::hasElements( )
195 throw(::com::sun::star::uno::RuntimeException
)
197 return !maProperties
.empty();
201 ::rtl::OUString SAL_CALL
NamedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
)
203 return getImplementationName_static();
206 ::rtl::OUString SAL_CALL
NamedPropertyValuesContainer::getImplementationName_static( )
208 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPropertyValuesContainer" ) );
211 sal_Bool SAL_CALL
NamedPropertyValuesContainer::supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
)
213 rtl::OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) );
214 return aServiceName
== ServiceName
;
217 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
219 return getSupportedServiceNames_static();
223 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
NamedPropertyValuesContainer::getSupportedServiceNames_static( )
225 const rtl::OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) );
226 const uno::Sequence
< rtl::OUString
> aSeq( &aServiceName
, 1 );
230 uno::Reference
< uno::XInterface
> SAL_CALL
NamedPropertyValuesContainer::Create(
231 const uno::Reference
< uno::XComponentContext
>&)
233 return (cppu::OWeakObject
*)new NamedPropertyValuesContainer();
236 void createRegistryInfo_NamedPropertyValuesContainer()
238 static ::comphelper::module::OAutoRegistration
< NamedPropertyValuesContainer
> aAutoRegistration
;