Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

BackendInfo.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): Emmanuel Cecchet.
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  * This class defines a BackendInfo. We cannot use DatabaseBackend as a
00041  * serializable object because it is used as an MBean interface. We use this
00042  * class to share configuration information on backends between distributed
00043  * virtual database.
00044  * 
00045  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00046  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00047  * @version 1.0
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    * Creates a new <code>BackendInfo</code> object. Extract configuration
00061    * information from the original backend object
00062    * 
00063    * @param name name of the backend
00064    * @param driverPath driver path
00065    * @param driverClassName driver class name
00066    * @param url backend url
00067    * @param vdbName Name of the virtual database this backend is attached to
00068    * @param connectionTestStatement connection test statement
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    * Creates a new <code>BackendInfo</code> object. Extract configuration
00084    * information from the original backend object
00085    * 
00086    * @param backend DatabaseBackend to extract information from
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    * Extract information from the xml configuration Creates a new
00101    * <code>BackendInfo</code> object
00102    * 
00103    * @param xml xml version of a backend
00104    * @throws DocumentException if fails to create object
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    * Create a corresponding DatabaseBackend object from the information stored
00126    * in this object.
00127    * 
00128    * @return a <code>DatabaseBackend</code>
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    * Returns the xml value.
00146    * 
00147    * @return Returns the xml.
00148    */
00149   public String getXml()
00150   {
00151     return xml;
00152   }
00153 
00154   /**
00155    * Returns the connectionTestStatement value.
00156    * 
00157    * @return Returns the connectionTestStatement.
00158    */
00159   public String getConnectionTestStatement()
00160   {
00161     return connectionTestStatement;
00162   }
00163 
00164   /**
00165    * Returns the driverClassName value.
00166    * 
00167    * @return Returns the driverClassName.
00168    */
00169   public String getDriverClassName()
00170   {
00171     return driverClassName;
00172   }
00173 
00174   /**
00175    * Returns the driverPath value.
00176    * 
00177    * @return Returns the driverPath.
00178    */
00179   public String getDriverPath()
00180   {
00181     return driverPath;
00182   }
00183 
00184   /**
00185    * Returns the name value.
00186    * 
00187    * @return Returns the name.
00188    */
00189   public String getName()
00190   {
00191     return name;
00192   }
00193 
00194   /**
00195    * Returns the url value.
00196    * 
00197    * @return Returns the url.
00198    */
00199   public String getUrl()
00200   {
00201     return url;
00202   }
00203 
00204   /**
00205    * Returns the virtualDatabaseName value.
00206    * 
00207    * @return Returns the virtualDatabaseName.
00208    */
00209   public String getVirtualDatabaseName()
00210   {
00211     return virtualDatabaseName;
00212   }
00213 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1