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 "dbase/DDriver.hxx"
31 #include "dbase/DConnection.hxx"
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include "connectivity/dbexception.hxx"
34 #include "resource/dbase_res.hrc"
35 
36 using namespace connectivity::dbase;
37 using namespace connectivity::file;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::sdbcx;
41 using namespace ::com::sun::star::sdbc;
42 using namespace ::com::sun::star::lang;
43 
44 
45 // static ServiceInfo
46 //------------------------------------------------------------------------------
47 rtl::OUString ODriver::getImplementationName_Static(  ) throw(RuntimeException)
48 {
49 	return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.dbase.ODriver");
50 }
51 
52 //------------------------------------------------------------------
53 ::rtl::OUString SAL_CALL ODriver::getImplementationName(  ) throw(RuntimeException)
54 {
55 	return getImplementationName_Static();
56 }
57 
58 //------------------------------------------------------------------
59 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  SAL_CALL connectivity::dbase::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
60 {
61 	return *(new ODriver(_rxFactory));
62 }
63 // --------------------------------------------------------------------------------
64 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
65 {
66 	::osl::MutexGuard aGuard( m_aMutex );
67 	if (ODriver_BASE::rBHelper.bDisposed)
68 		throw DisposedException();
69 
70 	if ( ! acceptsURL(url) )
71 		return NULL;
72 
73 	ODbaseConnection* pCon = new ODbaseConnection(this);
74 	pCon->construct(url,info);
75     Reference< XConnection > xCon = pCon;
76     m_xConnections.push_back(WeakReferenceHelper(*pCon));
77 
78 	return xCon;
79 }
80 // --------------------------------------------------------------------------------
81 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException)
82 {
83 	return !url.compareTo(::rtl::OUString::createFromAscii("sdbc:dbase:"),11);
84 }
85 // -----------------------------------------------------------------------------
86 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
87 {
88 	if ( acceptsURL(url) )
89 	{
90 		::std::vector< DriverPropertyInfo > aDriverInfo;
91 
92 		Sequence< ::rtl::OUString > aBoolean(2);
93 		aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
94 		aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
95 
96 		aDriverInfo.push_back(DriverPropertyInfo(
97 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
98 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
99 				,sal_False
100 				,::rtl::OUString()
101 				,Sequence< ::rtl::OUString >())
102 				);
103 		aDriverInfo.push_back(DriverPropertyInfo(
104 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted"))
105 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display inactive records."))
106 				,sal_False
107 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
108 				,aBoolean)
109 				);
110 		aDriverInfo.push_back(DriverPropertyInfo(
111 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EnableSQL92Check"))
112 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use SQL92 naming constraints."))
113 				,sal_False
114 				,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
115 				,aBoolean)
116 				);
117 		return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
118 	}
119 
120 	SharedResources aResources;
121     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
122 	::dbtools::throwGenericSQLException(sMessage ,*this);
123 	return Sequence< DriverPropertyInfo >();
124 }
125 // -----------------------------------------------------------------------------
126 
127 
128