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: sdbcdriverenum.cxx,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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include "sdbcdriverenum.hxx"
38 #include <comphelper/stl_types.hxx>
39 #include <comphelper/processfactory.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/container/XEnumerationAccess.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
44 //........................................................................
47 //........................................................................
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::container
;
53 //====================================================================
54 //= ODriverEnumerationImpl
55 //====================================================================
56 class ODriverEnumerationImpl
59 ::std::vector
< ::rtl::OUString
> m_aImplNames
;
62 ODriverEnumerationImpl();
64 const ::std::vector
< ::rtl::OUString
>& getDriverImplNames() const { return m_aImplNames
; }
67 //--------------------------------------------------------------------
68 ODriverEnumerationImpl::ODriverEnumerationImpl()
72 Reference
< XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
73 Reference
< XInterface
> xDM
= xORB
->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdbc.DriverManager"));
74 OSL_ENSURE(xDM
.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: no access to the SDBC driver manager!");
76 Reference
< XEnumerationAccess
> xEnumAccess(xDM
, UNO_QUERY
);
77 OSL_ENSURE(xEnumAccess
.is() || !xDM
.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: can't enumerate SDBC drivers (missing the interface)!");
80 Reference
< XEnumeration
> xEnumDrivers
= xEnumAccess
->createEnumeration();
81 OSL_ENSURE(xEnumDrivers
.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
83 Reference
< XServiceInfo
> xDriverSI
;
84 while (xEnumDrivers
->hasMoreElements())
86 xEnumDrivers
->nextElement() >>= xDriverSI
;
87 OSL_ENSURE(xDriverSI
.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
89 m_aImplNames
.push_back(xDriverSI
->getImplementationName());
93 catch(const Exception
&)
95 OSL_ENSURE(sal_False
, "ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
99 //====================================================================
100 //= ODriverEnumeration
101 //====================================================================
102 //--------------------------------------------------------------------
103 ODriverEnumeration::ODriverEnumeration() throw()
104 :m_pImpl(new ODriverEnumerationImpl
)
108 //--------------------------------------------------------------------
109 ODriverEnumeration::~ODriverEnumeration() throw()
114 //--------------------------------------------------------------------
115 ODriverEnumeration::const_iterator
ODriverEnumeration::begin() const throw()
117 return m_pImpl
->getDriverImplNames().begin();
120 //--------------------------------------------------------------------
121 ODriverEnumeration::const_iterator
ODriverEnumeration::end() const throw()
123 return m_pImpl
->getDriverImplNames().end();
126 //--------------------------------------------------------------------
127 sal_Int32
ODriverEnumeration::size() const throw()
129 return m_pImpl
->getDriverImplNames().size();
132 //........................................................................
133 } // namespace offapp
134 //........................................................................