00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.common.shared;
00026
00027 import java.io.Serializable;
00028 import java.io.StringReader;
00029
00030 import javax.management.NotCompliantMBeanException;
00031
00032 import org.dom4j.Document;
00033 import org.dom4j.DocumentException;
00034 import org.dom4j.Node;
00035 import org.dom4j.io.SAXReader;
00036 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00037 import org.objectweb.cjdbc.controller.backend.DatabaseBackend;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 public class BackendInfo implements Serializable
00050 {
00051 private String name;
00052 private String url;
00053 private String driverPath;
00054 private String driverClassName;
00055 private String virtualDatabaseName;
00056 private String connectionTestStatement;
00057 private String xml;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 public BackendInfo(String name, String driverPath, String driverClassName,
00071 String url, String vdbName, String connectionTestStatement)
00072 {
00073 this.name = name;
00074 this.driverPath = driverPath;
00075 this.driverClassName = driverClassName;
00076 this.virtualDatabaseName = vdbName;
00077 this.url = url;
00078 this.connectionTestStatement = connectionTestStatement;
00079 this.xml = null;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 public BackendInfo(DatabaseBackend backend)
00089 {
00090 this.url = backend.getURL();
00091 this.name = backend.getName();
00092 this.driverPath = backend.getDriverPath();
00093 this.driverClassName = backend.getDriverClassName();
00094 this.virtualDatabaseName = backend.getVirtualDatabaseName();
00095 this.connectionTestStatement = backend.getConnectionTestStatement();
00096 this.xml = null;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106 public BackendInfo(String xml) throws DocumentException
00107 {
00108 StringReader sreader = new StringReader(xml);
00109 SAXReader reader = new SAXReader();
00110 Document document = reader.read(sreader);
00111 Node node = document.selectSingleNode("//"
00112 + DatabasesXmlTags.ELT_DatabaseBackend);
00113 this.name = node.valueOf("@" + DatabasesXmlTags.ATT_name);
00114 this.url = node.valueOf("@" + DatabasesXmlTags.ATT_url);
00115 this.driverPath = node.valueOf("@" + DatabasesXmlTags.ATT_driverPath);
00116 if (driverPath.equals(""))
00117 driverPath = null;
00118 this.driverClassName = node.valueOf("@" + DatabasesXmlTags.ATT_driver);
00119 this.connectionTestStatement = node.valueOf("@"
00120 + DatabasesXmlTags.ATT_connectionTestStatement);
00121 this.xml = xml;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 public DatabaseBackend getDatabaseBackend()
00131 {
00132 try
00133 {
00134 return new DatabaseBackend(name, driverPath, driverClassName, url,
00135 virtualDatabaseName, true, connectionTestStatement);
00136 }
00137 catch (NotCompliantMBeanException e)
00138 {
00139 throw new RuntimeException(
00140 "Unable to recreate backend from BackendInfo object", e);
00141 }
00142 }
00143
00144
00145
00146
00147
00148
00149 public String getXml()
00150 {
00151 return xml;
00152 }
00153
00154
00155
00156
00157
00158
00159 public String getConnectionTestStatement()
00160 {
00161 return connectionTestStatement;
00162 }
00163
00164
00165
00166
00167
00168
00169 public String getDriverClassName()
00170 {
00171 return driverClassName;
00172 }
00173
00174
00175
00176
00177
00178
00179 public String getDriverPath()
00180 {
00181 return driverPath;
00182 }
00183
00184
00185
00186
00187
00188
00189 public String getName()
00190 {
00191 return name;
00192 }
00193
00194
00195
00196
00197
00198
00199 public String getUrl()
00200 {
00201 return url;
00202 }
00203
00204
00205
00206
00207
00208
00209 public String getVirtualDatabaseName()
00210 {
00211 return virtualDatabaseName;
00212 }
00213 }