Bump version to 4.3-4
[LibreOffice.git] / cui / source / options / sdbcdriverenum.cxx
blobcac802cbfe447d68cbde09e6f6acdfc34fc59a38
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sdbcdriverenum.hxx"
21 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/container/XEnumerationAccess.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/sdbc/DriverManager.hpp>
27 namespace offapp
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::sdbc;
37 //= ODriverEnumerationImpl
39 class ODriverEnumerationImpl
41 protected:
42 ::std::vector< OUString > m_aImplNames;
44 public:
45 ODriverEnumerationImpl();
47 const ::std::vector< OUString >& getDriverImplNames() const { return m_aImplNames; }
51 ODriverEnumerationImpl::ODriverEnumerationImpl()
53 try
55 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
56 Reference< XDriverManager2 > xEnumAccess = DriverManager::create( xContext );
58 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createEnumeration();
59 OSL_ENSURE(xEnumDrivers.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
61 Reference< XServiceInfo > xDriverSI;
62 while (xEnumDrivers->hasMoreElements())
64 xEnumDrivers->nextElement() >>= xDriverSI;
65 OSL_ENSURE(xDriverSI.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
66 if (xDriverSI.is())
67 m_aImplNames.push_back(xDriverSI->getImplementationName());
70 catch(const Exception&)
72 OSL_FAIL("ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
77 //= ODriverEnumeration
80 ODriverEnumeration::ODriverEnumeration() throw()
81 :m_pImpl(new ODriverEnumerationImpl)
86 ODriverEnumeration::~ODriverEnumeration() throw()
88 delete m_pImpl;
92 ODriverEnumeration::const_iterator ODriverEnumeration::begin() const throw()
94 return m_pImpl->getDriverImplNames().begin();
98 ODriverEnumeration::const_iterator ODriverEnumeration::end() const throw()
100 return m_pImpl->getDriverImplNames().end();
103 } // namespace offapp
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */