LibreOffice Module cui (master) 1
sdbcdriverenum.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "sdbcdriverenum.hxx"
22#include <osl/diagnose.h>
23#include <tools/diagnose_ex.h>
24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/sdbc/DriverManager.hpp>
26
27
28namespace offapp
29{
30
31
32 using namespace css::uno;
33 using namespace css::lang;
34 using namespace css::container;
35 using namespace css::sdbc;
36
38 {
39 protected:
40 std::vector< OUString > m_aImplNames;
41
42 public:
44
45 const std::vector< OUString >& getDriverImplNames() const { return m_aImplNames; }
46 };
47
48
50 {
51 try
52 {
53 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
54 Reference< XDriverManager2 > xEnumAccess = DriverManager::create( xContext );
55
56 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createEnumeration();
57 OSL_ENSURE(xEnumDrivers.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
58
59 Reference< XServiceInfo > xDriverSI;
60 while (xEnumDrivers->hasMoreElements())
61 {
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());
66 }
67 }
68 catch(const Exception&)
69 {
70 TOOLS_WARN_EXCEPTION( "cui.options", "ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
71 }
72 }
73
75 :m_pImpl(new ODriverEnumerationImpl)
76 {
77 }
78
79
81 {
82 }
83
84
86 {
87 return m_pImpl->getDriverImplNames().begin();
88 }
89
90
92 {
93 return m_pImpl->getDriverImplNames().end();
94 }
95
96} // namespace offapp
97
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const std::vector< OUString > & getDriverImplNames() const
std::vector< OUString > m_aImplNames
const_iterator end() const noexcept
std::unique_ptr< ODriverEnumerationImpl > m_pImpl
const_iterator begin() const noexcept
std::vector< OUString >::const_iterator const_iterator
#define TOOLS_WARN_EXCEPTION(area, stream)
@ Exception