bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / options / sdbcdriverenum.cxx
blobb32ccfca776749e7a1e72a4c17747d42d97bef0d
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 <com/sun/star/container/XEnumerationAccess.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
28 namespace offapp
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::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 OSL_FAIL("ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
74 ODriverEnumeration::ODriverEnumeration() throw()
75 :m_pImpl(new ODriverEnumerationImpl)
80 ODriverEnumeration::~ODriverEnumeration() throw()
82 delete m_pImpl;
86 ODriverEnumeration::const_iterator ODriverEnumeration::begin() const throw()
88 return m_pImpl->getDriverImplNames().begin();
92 ODriverEnumeration::const_iterator ODriverEnumeration::end() const throw()
94 return m_pImpl->getDriverImplNames().end();
97 } // namespace offapp
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */