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_charttools.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 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 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 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 70 NameContainer::~NameContainer() 71 { 72 } 73 74 //XServiceInfo 75 OUString SAL_CALL NameContainer::getImplementationName() 76 { 77 return m_aImplementationName; 78 } 79 80 sal_Bool SAL_CALL NameContainer::supportsService( const OUString& ServiceName ) 81 { 82 Sequence< OUString > aSNL = getSupportedServiceNames(); 83 const OUString* pArray = aSNL.getArray(); 84 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 85 { 86 if( pArray[ i ] == ServiceName ) 87 return sal_True; 88 } 89 return sal_False; 90 } 91 92 Sequence< OUString > SAL_CALL NameContainer::getSupportedServiceNames() 93 { 94 Sequence< OUString > aSNS( 1 ); 95 aSNS.getArray()[ 0 ] = m_aServicename; 96 return aSNS; 97 } 98 99 //----------------------------------------------------------------- 100 //----------------------------------------------------------------- 101 //----------------------------------------------------------------- 102 103 // XNameContainer 104 void SAL_CALL NameContainer::insertByName( const OUString& rName, const Any& rElement ) 105 { 106 if( m_aMap.find( rName ) != m_aMap.end() ) 107 throw container::ElementExistException(); 108 m_aMap.insert( tContentMap::value_type( rName, rElement )); 109 } 110 111 112 113 void SAL_CALL NameContainer::removeByName( const OUString& Name ) 114 { 115 tContentMap::iterator aIt( m_aMap.find( Name )); 116 if( aIt == m_aMap.end()) 117 throw container::NoSuchElementException(); 118 m_aMap.erase( aIt ); 119 } 120 121 // XNameReplace 122 void SAL_CALL NameContainer::replaceByName( const OUString& rName, const Any& rElement ) 123 { 124 tContentMap::iterator aIt( m_aMap.find( rName )); 125 if( aIt == m_aMap.end() ) 126 throw container::NoSuchElementException(); 127 aIt->second = rElement; 128 } 129 130 // XNameAccess 131 Any SAL_CALL NameContainer::getByName( const OUString& rName ) 132 { 133 tContentMap::iterator aIter( m_aMap.find( rName ) ); 134 if( aIter == m_aMap.end() ) 135 throw container::NoSuchElementException(); 136 return aIter->second; 137 } 138 139 Sequence< OUString > SAL_CALL NameContainer::getElementNames() 140 { 141 sal_Int32 nCount = m_aMap.size(); 142 Sequence< OUString > aSeq(nCount); 143 sal_Int32 nN = 0; 144 for( tContentMap::iterator aIter = m_aMap.begin(); aIter != m_aMap.end(), nN < nCount; aIter++, nN++ ) 145 aSeq[nN]=aIter->first; 146 return aSeq; 147 } 148 149 sal_Bool SAL_CALL NameContainer::hasByName( const OUString& rName ) 150 { 151 return ( m_aMap.find( rName ) != m_aMap.end() ); 152 } 153 154 // XElementAccess 155 sal_Bool SAL_CALL NameContainer::hasElements() 156 { 157 return ! m_aMap.empty(); 158 } 159 160 uno::Type SAL_CALL NameContainer::getElementType() 161 { 162 return m_aType; 163 } 164 165 // XCloneable 166 uno::Reference< util::XCloneable > SAL_CALL NameContainer::createClone() 167 { 168 return uno::Reference< util::XCloneable >( new NameContainer( *this )); 169 } 170 171 //............................................................................. 172 } //namespace chart 173 //............................................................................. 174