1*d0626817SAndrew Rist /**************************************************************
2*d0626817SAndrew Rist  *
3*d0626817SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d0626817SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d0626817SAndrew Rist  * distributed with this work for additional information
6*d0626817SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d0626817SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d0626817SAndrew Rist  * "License"); you may not use this file except in compliance
9*d0626817SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d0626817SAndrew Rist  *
11*d0626817SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d0626817SAndrew Rist  *
13*d0626817SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d0626817SAndrew Rist  * software distributed under the License is distributed on an
15*d0626817SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d0626817SAndrew Rist  * KIND, either express or implied.  See the License for the
17*d0626817SAndrew Rist  * specific language governing permissions and limitations
18*d0626817SAndrew Rist  * under the License.
19*d0626817SAndrew Rist  *
20*d0626817SAndrew Rist  *************************************************************/
21*d0626817SAndrew Rist 
22*d0626817SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <vbahelper/collectionbase.hxx>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <map>
27cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
28cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
29cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace vbahelper {
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir using namespace ::ooo::vba;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // ============================================================================
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // ----------------------------------------------------------------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class CollectionEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration >
43cdf0e10cSrcweir {
44cdf0e10cSrcweir public:
45cdf0e10cSrcweir     explicit CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection );
46cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException);
47cdf0e10cSrcweir     virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
48cdf0e10cSrcweir 
49cdf0e10cSrcweir private:
50cdf0e10cSrcweir     ::rtl::Reference< CollectionBase > mxCollection;
51cdf0e10cSrcweir     sal_Int32 mnCurrIndex;
52cdf0e10cSrcweir };
53cdf0e10cSrcweir 
CollectionEnumeration(const::rtl::Reference<CollectionBase> & rxCollection)54cdf0e10cSrcweir CollectionEnumeration::CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ) :
55cdf0e10cSrcweir     mxCollection( rxCollection ),
56cdf0e10cSrcweir     mnCurrIndex( 1 )    // collection expects one-based indexes
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
hasMoreElements()60cdf0e10cSrcweir sal_Bool SAL_CALL CollectionEnumeration::hasMoreElements() throw (uno::RuntimeException)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     return mnCurrIndex <= mxCollection->getCount();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
nextElement()65cdf0e10cSrcweir uno::Any SAL_CALL CollectionEnumeration::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     if( hasMoreElements() )
68cdf0e10cSrcweir         return mxCollection->getItemByIndex( mnCurrIndex++ );
69cdf0e10cSrcweir     throw container::NoSuchElementException();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ----------------------------------------------------------------------------
73cdf0e10cSrcweir 
74cdf0e10cSrcweir struct IsLessIgnoreCase
75cdf0e10cSrcweir {
operator ()vbahelper::__anonc8aca98e0111::IsLessIgnoreCase76cdf0e10cSrcweir     inline bool operator()( const ::rtl::OUString& rName1, const ::rtl::OUString& rName2 ) const
77cdf0e10cSrcweir         { return ::rtl_ustr_compareIgnoreAsciiCase_WithLength( rName1.getStr(), rName1.getLength(), rName2.getStr(), rName2.getLength() ) < 0; }
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // ----------------------------------------------------------------------------
81cdf0e10cSrcweir 
82cdf0e10cSrcweir class SequenceToContainer : public ::cppu::WeakImplHelper2< container::XIndexAccess, container::XNameAccess >
83cdf0e10cSrcweir {
84cdf0e10cSrcweir public:
85cdf0e10cSrcweir     explicit SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType );
86cdf0e10cSrcweir     explicit SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType );
87cdf0e10cSrcweir     // XIndexAccess
88cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException);
89cdf0e10cSrcweir     virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException);
90cdf0e10cSrcweir     // XNameAccess
91cdf0e10cSrcweir     virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
92cdf0e10cSrcweir     virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (uno::RuntimeException);
93cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException);
94cdf0e10cSrcweir     // XElementAccess
95cdf0e10cSrcweir     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException);
96cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir private:
99cdf0e10cSrcweir     typedef uno::Sequence< ::rtl::OUString > ElementNameSequence;
100cdf0e10cSrcweir     typedef ::std::vector< uno::Any > ElementVector;
101cdf0e10cSrcweir     typedef ::std::map< ::rtl::OUString, uno::Any, IsLessIgnoreCase > ElementMap;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     ElementNameSequence maElementNames;
104cdf0e10cSrcweir     ElementVector maElements;
105cdf0e10cSrcweir     ElementMap maElementMap;
106cdf0e10cSrcweir     uno::Type maElementType;
107cdf0e10cSrcweir };
108cdf0e10cSrcweir 
SequenceToContainer(const::std::vector<uno::Reference<container::XNamed>> & rElements,const uno::Type & rElementType)109cdf0e10cSrcweir SequenceToContainer::SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ) :
110cdf0e10cSrcweir     maElementType( rElementType )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) );
113cdf0e10cSrcweir     maElements.reserve( rElements.size() );
114cdf0e10cSrcweir     ::rtl::OUString* pElementName = maElementNames.getArray();
115cdf0e10cSrcweir     for( ::std::vector< uno::Reference< container::XNamed > >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName )
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         uno::Reference< container::XNamed > xNamed = *aIt;
118cdf0e10cSrcweir         *pElementName = xNamed->getName();
119cdf0e10cSrcweir         maElements.push_back( uno::Any( xNamed ) );
120cdf0e10cSrcweir         // same name may occur multiple times, VBA returns first occurance
121cdf0e10cSrcweir         if( maElementMap.count( *pElementName ) == 0 )
122cdf0e10cSrcweir             maElementMap[ *pElementName ] <<= xNamed;
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
SequenceToContainer(const::std::vector<beans::NamedValue> & rElements,const uno::Type & rElementType)126cdf0e10cSrcweir SequenceToContainer::SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ) :
127cdf0e10cSrcweir     maElementType( rElementType )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) );
130cdf0e10cSrcweir     maElements.reserve( rElements.size() );
131cdf0e10cSrcweir     ::rtl::OUString* pElementName = maElementNames.getArray();
132cdf0e10cSrcweir     for( ::std::vector< beans::NamedValue >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName )
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         *pElementName = aIt->Name;
135cdf0e10cSrcweir         maElements.push_back( aIt->Value );
136cdf0e10cSrcweir         // same name may occur multiple times, VBA returns first occurance
137cdf0e10cSrcweir         if( maElementMap.count( *pElementName ) == 0 )
138cdf0e10cSrcweir             maElementMap[ *pElementName ] = aIt->Value;
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
getCount()142cdf0e10cSrcweir sal_Int32 SAL_CALL SequenceToContainer::getCount() throw (uno::RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     return static_cast< sal_Int32 >( maElements.size() );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)147cdf0e10cSrcweir uno::Any SAL_CALL SequenceToContainer::getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     if( (0 <= nIndex) && (nIndex < getCount()) )
150cdf0e10cSrcweir         return maElements[ static_cast< size_t >( nIndex ) ];
151cdf0e10cSrcweir     throw lang::IndexOutOfBoundsException();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
getByName(const::rtl::OUString & rName)154cdf0e10cSrcweir uno::Any SAL_CALL SequenceToContainer::getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     ElementMap::iterator aIt = maElementMap.find( rName );
157cdf0e10cSrcweir     if( aIt != maElementMap.end() )
158cdf0e10cSrcweir         return aIt->second;
159cdf0e10cSrcweir     throw container::NoSuchElementException();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
getElementNames()162cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL SequenceToContainer::getElementNames() throw (uno::RuntimeException)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     return maElementNames;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
hasByName(const::rtl::OUString & rName)167cdf0e10cSrcweir sal_Bool SAL_CALL SequenceToContainer::hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     return maElementMap.count( rName ) > 0;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
getElementType()172cdf0e10cSrcweir uno::Type SAL_CALL SequenceToContainer::getElementType() throw (uno::RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     return maElementType;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
hasElements()177cdf0e10cSrcweir sal_Bool SAL_CALL SequenceToContainer::hasElements() throw (uno::RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     return !maElements.empty();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir } // namespace
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // ============================================================================
185cdf0e10cSrcweir 
CollectionBase(const uno::Type & rElementType)186cdf0e10cSrcweir CollectionBase::CollectionBase( const uno::Type& rElementType ) :
187cdf0e10cSrcweir     maElementType( rElementType ),
188cdf0e10cSrcweir     mbConvertOnDemand( false )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
getCount()192cdf0e10cSrcweir sal_Int32 SAL_CALL CollectionBase::getCount() throw (uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     if( mxIndexAccess.is() )
195cdf0e10cSrcweir         return mxIndexAccess->getCount();
196cdf0e10cSrcweir     if( mxNameAccess.is() )
197cdf0e10cSrcweir         return mxNameAccess->getElementNames().getLength();
198cdf0e10cSrcweir     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
createEnumeration()201cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL CollectionBase::createEnumeration() throw (uno::RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     return new CollectionEnumeration( this );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
getElementType()206cdf0e10cSrcweir uno::Type SAL_CALL CollectionBase::getElementType() throw (uno::RuntimeException)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     return maElementType;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
hasElements()211cdf0e10cSrcweir sal_Bool SAL_CALL CollectionBase::hasElements() throw (uno::RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     if( mxIndexAccess.is() )
214cdf0e10cSrcweir         return mxIndexAccess->hasElements();
215cdf0e10cSrcweir     if( mxNameAccess.is() )
216cdf0e10cSrcweir         return mxNameAccess->hasElements();
217cdf0e10cSrcweir     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
getDefaultMethodName()220cdf0e10cSrcweir ::rtl::OUString SAL_CALL CollectionBase::getDefaultMethodName() throw (uno::RuntimeException)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     static ::rtl::OUString saDefMethodName( RTL_CONSTASCII_USTRINGPARAM( "Item" ) );
223cdf0e10cSrcweir     return saDefMethodName;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir // ----------------------------------------------------------------------------
227cdf0e10cSrcweir 
initContainer(const uno::Reference<container::XElementAccess> & rxElementAccess,ContainerType eContainerType)228cdf0e10cSrcweir void CollectionBase::initContainer(
229cdf0e10cSrcweir         const uno::Reference< container::XElementAccess >& rxElementAccess,
230cdf0e10cSrcweir         ContainerType eContainerType ) throw (uno::RuntimeException)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     mxIndexAccess.set( rxElementAccess, uno::UNO_QUERY );
233cdf0e10cSrcweir     mxNameAccess.set( rxElementAccess, uno::UNO_QUERY );
234cdf0e10cSrcweir     switch( eContainerType )
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         case CONTAINER_NATIVE_VBA:
237cdf0e10cSrcweir             mbConvertOnDemand = false;
238cdf0e10cSrcweir         break;
239cdf0e10cSrcweir         case CONTAINER_CONVERT_ON_DEMAND:
240cdf0e10cSrcweir             mbConvertOnDemand = true;
241cdf0e10cSrcweir         break;
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
initElements(const::std::vector<uno::Reference<container::XNamed>> & rElements,ContainerType eContainerType)245cdf0e10cSrcweir void CollectionBase::initElements( const ::std::vector< uno::Reference< container::XNamed > >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity
248cdf0e10cSrcweir     initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
initElements(const::std::vector<beans::NamedValue> & rElements,ContainerType eContainerType)251cdf0e10cSrcweir void CollectionBase::initElements( const ::std::vector< beans::NamedValue >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException)
252cdf0e10cSrcweir {
253cdf0e10cSrcweir     // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity
254cdf0e10cSrcweir     initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType );
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
createCollectionItem(const uno::Any & rElement,const uno::Any & rIndex)257cdf0e10cSrcweir uno::Any CollectionBase::createCollectionItem( const uno::Any& rElement, const uno::Any& rIndex ) throw (css::uno::RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     uno::Any aItem = mbConvertOnDemand ? implCreateCollectionItem( rElement, rIndex ) : rElement;
260cdf0e10cSrcweir     if( aItem.hasValue() )
261cdf0e10cSrcweir         return aItem;
262cdf0e10cSrcweir     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item." ) ), 0 );
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
getItemByIndex(sal_Int32 nIndex)265cdf0e10cSrcweir uno::Any CollectionBase::getItemByIndex( sal_Int32 nIndex ) throw (uno::RuntimeException)
266cdf0e10cSrcweir {
267cdf0e10cSrcweir     if( mxIndexAccess.is() )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         if( (1 <= nIndex) && (nIndex <= mxIndexAccess->getCount()) )
270cdf0e10cSrcweir             // createCollectionItem() will convert from container element to VBA item
271cdf0e10cSrcweir             return createCollectionItem( mxIndexAccess->getByIndex( nIndex - 1 ), uno::Any( nIndex ) );
272cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 );
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir     if( mxNameAccess.is() )
275cdf0e10cSrcweir     {
276cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aElementNames = mxNameAccess->getElementNames();
277cdf0e10cSrcweir         if( (1 <= nIndex) && (nIndex <= aElementNames.getLength()) )
278cdf0e10cSrcweir             // createCollectionItem() will convert from container element to VBA item
279cdf0e10cSrcweir             return createCollectionItem( mxNameAccess->getByName( aElementNames[ nIndex - 1 ] ), uno::Any( aElementNames[ nIndex - 1 ] ) );
280cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 );
281cdf0e10cSrcweir     }
282cdf0e10cSrcweir     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
getItemByName(const::rtl::OUString & rName)285cdf0e10cSrcweir uno::Any CollectionBase::getItemByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     if( mxNameAccess.is() )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         if( rName.getLength() > 0 )
290cdf0e10cSrcweir             // createCollectionItem() will convert from container element to VBA item
291cdf0e10cSrcweir             return createCollectionItem( mxNameAccess->getByName( rName ), uno::Any( rName ) );
292cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 );
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir     if( mxIndexAccess.is() )
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         for( sal_Int32 nIndex = 0, nSize = mxIndexAccess->getCount(); nIndex < nSize; ++nIndex )
297cdf0e10cSrcweir         {
298cdf0e10cSrcweir             uno::Any aElement = mxIndexAccess->getByIndex( nIndex );
299cdf0e10cSrcweir             uno::Reference< container::XNamed > xNamed( aElement, uno::UNO_QUERY );
300cdf0e10cSrcweir             if( xNamed.is() && xNamed->getName().equalsIgnoreAsciiCase( rName ) )
301cdf0e10cSrcweir                 // createCollectionItem() will convert from container element to VBA item
302cdf0e10cSrcweir                 return createCollectionItem( aElement, uno::Any( nIndex ) );
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 );
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
getAnyItemOrThis(const uno::Any & rIndex)309cdf0e10cSrcweir uno::Any CollectionBase::getAnyItemOrThis( const uno::Any& rIndex ) throw (uno::RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     if( !rIndex.hasValue() )
312cdf0e10cSrcweir         return uno::Any( uno::Reference< XCollectionBase >( this ) );
313cdf0e10cSrcweir     if( rIndex.has< ::rtl::OUString >() )
314cdf0e10cSrcweir         return getItemByName( rIndex.get< ::rtl::OUString >() );
315cdf0e10cSrcweir     // extractIntFromAny() throws if no index can be extracted
316cdf0e10cSrcweir     return getItemByIndex( extractIntFromAny( rIndex ) );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir // protected ------------------------------------------------------------------
320cdf0e10cSrcweir 
implCreateCollectionItem(const uno::Any &,const uno::Any &)321cdf0e10cSrcweir uno::Any CollectionBase::implCreateCollectionItem( const uno::Any& /*rElement*/, const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Creation of VBA implementation object not implemented." ) ), 0 );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir // ============================================================================
327cdf0e10cSrcweir 
328cdf0e10cSrcweir } // namespace vbahelper
329