1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ACollection.hxx,v $
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 #ifndef _CONNECTIVITY_ADO_COLLECTION_HXX_
32 #define _CONNECTIVITY_ADO_COLLECTION_HXX_
34 #include <cppuhelper/implbase3.hxx>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/container/XIndexAccess.hpp>
37 #include "ado/Awrapadox.hxx"
38 #include "ado/Aolevariant.hxx"
39 #include <com/sun/star/lang/XServiceInfo.hpp>
41 namespace connectivity
45 namespace starcontainer
= ::com::sun::star::container
;
46 namespace starlang
= ::com::sun::star::lang
;
47 namespace staruno
= ::com::sun::star::uno
;
48 namespace starbeans
= ::com::sun::star::beans
;
50 typedef ::cppu::WeakImplHelper3
< starcontainer::XNameAccess
,
51 starcontainer::XIndexAccess
,
52 starlang::XServiceInfo
> OCollectionBase
;
54 //************************************************************
56 //************************************************************
57 template <class T
,class SimT
,class OCl
> class OCollection
: public OCollectionBase
60 OCollection( const OCollection
& ); // never implemented
61 OCollection
& operator=( const OCollection
& ); // never implemented
64 vector
<OCl
*> m_aElements
;
65 ::cppu::OWeakObject
& m_rParent
;
66 ::osl::Mutex
& m_rMutex
; // mutex of the parent
71 OCollection(::cppu::OWeakObject
& _rParent
, ::osl::Mutex
& _rMutex
,T
* _pCollection
)
74 ,m_pCollection(_pCollection
)
76 m_pCollection
->AddRef();
81 m_pCollection
->Release();
84 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (staruno::RuntimeException
)
86 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ACollection");
88 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& _rServiceName
) throw(staruno::RuntimeException
)
90 staruno::Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
91 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
92 for (sal_Int32 i
=0; i
<aSupported
.getLength(); ++i
, ++pSupported
)
93 if (pSupported
->equals(_rServiceName
))
98 virtual staruno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(staruno::RuntimeException
)
100 staruno::Sequence
< ::rtl::OUString
> aSupported(1);
101 aSupported
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Container");
105 // dispatch the refcounting to the parent
106 virtual void SAL_CALL
acquire() throw()
110 virtual void SAL_CALL
release() throw()
115 // ::com::sun::star::container::XElementAccess
116 virtual staruno::Type SAL_CALL
getElementType( ) throw(staruno::RuntimeException
)
118 return::getCppuType(static_cast< staruno::Reference
< starbeans::XPropertySet
>*>(NULL
));
121 virtual sal_Bool SAL_CALL
hasElements( ) throw(staruno::RuntimeException
)
123 ::osl::MutexGuard
aGuard(m_rMutex
);
124 return getCount() > 0;
127 // starcontainer::XIndexAccess
128 virtual sal_Int32 SAL_CALL
getCount( ) throw(staruno::RuntimeException
)
130 ::osl::MutexGuard
aGuard(m_rMutex
);
132 m_pCollection
->get_Count(&nCnt
);
136 virtual staruno::Any SAL_CALL
getByIndex( sal_Int32 Index
) throw(starlang::IndexOutOfBoundsException
, starlang::WrappedTargetException
, staruno::RuntimeException
)
138 ::osl::MutexGuard
aGuard(m_rMutex
);
139 if (Index
< 0 || Index
>= getCount())
140 throw starlang::IndexOutOfBoundsException();
142 m_pCollection
->get_Item(OLEVariant(Index
),&pCol
);
144 throw starlang::IndexOutOfBoundsException();
146 OCl
* pIndex
= new OCl(pCol
);
148 m_aElements
.push_back(pIndex
);
150 return staruno::makeAny( staruno::Reference
< starbeans::XPropertySet
>(pIndex
));
154 // starcontainer::XNameAccess
155 virtual staruno::Any SAL_CALL
getByName( const ::rtl::OUString
& aName
) throw(starcontainer::NoSuchElementException
, starlang::WrappedTargetException
, staruno::RuntimeException
)
157 ::osl::MutexGuard
aGuard(m_rMutex
);
160 m_pCollection
->get_Item(OLEVariant(aName
),&pCol
);
162 throw starlang::IndexOutOfBoundsException();
164 OCl
* pIndex
= new OCl(pCol
);
166 m_aElements
.push_back(pIndex
);
168 return staruno::makeAny( staruno::Reference
< starbeans::XPropertySet
>(pIndex
));
170 virtual staruno::Sequence
< ::rtl::OUString
> SAL_CALL
getElementNames( ) throw(staruno::RuntimeException
)
172 ::osl::MutexGuard
aGuard(m_rMutex
);
173 sal_Int32 nLen
= getCount();
174 staruno::Sequence
< ::rtl::OUString
> aNameList(nLen
);
176 ::rtl::OUString
* pStringArray
= aNameList
.getArray();
178 for (sal_Int32 i
=0;i
<nLen
;++i
)
182 m_pCollection
->get_Item(aVar
,&pIdx
);
185 pIdx
->get_Name(&sBSTR
);
186 (*pStringArray
) = (sal_Unicode
*)sBSTR
;
192 virtual sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
) throw(staruno::RuntimeException
)
194 ::osl::MutexGuard
aGuard(m_rMutex
);
196 m_pCollection
->get_Item(OLEVariant(aName
),&pCol
);
200 void SAL_CALL
disposing()
202 ::osl::MutexGuard
aGuard(m_rMutex
);
203 for (::std::vector
<OCl
*>::const_iterator i
= m_aElements
.begin(); i
!= m_aElements
.end(); ++i
)
221 typedef OCollection
< ADOIndexes
,ADOIndex
,OIndex
> OIndexes
;
222 typedef OCollection
< ADOKeys
,ADOKey
,OKey
> OKeys
;
223 typedef OCollection
< ADOColumns
,ADOColumn
,OColumn
> OColumns
;
224 typedef OCollection
< ADOTables
,ADOTable
,OTable
> OTables
;
225 typedef OCollection
< ADOViews
,ADOView
,OView
> OViews
;
226 typedef OCollection
< ADOGroups
,ADOGroup
,OGroup
> OGroups
;
227 typedef OCollection
< ADOUsers
,ADOUser
,OUser
> OUsers
;
231 #endif // _CONNECTIVITY_ADO_COLLECTION_HXX_