1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/stl_types.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/container/XEnumerationAccess.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
27 //........................................................................
30 //........................................................................
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 //====================================================================
38 //= ODriverEnumerationImpl
39 //====================================================================
40 class ODriverEnumerationImpl
43 ::std::vector
< OUString
> m_aImplNames
;
46 ODriverEnumerationImpl();
48 const ::std::vector
< OUString
>& getDriverImplNames() const { return m_aImplNames
; }
51 //--------------------------------------------------------------------
52 ODriverEnumerationImpl::ODriverEnumerationImpl()
56 Reference
< XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
57 Reference
< XDriverManager2
> xEnumAccess
= DriverManager::create( xContext
);
59 Reference
< XEnumeration
> xEnumDrivers
= xEnumAccess
->createEnumeration();
60 OSL_ENSURE(xEnumDrivers
.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
62 Reference
< XServiceInfo
> xDriverSI
;
63 while (xEnumDrivers
->hasMoreElements())
65 xEnumDrivers
->nextElement() >>= xDriverSI
;
66 OSL_ENSURE(xDriverSI
.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
68 m_aImplNames
.push_back(xDriverSI
->getImplementationName());
71 catch(const Exception
&)
73 OSL_FAIL("ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
77 //====================================================================
78 //= ODriverEnumeration
79 //====================================================================
80 //--------------------------------------------------------------------
81 ODriverEnumeration::ODriverEnumeration() throw()
82 :m_pImpl(new ODriverEnumerationImpl
)
86 //--------------------------------------------------------------------
87 ODriverEnumeration::~ODriverEnumeration() throw()
92 //--------------------------------------------------------------------
93 ODriverEnumeration::const_iterator
ODriverEnumeration::begin() const throw()
95 return m_pImpl
->getDriverImplNames().begin();
98 //--------------------------------------------------------------------
99 ODriverEnumeration::const_iterator
ODriverEnumeration::end() const throw()
101 return m_pImpl
->getDriverImplNames().end();
103 //........................................................................
104 } // namespace offapp
105 //........................................................................
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */