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 #include <comphelper/namecontainer.hxx>
27*b1cdbd2cSJim Jagielski #include <cppuhelper/implbase1.hxx>
28*b1cdbd2cSJim Jagielski #include <osl/diagnose.h>
29*b1cdbd2cSJim Jagielski #include <osl/mutex.hxx>
30*b1cdbd2cSJim Jagielski #include <comphelper/stl_types.hxx>
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim Jagielski DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Any, SvGenericNameContainerMapImpl );
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski namespace comphelper
35*b1cdbd2cSJim Jagielski {
36*b1cdbd2cSJim Jagielski class NameContainerImpl
37*b1cdbd2cSJim Jagielski {
38*b1cdbd2cSJim Jagielski public:
39*b1cdbd2cSJim Jagielski osl::Mutex maMutex;
40*b1cdbd2cSJim Jagielski };
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski /** this is the base helper class for NameContainer thats also declared in this header. */
43*b1cdbd2cSJim Jagielski class NameContainer : public ::cppu::WeakImplHelper1< ::com::sun::star::container::XNameContainer >, private NameContainerImpl
44*b1cdbd2cSJim Jagielski {
45*b1cdbd2cSJim Jagielski public:
46*b1cdbd2cSJim Jagielski NameContainer( ::com::sun::star::uno::Type aType );
47*b1cdbd2cSJim Jagielski virtual ~NameContainer();
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski // XNameContainer
50*b1cdbd2cSJim Jagielski virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
51*b1cdbd2cSJim Jagielski throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException,
52*b1cdbd2cSJim Jagielski ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
53*b1cdbd2cSJim Jagielski virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
54*b1cdbd2cSJim Jagielski throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
55*b1cdbd2cSJim Jagielski ::com::sun::star::uno::RuntimeException);
56*b1cdbd2cSJim Jagielski
57*b1cdbd2cSJim Jagielski // XNameReplace
58*b1cdbd2cSJim Jagielski virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
59*b1cdbd2cSJim Jagielski throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException,
60*b1cdbd2cSJim Jagielski ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
61*b1cdbd2cSJim Jagielski
62*b1cdbd2cSJim Jagielski // XNameAccess
63*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
64*b1cdbd2cSJim Jagielski throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException,
65*b1cdbd2cSJim Jagielski ::com::sun::star::uno::RuntimeException);
66*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( )
67*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
68*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
69*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
70*b1cdbd2cSJim Jagielski
71*b1cdbd2cSJim Jagielski // XElementAccess
72*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL hasElements( )
73*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
74*b1cdbd2cSJim Jagielski virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
75*b1cdbd2cSJim Jagielski throw(::com::sun::star::uno::RuntimeException);
76*b1cdbd2cSJim Jagielski
77*b1cdbd2cSJim Jagielski private:
78*b1cdbd2cSJim Jagielski SvGenericNameContainerMapImpl maProperties;
79*b1cdbd2cSJim Jagielski const ::com::sun::star::uno::Type maType;
80*b1cdbd2cSJim Jagielski };
81*b1cdbd2cSJim Jagielski }
82*b1cdbd2cSJim Jagielski
83*b1cdbd2cSJim Jagielski using namespace ::comphelper;
84*b1cdbd2cSJim Jagielski using namespace ::osl;
85*b1cdbd2cSJim Jagielski using namespace ::rtl;
86*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::uno;
87*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::container;
88*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::lang;
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski
NameContainer(::com::sun::star::uno::Type aType)91*b1cdbd2cSJim Jagielski NameContainer::NameContainer( ::com::sun::star::uno::Type aType )
92*b1cdbd2cSJim Jagielski : maType( aType )
93*b1cdbd2cSJim Jagielski {
94*b1cdbd2cSJim Jagielski }
95*b1cdbd2cSJim Jagielski
~NameContainer()96*b1cdbd2cSJim Jagielski NameContainer::~NameContainer()
97*b1cdbd2cSJim Jagielski {
98*b1cdbd2cSJim Jagielski }
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski // XNameContainer
insertByName(const rtl::OUString & aName,const Any & aElement)101*b1cdbd2cSJim Jagielski void SAL_CALL NameContainer::insertByName( const rtl::OUString& aName, const Any& aElement )
102*b1cdbd2cSJim Jagielski throw(IllegalArgumentException, ElementExistException,
103*b1cdbd2cSJim Jagielski WrappedTargetException, RuntimeException)
104*b1cdbd2cSJim Jagielski {
105*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
106*b1cdbd2cSJim Jagielski
107*b1cdbd2cSJim Jagielski if( maProperties.find( aName ) != maProperties.end() )
108*b1cdbd2cSJim Jagielski throw ElementExistException();
109*b1cdbd2cSJim Jagielski
110*b1cdbd2cSJim Jagielski if( aElement.getValueType() != maType )
111*b1cdbd2cSJim Jagielski throw IllegalArgumentException();
112*b1cdbd2cSJim Jagielski
113*b1cdbd2cSJim Jagielski maProperties.insert( SvGenericNameContainerMapImpl::value_type(aName,aElement));
114*b1cdbd2cSJim Jagielski }
115*b1cdbd2cSJim Jagielski
removeByName(const::rtl::OUString & Name)116*b1cdbd2cSJim Jagielski void SAL_CALL NameContainer::removeByName( const ::rtl::OUString& Name )
117*b1cdbd2cSJim Jagielski throw(NoSuchElementException, WrappedTargetException,
118*b1cdbd2cSJim Jagielski RuntimeException)
119*b1cdbd2cSJim Jagielski {
120*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
121*b1cdbd2cSJim Jagielski
122*b1cdbd2cSJim Jagielski SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( Name );
123*b1cdbd2cSJim Jagielski if( aIter == maProperties.end() )
124*b1cdbd2cSJim Jagielski throw NoSuchElementException();
125*b1cdbd2cSJim Jagielski
126*b1cdbd2cSJim Jagielski maProperties.erase( aIter );
127*b1cdbd2cSJim Jagielski }
128*b1cdbd2cSJim Jagielski
129*b1cdbd2cSJim Jagielski // XNameReplace
130*b1cdbd2cSJim Jagielski
replaceByName(const::rtl::OUString & aName,const Any & aElement)131*b1cdbd2cSJim Jagielski void SAL_CALL NameContainer::replaceByName( const ::rtl::OUString& aName, const Any& aElement )
132*b1cdbd2cSJim Jagielski throw(IllegalArgumentException, NoSuchElementException,
133*b1cdbd2cSJim Jagielski WrappedTargetException, RuntimeException)
134*b1cdbd2cSJim Jagielski {
135*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielski SvGenericNameContainerMapImpl::iterator aIter( maProperties.find( aName ) );
138*b1cdbd2cSJim Jagielski if( aIter == maProperties.end() )
139*b1cdbd2cSJim Jagielski throw NoSuchElementException();
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski if( aElement.getValueType() != maType )
142*b1cdbd2cSJim Jagielski throw IllegalArgumentException();
143*b1cdbd2cSJim Jagielski
144*b1cdbd2cSJim Jagielski (*aIter).second = aElement;
145*b1cdbd2cSJim Jagielski }
146*b1cdbd2cSJim Jagielski
147*b1cdbd2cSJim Jagielski // XNameAccess
148*b1cdbd2cSJim Jagielski
getByName(const::rtl::OUString & aName)149*b1cdbd2cSJim Jagielski Any SAL_CALL NameContainer::getByName( const ::rtl::OUString& aName )
150*b1cdbd2cSJim Jagielski throw(NoSuchElementException, WrappedTargetException,
151*b1cdbd2cSJim Jagielski RuntimeException)
152*b1cdbd2cSJim Jagielski {
153*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
154*b1cdbd2cSJim Jagielski
155*b1cdbd2cSJim Jagielski SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( aName );
156*b1cdbd2cSJim Jagielski if( aIter == maProperties.end() )
157*b1cdbd2cSJim Jagielski throw NoSuchElementException();
158*b1cdbd2cSJim Jagielski
159*b1cdbd2cSJim Jagielski return (*aIter).second;
160*b1cdbd2cSJim Jagielski }
161*b1cdbd2cSJim Jagielski
getElementNames()162*b1cdbd2cSJim Jagielski Sequence< ::rtl::OUString > SAL_CALL NameContainer::getElementNames( )
163*b1cdbd2cSJim Jagielski throw(RuntimeException)
164*b1cdbd2cSJim Jagielski {
165*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim Jagielski SvGenericNameContainerMapImpl::iterator aIter = maProperties.begin();
168*b1cdbd2cSJim Jagielski const SvGenericNameContainerMapImpl::iterator aEnd = maProperties.end();
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski Sequence< rtl::OUString > aNames( maProperties.size() );
171*b1cdbd2cSJim Jagielski rtl::OUString* pNames = aNames.getArray();
172*b1cdbd2cSJim Jagielski
173*b1cdbd2cSJim Jagielski while( aIter != aEnd )
174*b1cdbd2cSJim Jagielski {
175*b1cdbd2cSJim Jagielski *pNames++ = (*aIter++).first;
176*b1cdbd2cSJim Jagielski }
177*b1cdbd2cSJim Jagielski
178*b1cdbd2cSJim Jagielski return aNames;
179*b1cdbd2cSJim Jagielski }
180*b1cdbd2cSJim Jagielski
hasByName(const::rtl::OUString & aName)181*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL NameContainer::hasByName( const ::rtl::OUString& aName )
182*b1cdbd2cSJim Jagielski throw(RuntimeException)
183*b1cdbd2cSJim Jagielski {
184*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
185*b1cdbd2cSJim Jagielski
186*b1cdbd2cSJim Jagielski SvGenericNameContainerMapImpl::iterator aIter = maProperties.find( aName );
187*b1cdbd2cSJim Jagielski return aIter != maProperties.end();
188*b1cdbd2cSJim Jagielski }
189*b1cdbd2cSJim Jagielski
hasElements()190*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL NameContainer::hasElements( )
191*b1cdbd2cSJim Jagielski throw(RuntimeException)
192*b1cdbd2cSJim Jagielski {
193*b1cdbd2cSJim Jagielski MutexGuard aGuard( maMutex );
194*b1cdbd2cSJim Jagielski
195*b1cdbd2cSJim Jagielski return !maProperties.empty();
196*b1cdbd2cSJim Jagielski }
197*b1cdbd2cSJim Jagielski
getElementType()198*b1cdbd2cSJim Jagielski Type SAL_CALL NameContainer::getElementType()
199*b1cdbd2cSJim Jagielski throw( RuntimeException )
200*b1cdbd2cSJim Jagielski {
201*b1cdbd2cSJim Jagielski return maType;
202*b1cdbd2cSJim Jagielski }
203*b1cdbd2cSJim Jagielski
NameContainer_createInstance(Type aType)204*b1cdbd2cSJim Jagielski Reference< XNameContainer > comphelper::NameContainer_createInstance( Type aType )
205*b1cdbd2cSJim Jagielski {
206*b1cdbd2cSJim Jagielski return (XNameContainer*) new NameContainer( aType );
207*b1cdbd2cSJim Jagielski }
208