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_connectivity.hxx"
30 #include "calc/CDriver.hxx"
31 #include "calc/CConnection.hxx"
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include "connectivity/dbexception.hxx"
34 #include "resource/sharedresources.hxx"
35 #include "resource/calc_res.hrc"
36 
37 using namespace connectivity::calc;
38 using namespace connectivity::file;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::lang;
44 
45 
46 //------------------------------------------------------------------------------
47 // static ServiceInfo
48 
49 rtl::OUString ODriver::getImplementationName_Static(  ) throw(RuntimeException)
50 {
51 	return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.calc.ODriver");
52 }
53 
54 ::rtl::OUString SAL_CALL ODriver::getImplementationName(  ) throw(RuntimeException)
55 {
56 	return getImplementationName_Static();
57 }
58 
59 // service names from file::OFileDriver
60 
61 //------------------------------------------------------------------
62 
63 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
64 	connectivity::calc::ODriver_CreateInstance(const ::com::sun::star::uno::Reference<
65 		::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
66 {
67 	return *(new ODriver(_rxFactory));
68 }
69 
70 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url,
71 	const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
72 {
73 	::osl::MutexGuard aGuard( m_aMutex );
74 	if (ODriver_BASE::rBHelper.bDisposed)
75 		throw DisposedException();
76 
77 	if ( ! acceptsURL(url) )
78 		return NULL;
79 
80 	OCalcConnection* pCon = new OCalcConnection(this);
81 	pCon->construct(url,info);
82 	Reference< XConnection > xCon = pCon;
83 	m_xConnections.push_back(WeakReferenceHelper(*pCon));
84 
85 	return xCon;
86 }
87 
88 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
89                 throw(SQLException, RuntimeException)
90 {
91 	return url.compareTo(::rtl::OUString::createFromAscii("sdbc:calc:"),10) == 0;
92 }
93 
94 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
95 {
96 	if ( !acceptsURL(url) )
97     {
98         SharedResources aResources;
99         const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
100 		::dbtools::throwGenericSQLException(sMessage ,*this);
101     }
102 	return Sequence< DriverPropertyInfo >();
103 }
104 // -----------------------------------------------------------------------------
105 
106