1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "NameContainer.hxx"
28 
29 /*
30 //SvXMLUnitConverter
31 #include <xmloff/xmluconv.hxx>
32 */
33 #include <com/sun/star/uno/Any.hxx>
34 
35 using namespace ::com::sun::star;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::uno::Any;
38 using ::rtl::OUString;
39 
40 
41 //.............................................................................
42 namespace chart
43 {
44 //.............................................................................
45 
createNameContainer(const::com::sun::star::uno::Type & rType,const rtl::OUString & rServicename,const rtl::OUString & rImplementationName)46 uno::Reference< container::XNameContainer > createNameContainer(
47         const ::com::sun::star::uno::Type& rType, const rtl::OUString& rServicename, const rtl::OUString& rImplementationName )
48 {
49     return new NameContainer( rType, rServicename, rImplementationName );
50 }
51 
NameContainer(const::com::sun::star::uno::Type & rType,const OUString & rServicename,const OUString & rImplementationName)52 NameContainer::NameContainer( const ::com::sun::star::uno::Type& rType, const OUString& rServicename, const OUString& rImplementationName )
53     : m_aType( rType )
54     , m_aServicename( rServicename )
55     , m_aImplementationName( rImplementationName )
56     , m_aMap()
57 {
58 }
59 
NameContainer(const NameContainer & rOther)60 NameContainer::NameContainer(
61     const NameContainer & rOther )
62     : impl::NameContainer_Base()
63     , m_aType( rOther.m_aType )
64     , m_aServicename( rOther.m_aServicename )
65     , m_aImplementationName( rOther.m_aImplementationName )
66     , m_aMap( rOther.m_aMap )
67 {
68 }
69 
~NameContainer()70 NameContainer::~NameContainer()
71 {
72 }
73 
74 //XServiceInfo
getImplementationName()75 OUString SAL_CALL NameContainer::getImplementationName()
76 	throw( ::com::sun::star::uno::RuntimeException )
77 {
78 	return m_aImplementationName;
79 }
80 
supportsService(const OUString & ServiceName)81 sal_Bool SAL_CALL NameContainer::supportsService( const OUString& ServiceName )
82 	throw( ::com::sun::star::uno::RuntimeException )
83 {
84 	Sequence< OUString > aSNL = getSupportedServiceNames();
85 	const OUString* pArray = aSNL.getArray();
86 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
87 	{
88 		if( pArray[ i ] == ServiceName )
89 			return sal_True;
90 	}
91 	return sal_False;
92 }
93 
getSupportedServiceNames()94 Sequence< OUString > SAL_CALL NameContainer::getSupportedServiceNames()
95 	throw( ::com::sun::star::uno::RuntimeException )
96 {
97 	Sequence< OUString > aSNS( 1 );
98 	aSNS.getArray()[ 0 ] = m_aServicename;
99 	return aSNS;
100 }
101 
102 //-----------------------------------------------------------------
103 //-----------------------------------------------------------------
104 //-----------------------------------------------------------------
105 
106 // XNameContainer
insertByName(const OUString & rName,const Any & rElement)107 void SAL_CALL NameContainer::insertByName( const OUString& rName, const Any& rElement )
108 	throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
109 {
110     if( m_aMap.find( rName ) != m_aMap.end() )
111         throw container::ElementExistException();
112     m_aMap.insert( tContentMap::value_type( rName, rElement ));
113 }
114 
115 
116 
removeByName(const OUString & Name)117 void SAL_CALL NameContainer::removeByName( const OUString& Name )
118 	throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
119 {
120     tContentMap::iterator aIt( m_aMap.find( Name ));
121     if( aIt == m_aMap.end())
122         throw container::NoSuchElementException();
123     m_aMap.erase( aIt );
124 }
125 
126 // XNameReplace
replaceByName(const OUString & rName,const Any & rElement)127 void SAL_CALL NameContainer::replaceByName( const OUString& rName, const Any& rElement )
128 	throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
129 {
130     tContentMap::iterator aIt( m_aMap.find( rName ));
131     if( aIt == m_aMap.end() )
132         throw container::NoSuchElementException();
133     aIt->second = rElement;
134 }
135 
136 // XNameAccess
getByName(const OUString & rName)137 Any SAL_CALL NameContainer::getByName( const OUString& rName )
138 	throw( container::NoSuchElementException,  lang::WrappedTargetException, uno::RuntimeException)
139 {
140     tContentMap::iterator aIter( m_aMap.find( rName ) );
141     if( aIter == m_aMap.end() )
142         throw container::NoSuchElementException();
143     return aIter->second;
144 }
145 
getElementNames()146 Sequence< OUString > SAL_CALL NameContainer::getElementNames()
147 	throw( uno::RuntimeException )
148 {
149     sal_Int32 nCount = m_aMap.size();
150 	Sequence< OUString > aSeq(nCount);
151     sal_Int32 nN = 0;
152     for( tContentMap::iterator aIter = m_aMap.begin(); aIter != m_aMap.end(), nN < nCount; aIter++, nN++ )
153         aSeq[nN]=aIter->first;
154 	return aSeq;
155 }
156 
hasByName(const OUString & rName)157 sal_Bool SAL_CALL NameContainer::hasByName( const OUString& rName )
158 	throw( uno::RuntimeException )
159 {
160     return ( m_aMap.find( rName ) != m_aMap.end() );
161 }
162 
163 // XElementAccess
hasElements()164 sal_Bool SAL_CALL NameContainer::hasElements()
165 	throw( uno::RuntimeException )
166 {
167     return ! m_aMap.empty();
168 }
169 
getElementType()170 uno::Type SAL_CALL NameContainer::getElementType()
171 	throw( uno::RuntimeException )
172 {
173 	return m_aType;
174 }
175 
176 // XCloneable
createClone()177 uno::Reference< util::XCloneable > SAL_CALL NameContainer::createClone()
178     throw ( uno::RuntimeException )
179 {
180     return uno::Reference< util::XCloneable >( new NameContainer( *this ));
181 }
182 
183 //.............................................................................
184 } //namespace chart
185 //.............................................................................
186