merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / sdbcdriverenum.cxx
blob1fc0335ed30a8ea24b6f085792a675da3ce3d3bc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdbcdriverenum.cxx,v $
10 * $Revision: 1.6 $
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
36 #endif
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 //........................................................................
45 namespace offapp
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
58 protected:
59 ::std::vector< ::rtl::OUString > m_aImplNames;
61 public:
62 ODriverEnumerationImpl();
64 const ::std::vector< ::rtl::OUString >& getDriverImplNames() const { return m_aImplNames; }
67 //--------------------------------------------------------------------
68 ODriverEnumerationImpl::ODriverEnumerationImpl()
70 try
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)!");
78 if (xEnumAccess.is())
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!");
88 if (xDriverSI.is())
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()
111 delete m_pImpl;
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 //........................................................................