1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "NameContainer.hxx"
34 #include <xmloff/xmluconv.hxx>
36 #include <com/sun/star/uno/Any.hxx>
38 using namespace ::com::sun::star
;
39 using ::com::sun::star::uno::Sequence
;
40 using ::com::sun::star::uno::Any
;
41 using ::rtl::OUString
;
44 //.............................................................................
47 //.............................................................................
49 uno::Reference
< container::XNameContainer
> createNameContainer(
50 const ::com::sun::star::uno::Type
& rType
, const rtl::OUString
& rServicename
, const rtl::OUString
& rImplementationName
)
52 return new NameContainer( rType
, rServicename
, rImplementationName
);
55 NameContainer::NameContainer( const ::com::sun::star::uno::Type
& rType
, const OUString
& rServicename
, const OUString
& rImplementationName
)
57 , m_aServicename( rServicename
)
58 , m_aImplementationName( rImplementationName
)
63 NameContainer::NameContainer(
64 const NameContainer
& rOther
)
65 : impl::NameContainer_Base()
66 , m_aType( rOther
.m_aType
)
67 , m_aServicename( rOther
.m_aServicename
)
68 , m_aImplementationName( rOther
.m_aImplementationName
)
69 , m_aMap( rOther
.m_aMap
)
73 NameContainer::~NameContainer()
78 OUString SAL_CALL
NameContainer::getImplementationName()
79 throw( ::com::sun::star::uno::RuntimeException
)
81 return m_aImplementationName
;
84 sal_Bool SAL_CALL
NameContainer::supportsService( const OUString
& ServiceName
)
85 throw( ::com::sun::star::uno::RuntimeException
)
87 Sequence
< OUString
> aSNL
= getSupportedServiceNames();
88 const OUString
* pArray
= aSNL
.getArray();
89 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
91 if( pArray
[ i
] == ServiceName
)
97 Sequence
< OUString
> SAL_CALL
NameContainer::getSupportedServiceNames()
98 throw( ::com::sun::star::uno::RuntimeException
)
100 Sequence
< OUString
> aSNS( 1 );
101 aSNS
.getArray()[ 0 ] = m_aServicename
;
105 //-----------------------------------------------------------------
106 //-----------------------------------------------------------------
107 //-----------------------------------------------------------------
110 void SAL_CALL
NameContainer::insertByName( const OUString
& rName
, const Any
& rElement
)
111 throw( lang::IllegalArgumentException
, container::ElementExistException
, lang::WrappedTargetException
, uno::RuntimeException
)
113 if( m_aMap
.find( rName
) != m_aMap
.end() )
114 throw container::ElementExistException();
115 m_aMap
.insert( tContentMap::value_type( rName
, rElement
));
120 void SAL_CALL
NameContainer::removeByName( const OUString
& Name
)
121 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
123 tContentMap::iterator
aIt( m_aMap
.find( Name
));
124 if( aIt
== m_aMap
.end())
125 throw container::NoSuchElementException();
130 void SAL_CALL
NameContainer::replaceByName( const OUString
& rName
, const Any
& rElement
)
131 throw( lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
133 tContentMap::iterator
aIt( m_aMap
.find( rName
));
134 if( aIt
== m_aMap
.end() )
135 throw container::NoSuchElementException();
136 aIt
->second
= rElement
;
140 Any SAL_CALL
NameContainer::getByName( const OUString
& rName
)
141 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
143 tContentMap::iterator
aIter( m_aMap
.find( rName
) );
144 if( aIter
== m_aMap
.end() )
145 throw container::NoSuchElementException();
146 return aIter
->second
;
149 Sequence
< OUString
> SAL_CALL
NameContainer::getElementNames()
150 throw( uno::RuntimeException
)
152 sal_Int32 nCount
= m_aMap
.size();
153 Sequence
< OUString
> aSeq(nCount
);
155 for( tContentMap::iterator aIter
= m_aMap
.begin(); aIter
!= m_aMap
.end() && nN
< nCount
; ++aIter
, ++nN
)
156 aSeq
[nN
]=aIter
->first
;
160 sal_Bool SAL_CALL
NameContainer::hasByName( const OUString
& rName
)
161 throw( uno::RuntimeException
)
163 return ( m_aMap
.find( rName
) != m_aMap
.end() );
167 sal_Bool SAL_CALL
NameContainer::hasElements()
168 throw( uno::RuntimeException
)
170 return ! m_aMap
.empty();
173 uno::Type SAL_CALL
NameContainer::getElementType()
174 throw( uno::RuntimeException
)
180 uno::Reference
< util::XCloneable
> SAL_CALL
NameContainer::createClone()
181 throw ( uno::RuntimeException
)
183 return uno::Reference
< util::XCloneable
>( new NameContainer( *this ));
186 //.............................................................................
188 //.............................................................................
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */