1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 #include "sdbcdriverenum.hxx"
31 #include <comphelper/stl_types.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/container/XEnumerationAccess.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 
37 //........................................................................
38 namespace offapp
39 {
40 //........................................................................
41 
42 	using namespace ::com::sun::star::uno;
43 	using namespace ::com::sun::star::lang;
44 	using namespace ::com::sun::star::container;
45 
46 	//====================================================================
47 	//= ODriverEnumerationImpl
48 	//====================================================================
49 	class ODriverEnumerationImpl
50 	{
51 	protected:
52 		::std::vector< ::rtl::OUString >	m_aImplNames;
53 
54 	public:
55 		ODriverEnumerationImpl();
56 
57 		const ::std::vector< ::rtl::OUString >& getDriverImplNames() const { return m_aImplNames; }
58 	};
59 
60 	//--------------------------------------------------------------------
61 	ODriverEnumerationImpl::ODriverEnumerationImpl()
62 	{
63 		try
64 		{
65 			Reference< XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
66 			Reference< XInterface > xDM = xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdbc.DriverManager"));
67 			OSL_ENSURE(xDM.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: no access to the SDBC driver manager!");
68 
69 			Reference< XEnumerationAccess > xEnumAccess(xDM, UNO_QUERY);
70 			OSL_ENSURE(xEnumAccess.is() || !xDM.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: can't enumerate SDBC drivers (missing the interface)!");
71 			if (xEnumAccess.is())
72 			{
73 				Reference< XEnumeration > xEnumDrivers = xEnumAccess->createEnumeration();
74 				OSL_ENSURE(xEnumDrivers.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
75 
76 				Reference< XServiceInfo > xDriverSI;
77 				while (xEnumDrivers->hasMoreElements())
78 				{
79 					xEnumDrivers->nextElement() >>= xDriverSI;
80 					OSL_ENSURE(xDriverSI.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
81 					if (xDriverSI.is())
82 						m_aImplNames.push_back(xDriverSI->getImplementationName());
83 				}
84 			}
85 		}
86 		catch(const Exception&)
87 		{
88 			OSL_ENSURE(sal_False, "ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
89 		}
90 	}
91 
92 	//====================================================================
93 	//= ODriverEnumeration
94 	//====================================================================
95 	//--------------------------------------------------------------------
96 	ODriverEnumeration::ODriverEnumeration() throw()
97 		:m_pImpl(new ODriverEnumerationImpl)
98 	{
99 	}
100 
101 	//--------------------------------------------------------------------
102 	ODriverEnumeration::~ODriverEnumeration() throw()
103 	{
104 		delete m_pImpl;
105 	}
106 
107 	//--------------------------------------------------------------------
108 	ODriverEnumeration::const_iterator ODriverEnumeration::begin() const throw()
109 	{
110 		return m_pImpl->getDriverImplNames().begin();
111 	}
112 
113 	//--------------------------------------------------------------------
114 	ODriverEnumeration::const_iterator ODriverEnumeration::end() const throw()
115 	{
116 		return m_pImpl->getDriverImplNames().end();
117 	}
118 //........................................................................
119 }	// namespace offapp
120 //........................................................................
121 
122 
123