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 ************************************************************************/
29 #ifndef _CONNECTIVITY_ADO_COLLECTION_HXX_
30 #define _CONNECTIVITY_ADO_COLLECTION_HXX_
32 #include <cppuhelper/implbase3.hxx>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/container/XIndexAccess.hpp>
35 #include "ado/Awrapadox.hxx"
36 #include "ado/Aolevariant.hxx"
37 #include <com/sun/star/lang/XServiceInfo.hpp>
39 namespace connectivity
43 namespace starcontainer
= ::com::sun::star::container
;
44 namespace starlang
= ::com::sun::star::lang
;
45 namespace staruno
= ::com::sun::star::uno
;
46 namespace starbeans
= ::com::sun::star::beans
;
48 typedef ::cppu::WeakImplHelper3
< starcontainer::XNameAccess
,
49 starcontainer::XIndexAccess
,
50 starlang::XServiceInfo
> OCollectionBase
;
52 //************************************************************
54 //************************************************************
55 template <class T
,class SimT
,class OCl
> class OCollection
: public OCollectionBase
58 OCollection( const OCollection
& ); // never implemented
59 OCollection
& operator=( const OCollection
& ); // never implemented
62 vector
<OCl
*> m_aElements
;
63 ::cppu::OWeakObject
& m_rParent
;
64 ::osl::Mutex
& m_rMutex
; // mutex of the parent
69 OCollection(::cppu::OWeakObject
& _rParent
, ::osl::Mutex
& _rMutex
,T
* _pCollection
)
72 ,m_pCollection(_pCollection
)
74 m_pCollection
->AddRef();
79 m_pCollection
->Release();
82 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (staruno::RuntimeException
)
84 return ::rtl::OUString("com.sun.star.sdbcx.ACollection");
86 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& _rServiceName
) throw(staruno::RuntimeException
)
88 staruno::Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
89 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
90 for (sal_Int32 i
=0; i
<aSupported
.getLength(); ++i
, ++pSupported
)
91 if (pSupported
->equals(_rServiceName
))
96 virtual staruno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(staruno::RuntimeException
)
98 staruno::Sequence
< ::rtl::OUString
> aSupported(1);
99 aSupported
[0] = ::rtl::OUString("com.sun.star.sdbcx.Container");
103 // dispatch the refcounting to the parent
104 virtual void SAL_CALL
acquire() throw()
108 virtual void SAL_CALL
release() throw()
113 // ::com::sun::star::container::XElementAccess
114 virtual staruno::Type SAL_CALL
getElementType( ) throw(staruno::RuntimeException
)
116 return::getCppuType(static_cast< staruno::Reference
< starbeans::XPropertySet
>*>(NULL
));
119 virtual sal_Bool SAL_CALL
hasElements( ) throw(staruno::RuntimeException
)
121 ::osl::MutexGuard
aGuard(m_rMutex
);
122 return getCount() > 0;
125 // starcontainer::XIndexAccess
126 virtual sal_Int32 SAL_CALL
getCount( ) throw(staruno::RuntimeException
)
128 ::osl::MutexGuard
aGuard(m_rMutex
);
130 m_pCollection
->get_Count(&nCnt
);
134 virtual staruno::Any SAL_CALL
getByIndex( sal_Int32 Index
) throw(starlang::IndexOutOfBoundsException
, starlang::WrappedTargetException
, staruno::RuntimeException
)
136 ::osl::MutexGuard
aGuard(m_rMutex
);
137 if (Index
< 0 || Index
>= getCount())
138 throw starlang::IndexOutOfBoundsException();
140 m_pCollection
->get_Item(OLEVariant(Index
),&pCol
);
142 throw starlang::IndexOutOfBoundsException();
144 OCl
* pIndex
= new OCl(pCol
);
146 m_aElements
.push_back(pIndex
);
148 return staruno::makeAny( staruno::Reference
< starbeans::XPropertySet
>(pIndex
));
152 // starcontainer::XNameAccess
153 virtual staruno::Any SAL_CALL
getByName( const ::rtl::OUString
& aName
) throw(starcontainer::NoSuchElementException
, starlang::WrappedTargetException
, staruno::RuntimeException
)
155 ::osl::MutexGuard
aGuard(m_rMutex
);
158 m_pCollection
->get_Item(OLEVariant(aName
),&pCol
);
160 throw starlang::IndexOutOfBoundsException();
162 OCl
* pIndex
= new OCl(pCol
);
164 m_aElements
.push_back(pIndex
);
166 return staruno::makeAny( staruno::Reference
< starbeans::XPropertySet
>(pIndex
));
168 virtual staruno::Sequence
< ::rtl::OUString
> SAL_CALL
getElementNames( ) throw(staruno::RuntimeException
)
170 ::osl::MutexGuard
aGuard(m_rMutex
);
171 sal_Int32 nLen
= getCount();
172 staruno::Sequence
< ::rtl::OUString
> aNameList(nLen
);
174 ::rtl::OUString
* pStringArray
= aNameList
.getArray();
176 for (sal_Int32 i
=0;i
<nLen
;++i
)
180 m_pCollection
->get_Item(aVar
,&pIdx
);
183 pIdx
->get_Name(&sBSTR
);
184 (*pStringArray
) = (sal_Unicode
*)sBSTR
;
190 virtual sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
) throw(staruno::RuntimeException
)
192 ::osl::MutexGuard
aGuard(m_rMutex
);
194 m_pCollection
->get_Item(OLEVariant(aName
),&pCol
);
198 void SAL_CALL
disposing()
200 ::osl::MutexGuard
aGuard(m_rMutex
);
201 for (::std::vector
<OCl
*>::const_iterator i
= m_aElements
.begin(); i
!= m_aElements
.end(); ++i
)
219 typedef OCollection
< ADOIndexes
,ADOIndex
,OIndex
> OIndexes
;
220 typedef OCollection
< ADOKeys
,ADOKey
,OKey
> OKeys
;
221 typedef OCollection
< ADOColumns
,ADOColumn
,OColumn
> OColumns
;
222 typedef OCollection
< ADOTables
,ADOTable
,OTable
> OTables
;
223 typedef OCollection
< ADOViews
,ADOView
,OView
> OViews
;
224 typedef OCollection
< ADOGroups
,ADOGroup
,OGroup
> OGroups
;
225 typedef OCollection
< ADOUsers
,ADOUser
,OUser
> OUsers
;
229 #endif // _CONNECTIVITY_ADO_COLLECTION_HXX_
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */