1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_comphelper.hxx"
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski #include "comphelper_module.hxx"
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski #include <com/sun/star/container/XNameContainer.hpp>
30*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Sequence.h>
31*b1cdbd2cSJim Jagielski #include <com/sun/star/beans/PropertyValue.hpp>
32*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/XComponentContext.hpp>
33*b1cdbd2cSJim Jagielski #include <cppuhelper/implbase2.hxx>
34*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XServiceInfo.hpp>
35*b1cdbd2cSJim Jagielski #include <comphelper/stl_types.hxx>
36*b1cdbd2cSJim Jagielski
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski #include <map>
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski
41*b1cdbd2cSJim Jagielski using namespace com::sun::star;
42*b1cdbd2cSJim Jagielski
43*b1cdbd2cSJim Jagielski DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence<beans::PropertyValue>, NamedPropertyValues );
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski class NamedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
46*b1cdbd2cSJim Jagielski {
47*b1cdbd2cSJim Jagielski public:
48*b1cdbd2cSJim Jagielski NamedPropertyValuesContainer() throw();
49*b1cdbd2cSJim Jagielski virtual ~NamedPropertyValuesContainer() throw();
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski // XNameContainer
52*b1cdbd2cSJim Jagielski virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
53*b1cdbd2cSJim Jagielski throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
54*b1cdbd2cSJim Jagielski ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
55*b1cdbd2cSJim Jagielski virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
56*b1cdbd2cSJim Jagielski throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
57*b1cdbd2cSJim Jagielski ::com::sun::star::uno::RuntimeException);
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski // XNameReplace
60*b1cdbd2cSJim Jagielski virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
61*b1cdbd2cSJim Jagielski throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
62*b1cdbd2cSJim Jagielski ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
63*b1cdbd2cSJim Jagielski
64*b1cdbd2cSJim Jagielski // XNameAccess
65*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
66*b1cdbd2cSJim Jagielski throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
67*b1cdbd2cSJim Jagielski ::com::sun::star::uno::RuntimeException);
68*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( )
69*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
70*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
71*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
72*b1cdbd2cSJim Jagielski
73*b1cdbd2cSJim Jagielski // XElementAccess
74*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
75*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
76*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL hasElements( )
77*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski //XServiceInfo
80*b1cdbd2cSJim Jagielski virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
81*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
82*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim Jagielski // XServiceInfo - static versions (used for component registration)
85*b1cdbd2cSJim Jagielski static ::rtl::OUString SAL_CALL getImplementationName_static();
86*b1cdbd2cSJim Jagielski static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
87*b1cdbd2cSJim Jagielski static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
88*b1cdbd2cSJim Jagielski
89*b1cdbd2cSJim Jagielski private:
90*b1cdbd2cSJim Jagielski NamedPropertyValues maProperties;
91*b1cdbd2cSJim Jagielski };
92*b1cdbd2cSJim Jagielski
NamedPropertyValuesContainer()93*b1cdbd2cSJim Jagielski NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
94*b1cdbd2cSJim Jagielski {
95*b1cdbd2cSJim Jagielski }
96*b1cdbd2cSJim Jagielski
~NamedPropertyValuesContainer()97*b1cdbd2cSJim Jagielski NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw()
98*b1cdbd2cSJim Jagielski {
99*b1cdbd2cSJim Jagielski }
100*b1cdbd2cSJim Jagielski
101*b1cdbd2cSJim Jagielski // XNameContainer
insertByName(const rtl::OUString & aName,const uno::Any & aElement)102*b1cdbd2cSJim Jagielski void SAL_CALL NamedPropertyValuesContainer::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
103*b1cdbd2cSJim Jagielski throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
104*b1cdbd2cSJim Jagielski ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
105*b1cdbd2cSJim Jagielski {
106*b1cdbd2cSJim Jagielski if( maProperties.find( aName ) != maProperties.end() )
107*b1cdbd2cSJim Jagielski throw container::ElementExistException();
108*b1cdbd2cSJim Jagielski
109*b1cdbd2cSJim Jagielski uno::Sequence<beans::PropertyValue> aProps;
110*b1cdbd2cSJim Jagielski if( !(aElement >>= aProps ) )
111*b1cdbd2cSJim Jagielski throw lang::IllegalArgumentException();
112*b1cdbd2cSJim Jagielski
113*b1cdbd2cSJim Jagielski maProperties.insert( NamedPropertyValues::value_type(aName ,aProps) );
114*b1cdbd2cSJim Jagielski }
115*b1cdbd2cSJim Jagielski
removeByName(const::rtl::OUString & Name)116*b1cdbd2cSJim Jagielski void SAL_CALL NamedPropertyValuesContainer::removeByName( const ::rtl::OUString& Name )
117*b1cdbd2cSJim Jagielski throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
118*b1cdbd2cSJim Jagielski ::com::sun::star::uno::RuntimeException)
119*b1cdbd2cSJim Jagielski {
120*b1cdbd2cSJim Jagielski NamedPropertyValues::iterator aIter = maProperties.find( Name );
121*b1cdbd2cSJim Jagielski if( aIter == maProperties.end() )
122*b1cdbd2cSJim Jagielski throw container::NoSuchElementException();
123*b1cdbd2cSJim Jagielski
124*b1cdbd2cSJim Jagielski maProperties.erase( aIter );
125*b1cdbd2cSJim Jagielski }
126*b1cdbd2cSJim Jagielski
127*b1cdbd2cSJim Jagielski // XNameReplace
replaceByName(const::rtl::OUString & aName,const::com::sun::star::uno::Any & aElement)128*b1cdbd2cSJim Jagielski void SAL_CALL NamedPropertyValuesContainer::replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
129*b1cdbd2cSJim Jagielski throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
130*b1cdbd2cSJim Jagielski ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
131*b1cdbd2cSJim Jagielski {
132*b1cdbd2cSJim Jagielski NamedPropertyValues::iterator aIter = maProperties.find( aName );
133*b1cdbd2cSJim Jagielski if( aIter == maProperties.end() )
134*b1cdbd2cSJim Jagielski throw container::NoSuchElementException();
135*b1cdbd2cSJim Jagielski
136*b1cdbd2cSJim Jagielski uno::Sequence<beans::PropertyValue> aProps;
137*b1cdbd2cSJim Jagielski if( !(aElement >>= aProps) )
138*b1cdbd2cSJim Jagielski throw lang::IllegalArgumentException();
139*b1cdbd2cSJim Jagielski
140*b1cdbd2cSJim Jagielski (*aIter).second = aProps;
141*b1cdbd2cSJim Jagielski }
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski // XNameAccess
getByName(const::rtl::OUString & aName)144*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Any SAL_CALL NamedPropertyValuesContainer::getByName( const ::rtl::OUString& aName )
145*b1cdbd2cSJim Jagielski throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
146*b1cdbd2cSJim Jagielski ::com::sun::star::uno::RuntimeException)
147*b1cdbd2cSJim Jagielski {
148*b1cdbd2cSJim Jagielski NamedPropertyValues::iterator aIter = maProperties.find( aName );
149*b1cdbd2cSJim Jagielski if( aIter == maProperties.end() )
150*b1cdbd2cSJim Jagielski throw container::NoSuchElementException();
151*b1cdbd2cSJim Jagielski
152*b1cdbd2cSJim Jagielski uno::Any aElement;
153*b1cdbd2cSJim Jagielski
154*b1cdbd2cSJim Jagielski aElement <<= (*aIter).second;
155*b1cdbd2cSJim Jagielski
156*b1cdbd2cSJim Jagielski return aElement;
157*b1cdbd2cSJim Jagielski }
158*b1cdbd2cSJim Jagielski
getElementNames()159*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames( )
160*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException)
161*b1cdbd2cSJim Jagielski {
162*b1cdbd2cSJim Jagielski NamedPropertyValues::iterator aIter = maProperties.begin();
163*b1cdbd2cSJim Jagielski const NamedPropertyValues::iterator aEnd = maProperties.end();
164*b1cdbd2cSJim Jagielski
165*b1cdbd2cSJim Jagielski uno::Sequence< rtl::OUString > aNames( maProperties.size() );
166*b1cdbd2cSJim Jagielski rtl::OUString* pNames = aNames.getArray();
167*b1cdbd2cSJim Jagielski
168*b1cdbd2cSJim Jagielski while( aIter != aEnd )
169*b1cdbd2cSJim Jagielski {
170*b1cdbd2cSJim Jagielski *pNames++ = (*aIter++).first;
171*b1cdbd2cSJim Jagielski }
172*b1cdbd2cSJim Jagielski
173*b1cdbd2cSJim Jagielski return aNames;
174*b1cdbd2cSJim Jagielski }
175*b1cdbd2cSJim Jagielski
hasByName(const::rtl::OUString & aName)176*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const ::rtl::OUString& aName )
177*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException)
178*b1cdbd2cSJim Jagielski {
179*b1cdbd2cSJim Jagielski NamedPropertyValues::iterator aIter = maProperties.find( aName );
180*b1cdbd2cSJim Jagielski return aIter != maProperties.end();
181*b1cdbd2cSJim Jagielski }
182*b1cdbd2cSJim Jagielski
183*b1cdbd2cSJim Jagielski // XElementAccess
getElementType()184*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType( )
185*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException)
186*b1cdbd2cSJim Jagielski {
187*b1cdbd2cSJim Jagielski return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0);
188*b1cdbd2cSJim Jagielski }
189*b1cdbd2cSJim Jagielski
hasElements()190*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements( )
191*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException)
192*b1cdbd2cSJim Jagielski {
193*b1cdbd2cSJim Jagielski return !maProperties.empty();
194*b1cdbd2cSJim Jagielski }
195*b1cdbd2cSJim Jagielski
196*b1cdbd2cSJim Jagielski //XServiceInfo
getImplementationName()197*b1cdbd2cSJim Jagielski ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
198*b1cdbd2cSJim Jagielski {
199*b1cdbd2cSJim Jagielski return getImplementationName_static();
200*b1cdbd2cSJim Jagielski }
201*b1cdbd2cSJim Jagielski
getImplementationName_static()202*b1cdbd2cSJim Jagielski ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static( )
203*b1cdbd2cSJim Jagielski {
204*b1cdbd2cSJim Jagielski return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPropertyValuesContainer" ) );
205*b1cdbd2cSJim Jagielski }
206*b1cdbd2cSJim Jagielski
supportsService(const::rtl::OUString & ServiceName)207*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
208*b1cdbd2cSJim Jagielski {
209*b1cdbd2cSJim Jagielski rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) );
210*b1cdbd2cSJim Jagielski return aServiceName == ServiceName;
211*b1cdbd2cSJim Jagielski }
212*b1cdbd2cSJim Jagielski
getSupportedServiceNames()213*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
214*b1cdbd2cSJim Jagielski {
215*b1cdbd2cSJim Jagielski return getSupportedServiceNames_static();
216*b1cdbd2cSJim Jagielski }
217*b1cdbd2cSJim Jagielski
218*b1cdbd2cSJim Jagielski
getSupportedServiceNames_static()219*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static( )
220*b1cdbd2cSJim Jagielski {
221*b1cdbd2cSJim Jagielski const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) );
222*b1cdbd2cSJim Jagielski const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
223*b1cdbd2cSJim Jagielski return aSeq;
224*b1cdbd2cSJim Jagielski }
225*b1cdbd2cSJim Jagielski
Create(const uno::Reference<uno::XComponentContext> &)226*b1cdbd2cSJim Jagielski uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create(
227*b1cdbd2cSJim Jagielski const uno::Reference< uno::XComponentContext >&)
228*b1cdbd2cSJim Jagielski {
229*b1cdbd2cSJim Jagielski return (cppu::OWeakObject*)new NamedPropertyValuesContainer();
230*b1cdbd2cSJim Jagielski }
231*b1cdbd2cSJim Jagielski
createRegistryInfo_NamedPropertyValuesContainer()232*b1cdbd2cSJim Jagielski void createRegistryInfo_NamedPropertyValuesContainer()
233*b1cdbd2cSJim Jagielski {
234*b1cdbd2cSJim Jagielski static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration;
235*b1cdbd2cSJim Jagielski }
236