Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "flat/EDriver.hxx"
21 : #include "flat/EConnection.hxx"
22 : #include <com/sun/star/lang/DisposedException.hpp>
23 : #include "connectivity/dbexception.hxx"
24 : #include <comphelper/sequence.hxx>
25 : #include "resource/common_res.hrc"
26 : #include "resource/sharedresources.hxx"
27 :
28 :
29 : using namespace connectivity::flat;
30 : using namespace connectivity::file;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::beans;
33 : using namespace ::com::sun::star::sdbcx;
34 : using namespace ::com::sun::star::sdbc;
35 : using namespace ::com::sun::star::lang;
36 :
37 :
38 : // static ServiceInfo
39 : //------------------------------------------------------------------------------
40 0 : rtl::OUString ODriver::getImplementationName_Static( ) throw(RuntimeException)
41 : {
42 0 : return rtl::OUString("com.sun.star.comp.sdbc.flat.ODriver");
43 : }
44 :
45 : //------------------------------------------------------------------
46 0 : ::rtl::OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException)
47 : {
48 0 : return getImplementationName_Static();
49 : }
50 :
51 : //------------------------------------------------------------------
52 0 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::flat::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
53 : {
54 0 : return *(new ODriver(_rxFactory));
55 : }
56 : // --------------------------------------------------------------------------------
57 0 : Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
58 : {
59 0 : ::osl::MutexGuard aGuard( m_aMutex );
60 0 : if (ODriver_BASE::rBHelper.bDisposed)
61 0 : throw DisposedException();
62 :
63 0 : if ( ! acceptsURL(url) )
64 0 : return NULL;
65 :
66 0 : OFlatConnection* pCon = new OFlatConnection(this);
67 0 : pCon->construct(url,info);
68 0 : Reference< XConnection > xCon = pCon;
69 0 : m_xConnections.push_back(WeakReferenceHelper(*pCon));
70 :
71 0 : return xCon;
72 : }
73 : // --------------------------------------------------------------------------------
74 0 : sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
75 : throw(SQLException, RuntimeException)
76 : {
77 0 : return url.compareTo(::rtl::OUString("sdbc:flat:"),10) == 0;
78 : }
79 : // -----------------------------------------------------------------------------
80 0 : Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
81 : {
82 0 : if ( acceptsURL(url) )
83 : {
84 0 : ::std::vector< DriverPropertyInfo > aDriverInfo;
85 :
86 0 : Sequence< ::rtl::OUString > aBoolean(2);
87 0 : aBoolean[0] = ::rtl::OUString("0");
88 0 : aBoolean[1] = ::rtl::OUString("1");
89 :
90 : aDriverInfo.push_back(DriverPropertyInfo(
91 : ::rtl::OUString("FieldDelimiter")
92 : ,::rtl::OUString("Field separator.")
93 : ,sal_False
94 : ,::rtl::OUString()
95 : ,Sequence< ::rtl::OUString >())
96 0 : );
97 : aDriverInfo.push_back(DriverPropertyInfo(
98 : ::rtl::OUString("HeaderLine")
99 : ,::rtl::OUString("Text contains headers.")
100 : ,sal_False
101 : ,::rtl::OUString("0")
102 : ,aBoolean)
103 0 : );
104 : aDriverInfo.push_back(DriverPropertyInfo(
105 : ::rtl::OUString("StringDelimiter")
106 : ,::rtl::OUString("Text separator.")
107 : ,sal_False
108 : ,::rtl::OUString("0")
109 : ,aBoolean)
110 0 : );
111 : aDriverInfo.push_back(DriverPropertyInfo(
112 : ::rtl::OUString("DecimalDelimiter")
113 : ,::rtl::OUString("Decimal separator.")
114 : ,sal_False
115 : ,::rtl::OUString("0")
116 : ,aBoolean)
117 0 : );
118 : aDriverInfo.push_back(DriverPropertyInfo(
119 : ::rtl::OUString("ThousandDelimiter")
120 : ,::rtl::OUString("Thousands separator.")
121 : ,sal_False
122 : ,::rtl::OUString("0")
123 : ,aBoolean)
124 0 : );
125 : return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url,info ),
126 0 : Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()));
127 : }
128 0 : ::connectivity::SharedResources aResources;
129 0 : const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
130 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
131 0 : return Sequence< DriverPropertyInfo >();
132 : }
133 : // -----------------------------------------------------------------------------
134 :
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|