masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / options / sdbcdriverenum.cxx
blob0408c5ecabe372fa9b3c35ddacb214eb63a076d0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 #include "sdbcdriverenum.hxx"
31 #include <comphelper/stl_types.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/container/XEnumerationAccess.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
37 //........................................................................
38 namespace offapp
40 //........................................................................
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::container;
46 //====================================================================
47 //= ODriverEnumerationImpl
48 //====================================================================
49 class ODriverEnumerationImpl
51 protected:
52 ::std::vector< ::rtl::OUString > m_aImplNames;
54 public:
55 ODriverEnumerationImpl();
57 const ::std::vector< ::rtl::OUString >& getDriverImplNames() const { return m_aImplNames; }
60 //--------------------------------------------------------------------
61 ODriverEnumerationImpl::ODriverEnumerationImpl()
63 try
65 Reference< XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
66 Reference< XInterface > xDM = xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdbc.DriverManager"));
67 OSL_ENSURE(xDM.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: no access to the SDBC driver manager!");
69 Reference< XEnumerationAccess > xEnumAccess(xDM, UNO_QUERY);
70 OSL_ENSURE(xEnumAccess.is() || !xDM.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: can't enumerate SDBC drivers (missing the interface)!");
71 if (xEnumAccess.is())
73 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createEnumeration();
74 OSL_ENSURE(xEnumDrivers.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
76 Reference< XServiceInfo > xDriverSI;
77 while (xEnumDrivers->hasMoreElements())
79 xEnumDrivers->nextElement() >>= xDriverSI;
80 OSL_ENSURE(xDriverSI.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
81 if (xDriverSI.is())
82 m_aImplNames.push_back(xDriverSI->getImplementationName());
86 catch(const Exception&)
88 OSL_ENSURE(sal_False, "ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
92 //====================================================================
93 //= ODriverEnumeration
94 //====================================================================
95 //--------------------------------------------------------------------
96 ODriverEnumeration::ODriverEnumeration() throw()
97 :m_pImpl(new ODriverEnumerationImpl)
101 //--------------------------------------------------------------------
102 ODriverEnumeration::~ODriverEnumeration() throw()
104 delete m_pImpl;
107 //--------------------------------------------------------------------
108 ODriverEnumeration::const_iterator ODriverEnumeration::begin() const throw()
110 return m_pImpl->getDriverImplNames().begin();
113 //--------------------------------------------------------------------
114 ODriverEnumeration::const_iterator ODriverEnumeration::end() const throw()
116 return m_pImpl->getDriverImplNames().end();
118 //........................................................................
119 } // namespace offapp
120 //........................................................................