Update ooo320-m1
[ooovba.git] / comphelper / source / container / NamedPropertyValuesContainer.cxx
blob6f79f3c0333d832bc7cdbc8cc9d6820e36c02bcc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NamedPropertyValuesContainer.cxx,v $
10 * $Revision: 1.8 $
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/XNameContainer.hpp>
37 #include <com/sun/star/uno/Sequence.h>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <cppuhelper/implbase2.hxx>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <comphelper/stl_types.hxx>
45 #include <map>
48 using namespace com::sun::star;
50 DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence<beans::PropertyValue>, NamedPropertyValues );
52 class NamedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
54 public:
55 NamedPropertyValuesContainer() throw();
56 virtual ~NamedPropertyValuesContainer() throw();
58 // XNameContainer
59 virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
60 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
61 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
62 virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
63 throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
64 ::com::sun::star::uno::RuntimeException);
66 // XNameReplace
67 virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
68 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
69 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
71 // XNameAccess
72 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
73 throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
74 ::com::sun::star::uno::RuntimeException);
75 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( )
76 throw(::com::sun::star::uno::RuntimeException);
77 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
78 throw(::com::sun::star::uno::RuntimeException);
80 // XElementAccess
81 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
82 throw(::com::sun::star::uno::RuntimeException);
83 virtual sal_Bool SAL_CALL hasElements( )
84 throw(::com::sun::star::uno::RuntimeException);
86 //XServiceInfo
87 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
88 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
89 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
91 // XServiceInfo - static versions (used for component registration)
92 static ::rtl::OUString SAL_CALL getImplementationName_static();
93 static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
94 static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
96 private:
97 NamedPropertyValues maProperties;
100 NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
104 NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw()
108 // XNameContainer
109 void SAL_CALL NamedPropertyValuesContainer::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
110 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
111 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
113 if( maProperties.find( aName ) != maProperties.end() )
114 throw container::ElementExistException();
116 uno::Sequence<beans::PropertyValue> aProps;
117 if( !(aElement >>= aProps ) )
118 throw lang::IllegalArgumentException();
120 maProperties.insert( NamedPropertyValues::value_type(aName ,aProps) );
123 void SAL_CALL NamedPropertyValuesContainer::removeByName( const ::rtl::OUString& Name )
124 throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
125 ::com::sun::star::uno::RuntimeException)
127 NamedPropertyValues::iterator aIter = maProperties.find( Name );
128 if( aIter == maProperties.end() )
129 throw container::NoSuchElementException();
131 maProperties.erase( aIter );
134 // XNameReplace
135 void SAL_CALL NamedPropertyValuesContainer::replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
136 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
137 ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
139 NamedPropertyValues::iterator aIter = maProperties.find( aName );
140 if( aIter == maProperties.end() )
141 throw container::NoSuchElementException();
143 uno::Sequence<beans::PropertyValue> aProps;
144 if( !(aElement >>= aProps) )
145 throw lang::IllegalArgumentException();
147 (*aIter).second = aProps;
150 // XNameAccess
151 ::com::sun::star::uno::Any SAL_CALL NamedPropertyValuesContainer::getByName( const ::rtl::OUString& aName )
152 throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
153 ::com::sun::star::uno::RuntimeException)
155 NamedPropertyValues::iterator aIter = maProperties.find( aName );
156 if( aIter == maProperties.end() )
157 throw container::NoSuchElementException();
159 uno::Any aElement;
161 aElement <<= (*aIter).second;
163 return aElement;
166 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames( )
167 throw(::com::sun::star::uno::RuntimeException)
169 NamedPropertyValues::iterator aIter = maProperties.begin();
170 const NamedPropertyValues::iterator aEnd = maProperties.end();
172 uno::Sequence< rtl::OUString > aNames( maProperties.size() );
173 rtl::OUString* pNames = aNames.getArray();
175 while( aIter != aEnd )
177 *pNames++ = (*aIter++).first;
180 return aNames;
183 sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const ::rtl::OUString& aName )
184 throw(::com::sun::star::uno::RuntimeException)
186 NamedPropertyValues::iterator aIter = maProperties.find( aName );
187 return aIter != maProperties.end();
190 // XElementAccess
191 ::com::sun::star::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType( )
192 throw(::com::sun::star::uno::RuntimeException)
194 return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
197 sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements( )
198 throw(::com::sun::star::uno::RuntimeException)
200 return !maProperties.empty();
203 //XServiceInfo
204 ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
206 return getImplementationName_static();
209 ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static( )
211 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPropertyValuesContainer" ) );
214 sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
216 rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) );
217 return aServiceName == ServiceName;
220 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
222 return getSupportedServiceNames_static();
226 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static( )
228 const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) );
229 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
230 return aSeq;
233 uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create(
234 const uno::Reference< uno::XComponentContext >&)
236 return (cppu::OWeakObject*)new NamedPropertyValuesContainer();
239 void createRegistryInfo_NamedPropertyValuesContainer()
241 static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration;