1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "NameContainer.hxx"
32 
33 /*
34 //SvXMLUnitConverter
35 #include <xmloff/xmluconv.hxx>
36 */
37 #include <com/sun/star/uno/Any.hxx>
38 
39 using namespace ::com::sun::star;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::uno::Any;
42 using ::rtl::OUString;
43 
44 
45 //.............................................................................
46 namespace chart
47 {
48 //.............................................................................
49 
50 uno::Reference< container::XNameContainer > createNameContainer(
51         const ::com::sun::star::uno::Type& rType, const rtl::OUString& rServicename, const rtl::OUString& rImplementationName )
52 {
53     return new NameContainer( rType, rServicename, rImplementationName );
54 }
55 
56 NameContainer::NameContainer( const ::com::sun::star::uno::Type& rType, const OUString& rServicename, const OUString& rImplementationName )
57     : m_aType( rType )
58     , m_aServicename( rServicename )
59     , m_aImplementationName( rImplementationName )
60     , m_aMap()
61 {
62 }
63 
64 NameContainer::NameContainer(
65     const NameContainer & rOther )
66     : impl::NameContainer_Base()
67     , m_aType( rOther.m_aType )
68     , m_aServicename( rOther.m_aServicename )
69     , m_aImplementationName( rOther.m_aImplementationName )
70     , m_aMap( rOther.m_aMap )
71 {
72 }
73 
74 NameContainer::~NameContainer()
75 {
76 }
77 
78 //XServiceInfo
79 OUString SAL_CALL NameContainer::getImplementationName()
80 	throw( ::com::sun::star::uno::RuntimeException )
81 {
82 	return m_aImplementationName;
83 }
84 
85 sal_Bool SAL_CALL NameContainer::supportsService( const OUString& ServiceName )
86 	throw( ::com::sun::star::uno::RuntimeException )
87 {
88 	Sequence< OUString > aSNL = getSupportedServiceNames();
89 	const OUString* pArray = aSNL.getArray();
90 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
91 	{
92 		if( pArray[ i ] == ServiceName )
93 			return sal_True;
94 	}
95 	return sal_False;
96 }
97 
98 Sequence< OUString > SAL_CALL NameContainer::getSupportedServiceNames()
99 	throw( ::com::sun::star::uno::RuntimeException )
100 {
101 	Sequence< OUString > aSNS( 1 );
102 	aSNS.getArray()[ 0 ] = m_aServicename;
103 	return aSNS;
104 }
105 
106 //-----------------------------------------------------------------
107 //-----------------------------------------------------------------
108 //-----------------------------------------------------------------
109 
110 // XNameContainer
111 void SAL_CALL NameContainer::insertByName( const OUString& rName, const Any& rElement )
112 	throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
113 {
114     if( m_aMap.find( rName ) != m_aMap.end() )
115         throw container::ElementExistException();
116     m_aMap.insert( tContentMap::value_type( rName, rElement ));
117 }
118 
119 
120 
121 void SAL_CALL NameContainer::removeByName( const OUString& Name )
122 	throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
123 {
124     tContentMap::iterator aIt( m_aMap.find( Name ));
125     if( aIt == m_aMap.end())
126         throw container::NoSuchElementException();
127     m_aMap.erase( aIt );
128 }
129 
130 // XNameReplace
131 void SAL_CALL NameContainer::replaceByName( const OUString& rName, const Any& rElement )
132 	throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
133 {
134     tContentMap::iterator aIt( m_aMap.find( rName ));
135     if( aIt == m_aMap.end() )
136         throw container::NoSuchElementException();
137     aIt->second = rElement;
138 }
139 
140 // XNameAccess
141 Any SAL_CALL NameContainer::getByName( const OUString& rName )
142 	throw( container::NoSuchElementException,  lang::WrappedTargetException, uno::RuntimeException)
143 {
144     tContentMap::iterator aIter( m_aMap.find( rName ) );
145     if( aIter == m_aMap.end() )
146         throw container::NoSuchElementException();
147     return aIter->second;
148 }
149 
150 Sequence< OUString > SAL_CALL NameContainer::getElementNames()
151 	throw( uno::RuntimeException )
152 {
153     sal_Int32 nCount = m_aMap.size();
154 	Sequence< OUString > aSeq(nCount);
155     sal_Int32 nN = 0;
156     for( tContentMap::iterator aIter = m_aMap.begin(); aIter != m_aMap.end(), nN < nCount; aIter++, nN++ )
157         aSeq[nN]=aIter->first;
158 	return aSeq;
159 }
160 
161 sal_Bool SAL_CALL NameContainer::hasByName( const OUString& rName )
162 	throw( uno::RuntimeException )
163 {
164     return ( m_aMap.find( rName ) != m_aMap.end() );
165 }
166 
167 // XElementAccess
168 sal_Bool SAL_CALL NameContainer::hasElements()
169 	throw( uno::RuntimeException )
170 {
171     return ! m_aMap.empty();
172 }
173 
174 uno::Type SAL_CALL NameContainer::getElementType()
175 	throw( uno::RuntimeException )
176 {
177 	return m_aType;
178 }
179 
180 // XCloneable
181 uno::Reference< util::XCloneable > SAL_CALL NameContainer::createClone()
182     throw ( uno::RuntimeException )
183 {
184     return uno::Reference< util::XCloneable >( new NameContainer( *this ));
185 }
186 
187 //.............................................................................
188 } //namespace chart
189 //.............................................................................
190