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 : #include "comphelper/processfactory.hxx"
28 :
29 :
30 : using namespace connectivity::flat;
31 : using namespace connectivity::file;
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::beans;
34 : using namespace ::com::sun::star::sdbcx;
35 : using namespace ::com::sun::star::sdbc;
36 : using namespace ::com::sun::star::lang;
37 :
38 :
39 : // static ServiceInfo
40 :
41 0 : OUString ODriver::getImplementationName_Static( ) throw(RuntimeException)
42 : {
43 0 : return OUString("com.sun.star.comp.sdbc.flat.ODriver");
44 : }
45 :
46 :
47 0 : OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException, std::exception)
48 : {
49 0 : return getImplementationName_Static();
50 : }
51 :
52 :
53 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 )
54 : {
55 0 : return *(new ODriver( comphelper::getComponentContext(_rxFactory) ));
56 : }
57 :
58 0 : Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, std::exception)
59 : {
60 0 : ::osl::MutexGuard aGuard( m_aMutex );
61 0 : if (ODriver_BASE::rBHelper.bDisposed)
62 0 : throw DisposedException();
63 :
64 0 : if ( ! acceptsURL(url) )
65 0 : return NULL;
66 :
67 0 : OFlatConnection* pCon = new OFlatConnection(this);
68 0 : pCon->construct(url,info);
69 0 : Reference< XConnection > xCon = pCon;
70 0 : m_xConnections.push_back(WeakReferenceHelper(*pCon));
71 :
72 0 : return xCon;
73 : }
74 :
75 0 : sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url )
76 : throw(SQLException, RuntimeException, std::exception)
77 : {
78 0 : return url.startsWith("sdbc:flat:");
79 : }
80 :
81 0 : Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, std::exception)
82 : {
83 0 : if ( acceptsURL(url) )
84 : {
85 0 : ::std::vector< DriverPropertyInfo > aDriverInfo;
86 :
87 0 : Sequence< OUString > aBoolean(2);
88 0 : aBoolean[0] = "0";
89 0 : aBoolean[1] = "1";
90 :
91 : aDriverInfo.push_back(DriverPropertyInfo(
92 : OUString("FieldDelimiter")
93 : ,OUString("Field separator.")
94 : ,sal_False
95 : ,OUString()
96 : ,Sequence< OUString >())
97 0 : );
98 : aDriverInfo.push_back(DriverPropertyInfo(
99 : OUString("HeaderLine")
100 : ,OUString("Text contains headers.")
101 : ,sal_False
102 : ,OUString("0")
103 : ,aBoolean)
104 0 : );
105 : aDriverInfo.push_back(DriverPropertyInfo(
106 : OUString("StringDelimiter")
107 : ,OUString("Text separator.")
108 : ,sal_False
109 : ,OUString("0")
110 : ,aBoolean)
111 0 : );
112 : aDriverInfo.push_back(DriverPropertyInfo(
113 : OUString("DecimalDelimiter")
114 : ,OUString("Decimal separator.")
115 : ,sal_False
116 : ,OUString("0")
117 : ,aBoolean)
118 0 : );
119 : aDriverInfo.push_back(DriverPropertyInfo(
120 : OUString("ThousandDelimiter")
121 : ,OUString("Thousands separator.")
122 : ,sal_False
123 : ,OUString("0")
124 : ,aBoolean)
125 0 : );
126 : return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url,info ),
127 0 : Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()));
128 : }
129 0 : ::connectivity::SharedResources aResources;
130 0 : const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
131 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
132 0 : return Sequence< DriverPropertyInfo >();
133 : }
134 :
135 :
136 :
137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|