merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / tools / NameContainer.cxx
blobbed657d27a0dac8cec9e1ce0cadf6f46d172ba4c
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: NameContainer.cxx,v $
10 * $Revision: 1.4 $
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_chart2.hxx"
34 #include "NameContainer.hxx"
37 //SvXMLUnitConverter
38 #include <xmloff/xmluconv.hxx>
40 #include <com/sun/star/uno/Any.hxx>
42 using namespace ::com::sun::star;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::Any;
45 using ::rtl::OUString;
48 //.............................................................................
49 namespace chart
51 //.............................................................................
53 uno::Reference< container::XNameContainer > createNameContainer(
54 const ::com::sun::star::uno::Type& rType, const rtl::OUString& rServicename, const rtl::OUString& rImplementationName )
56 return new NameContainer( rType, rServicename, rImplementationName );
59 NameContainer::NameContainer( const ::com::sun::star::uno::Type& rType, const OUString& rServicename, const OUString& rImplementationName )
60 : m_aType( rType )
61 , m_aServicename( rServicename )
62 , m_aImplementationName( rImplementationName )
63 , m_aMap()
67 NameContainer::NameContainer(
68 const NameContainer & rOther )
69 : impl::NameContainer_Base()
70 , m_aType( rOther.m_aType )
71 , m_aServicename( rOther.m_aServicename )
72 , m_aImplementationName( rOther.m_aImplementationName )
73 , m_aMap( rOther.m_aMap )
77 NameContainer::~NameContainer()
81 //XServiceInfo
82 OUString SAL_CALL NameContainer::getImplementationName()
83 throw( ::com::sun::star::uno::RuntimeException )
85 return m_aImplementationName;
88 sal_Bool SAL_CALL NameContainer::supportsService( const OUString& ServiceName )
89 throw( ::com::sun::star::uno::RuntimeException )
91 Sequence< OUString > aSNL = getSupportedServiceNames();
92 const OUString* pArray = aSNL.getArray();
93 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
95 if( pArray[ i ] == ServiceName )
96 return sal_True;
98 return sal_False;
101 Sequence< OUString > SAL_CALL NameContainer::getSupportedServiceNames()
102 throw( ::com::sun::star::uno::RuntimeException )
104 Sequence< OUString > aSNS( 1 );
105 aSNS.getArray()[ 0 ] = m_aServicename;
106 return aSNS;
109 //-----------------------------------------------------------------
110 //-----------------------------------------------------------------
111 //-----------------------------------------------------------------
113 // XNameContainer
114 void SAL_CALL NameContainer::insertByName( const OUString& rName, const Any& rElement )
115 throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
117 if( m_aMap.find( rName ) != m_aMap.end() )
118 throw container::ElementExistException();
119 m_aMap.insert( tContentMap::value_type( rName, rElement ));
124 void SAL_CALL NameContainer::removeByName( const OUString& Name )
125 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
127 tContentMap::iterator aIt( m_aMap.find( Name ));
128 if( aIt == m_aMap.end())
129 throw container::NoSuchElementException();
130 m_aMap.erase( aIt );
133 // XNameReplace
134 void SAL_CALL NameContainer::replaceByName( const OUString& rName, const Any& rElement )
135 throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
137 tContentMap::iterator aIt( m_aMap.find( rName ));
138 if( aIt == m_aMap.end() )
139 throw container::NoSuchElementException();
140 aIt->second = rElement;
143 // XNameAccess
144 Any SAL_CALL NameContainer::getByName( const OUString& rName )
145 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
147 tContentMap::iterator aIter( m_aMap.find( rName ) );
148 if( aIter == m_aMap.end() )
149 throw container::NoSuchElementException();
150 return aIter->second;
153 Sequence< OUString > SAL_CALL NameContainer::getElementNames()
154 throw( uno::RuntimeException )
156 sal_Int32 nCount = m_aMap.size();
157 Sequence< OUString > aSeq(nCount);
158 sal_Int32 nN = 0;
159 for( tContentMap::iterator aIter = m_aMap.begin(); aIter != m_aMap.end(), nN < nCount; aIter++, nN++ )
160 aSeq[nN]=aIter->first;
161 return aSeq;
164 sal_Bool SAL_CALL NameContainer::hasByName( const OUString& rName )
165 throw( uno::RuntimeException )
167 return ( m_aMap.find( rName ) != m_aMap.end() );
170 // XElementAccess
171 sal_Bool SAL_CALL NameContainer::hasElements()
172 throw( uno::RuntimeException )
174 return ! m_aMap.empty();
177 uno::Type SAL_CALL NameContainer::getElementType()
178 throw( uno::RuntimeException )
180 return m_aType;
183 // XCloneable
184 uno::Reference< util::XCloneable > SAL_CALL NameContainer::createClone()
185 throw ( uno::RuntimeException )
187 return uno::Reference< util::XCloneable >( new NameContainer( *this ));
190 //.............................................................................
191 } //namespace chart
192 //.............................................................................