KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > XDBCWrapper


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mediator;
24
25 import org.xquark.xml.xdbc.*;
26
27 public class XDBCWrapper {
28     // **********************************************************************
29
// * VERSIONING
30
// **********************************************************************
31
private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
32     private static final String JavaDoc RCSName = "Name";
33
34     // **********************************************************************
35
// * CLASS VARIABLE
36
// **********************************************************************
37
private Mediator mediator = null;
38     private XMLDataSource dataSource = null;
39     
40     private String JavaDoc name;
41     private String JavaDoc driver;
42     private String JavaDoc uri;
43     private String JavaDoc login = null;
44     private String JavaDoc passwd = null;
45     private boolean isConnected;
46
47
48     // ************************************************************************
49
// * INITIALISATION
50
// ************************************************************************
51
/**
52      *
53      */

54     public XDBCWrapper(String JavaDoc name, String JavaDoc driver, String JavaDoc connection) {
55         this(name, driver, connection, null, null);
56     }
57
58     /**
59      *
60      */

61     public XDBCWrapper(String JavaDoc name, String JavaDoc driver, String JavaDoc connection, String JavaDoc login, String JavaDoc passwd) {
62         this.name = name;
63         this.driver = driver;
64         this.uri = connection;
65         this.login = login;
66         this.passwd = passwd;
67         this.isConnected = false;
68     }
69     
70     public XDBCWrapper(String JavaDoc name, XMLDataSource source) {
71         this.name = name;
72         dataSource = source;
73     }
74     
75     void setMediator(Mediator mediator) {
76         this.mediator = mediator;
77     }
78
79     // ************************************************************************
80
// * CONNECTION/DISCONNECTION METHODS
81
// ************************************************************************
82

83     public synchronized XMLDataSource getDataSource() throws XMLDBCException {
84         if (dataSource == null) {
85             if (login != null && passwd != null) {
86                 dataSource = XMLDriverManager.getDataSource(uri, login, passwd);
87             } else {
88                 dataSource = XMLDriverManager.getDataSource(uri);
89             }
90         }
91         return dataSource;
92     }
93
94     /**
95      * Load the accessor driver and open a connection.
96      */

97     public XMLConnection getConnection() throws XMLDBCException {
98         return getDataSource().getConnection();
99     }
100
101     /**
102      * Close the accessor's connection.
103      */

104     public void close() {
105         isConnected = false;
106     }
107
108     // ************************************************************************
109
// * GET/SET METHODS
110
// ************************************************************************
111
/**
112      * Return the name of this accessor.
113      */

114     public String JavaDoc getName() {
115         return name;
116     }
117 }
118
Popular Tags