1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2ee96f1cSAndrew Rist  * distributed with this work for additional information
6*2ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2ee96f1cSAndrew Rist  *
11*2ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2ee96f1cSAndrew Rist  *
13*2ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2ee96f1cSAndrew Rist  * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist  * under the License.
19*2ee96f1cSAndrew Rist  *
20*2ee96f1cSAndrew Rist  *************************************************************/
21*2ee96f1cSAndrew Rist 
22*2ee96f1cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir #include "sdbcdriverenum.hxx"
27cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
28cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //........................................................................
34cdf0e10cSrcweir namespace offapp
35cdf0e10cSrcweir {
36cdf0e10cSrcweir //........................................................................
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
40cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	//====================================================================
43cdf0e10cSrcweir 	//= ODriverEnumerationImpl
44cdf0e10cSrcweir 	//====================================================================
45cdf0e10cSrcweir 	class ODriverEnumerationImpl
46cdf0e10cSrcweir 	{
47cdf0e10cSrcweir 	protected:
48cdf0e10cSrcweir 		::std::vector< ::rtl::OUString >	m_aImplNames;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	public:
51cdf0e10cSrcweir 		ODriverEnumerationImpl();
52cdf0e10cSrcweir 
getDriverImplNames() const53cdf0e10cSrcweir 		const ::std::vector< ::rtl::OUString >& getDriverImplNames() const { return m_aImplNames; }
54cdf0e10cSrcweir 	};
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	//--------------------------------------------------------------------
ODriverEnumerationImpl()57cdf0e10cSrcweir 	ODriverEnumerationImpl::ODriverEnumerationImpl()
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		try
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			Reference< XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
62cdf0e10cSrcweir 			Reference< XInterface > xDM = xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdbc.DriverManager"));
63cdf0e10cSrcweir 			OSL_ENSURE(xDM.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: no access to the SDBC driver manager!");
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 			Reference< XEnumerationAccess > xEnumAccess(xDM, UNO_QUERY);
66cdf0e10cSrcweir 			OSL_ENSURE(xEnumAccess.is() || !xDM.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: can't enumerate SDBC drivers (missing the interface)!");
67cdf0e10cSrcweir 			if (xEnumAccess.is())
68cdf0e10cSrcweir 			{
69cdf0e10cSrcweir 				Reference< XEnumeration > xEnumDrivers = xEnumAccess->createEnumeration();
70cdf0e10cSrcweir 				OSL_ENSURE(xEnumDrivers.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: invalid enumeration object!");
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 				Reference< XServiceInfo > xDriverSI;
73cdf0e10cSrcweir 				while (xEnumDrivers->hasMoreElements())
74cdf0e10cSrcweir 				{
75cdf0e10cSrcweir 					xEnumDrivers->nextElement() >>= xDriverSI;
76cdf0e10cSrcweir 					OSL_ENSURE(xDriverSI.is(), "ODriverEnumerationImpl::ODriverEnumerationImpl: driver without service info!");
77cdf0e10cSrcweir 					if (xDriverSI.is())
78cdf0e10cSrcweir 						m_aImplNames.push_back(xDriverSI->getImplementationName());
79cdf0e10cSrcweir 				}
80cdf0e10cSrcweir 			}
81cdf0e10cSrcweir 		}
82cdf0e10cSrcweir 		catch(const Exception&)
83cdf0e10cSrcweir 		{
84cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "ODriverEnumerationImpl::ODriverEnumerationImpl: caught an exception while enumerating the drivers!");
85cdf0e10cSrcweir 		}
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	//====================================================================
89cdf0e10cSrcweir 	//= ODriverEnumeration
90cdf0e10cSrcweir 	//====================================================================
91cdf0e10cSrcweir 	//--------------------------------------------------------------------
ODriverEnumeration()92cdf0e10cSrcweir 	ODriverEnumeration::ODriverEnumeration() throw()
93cdf0e10cSrcweir 		:m_pImpl(new ODriverEnumerationImpl)
94cdf0e10cSrcweir 	{
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	//--------------------------------------------------------------------
~ODriverEnumeration()98cdf0e10cSrcweir 	ODriverEnumeration::~ODriverEnumeration() throw()
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir 		delete m_pImpl;
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	//--------------------------------------------------------------------
begin() const104cdf0e10cSrcweir 	ODriverEnumeration::const_iterator ODriverEnumeration::begin() const throw()
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		return m_pImpl->getDriverImplNames().begin();
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	//--------------------------------------------------------------------
end() const110cdf0e10cSrcweir 	ODriverEnumeration::const_iterator ODriverEnumeration::end() const throw()
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		return m_pImpl->getDriverImplNames().end();
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir //........................................................................
115cdf0e10cSrcweir }	// namespace offapp
116cdf0e10cSrcweir //........................................................................
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119