Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / options / sdbcdriverenum.cxx
blob0ddd7f8f9f0885a3cc7397563b15a711d26871fa
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 <osl/diagnose.h>
23 #include <comphelper/diagnose_ex.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
28 namespace offapp
32 using namespace css::uno;
33 using namespace css::lang;
34 using namespace css::container;
35 using namespace css::sdbc;
37 class ODriverEnumerationImpl
39 protected:
40 std::vector< OUString > m_aImplNames;
42 public:
43 ODriverEnumerationImpl();
45 const std::vector< OUString >& getDriverImplNames() const { return m_aImplNames; }
49 ODriverEnumerationImpl::ODriverEnumerationImpl()
51 try
53 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
54 Reference< XDriverManager2 > xEnumAccess = DriverManager::create( xContext );
56 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createEnumeration();
57 OSL_ENSURE(xEnumDrivers.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
59 Reference< XServiceInfo > xDriverSI;
60 while (xEnumDrivers->hasMoreElements())
62 xEnumDrivers->nextElement() >>= xDriverSI;
63 OSL_ENSURE(xDriverSI.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
64 if (xDriverSI.is())
65 m_aImplNames.push_back(xDriverSI->getImplementationName());
68 catch(const Exception&)
70 TOOLS_WARN_EXCEPTION( "cui.options", "ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
74 ODriverEnumeration::ODriverEnumeration() noexcept
75 :m_pImpl(new ODriverEnumerationImpl)
80 ODriverEnumeration::~ODriverEnumeration() noexcept
85 ODriverEnumeration::const_iterator ODriverEnumeration::begin() const noexcept
87 return m_pImpl->getDriverImplNames().begin();
91 ODriverEnumeration::const_iterator ODriverEnumeration::end() const noexcept
93 return m_pImpl->getDriverImplNames().end();
96 } // namespace offapp
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */