> List of tutorials

Table of contents for Basic knowledge

Base-Class to read the file with a XML-structure for Connections
to the database-system or the Java-Application-Server - Fat-Client-Development

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes your rights or you think that rights of others (third parties) are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-08-23

This is document contains the code for Class JSBS_XML_Connections.
For easy 'cut and paste' ;-)

package js_base.xml;

import org.jdom.Element;
import
js_base.structures.JSBS_UniversalParameters;
/**
 
*
 * @author
kurt@javascout.biz
 * @date 2006-08-23
 *
 * @description
 *  Class with specialized methods for getting parameters for the connection to
 *  a database-system or a Java-Application-Server (JAS).
 *  This class inherits JSBS_XML_Base and uses its methods to read a file
 *  containing a XML-structure.
 
*
 * @change-log
 * when         who               why
 * --------------------------------------------------------
 *
 */

public class JSBS_XML_Connections extends JSBS_XML_Base {
/*
 * -------------------------------
 * Constructor of the class */
    public JSBS_XML_Connections(JSBS_UniversalParameters parmUniversalParameters) {
/* Perform the code in the constructor of the inherited class */
        super();
/* Get the filename for the XML-structure with the language dependant display-strings.
 * This is done by concatenating the directory with the language dependant files
 * and the filename for the file with the XML-structure. */
        String locstrFileName =
            parmUniversalParameters.strConnectionsDirectoryName +
            parmUniversalParameters.CONST_CONNECTIONS_PARM_FILE_NAME;

/* Read the RootElement (method implemented in the superclass - i.e. the class inherited) */
        
readXMLFile(locstrFileName);
    }

/*
 * ************************************************** */
/*
 * Method to get the class-name of the database-driver out of the XML-structure */
    public String getDataBaseDriverName() {
/* 
 * The code here is more simple as in other classes dealing with XML-structures.
 * The reason is, that the XML-structure is not deep and not finding an element
 * is a critical error which should lead to a dump of the application. */

      String locstrDataBaseDriverName = "";
/* 
 * First read the XML-element representing the section for the database-parameters. */
      
Element elementDataBaseParameters = XML_RootElement.getChild("DataBaseParameters");
      if (elementDataBaseParameters == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }

/* Get the XML-element with the parameter. */
      Element elementDataBaseDriverName = elementDataBaseParameters.getChild("DataBaseDriverName");
      if (elementDataBaseDriverName == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }

/* Get the content (text) of the XML-element and return it. */
      locstrDataBaseDriverName = elementDataBaseDriverName.get
TextTrim();
      return locstrDataBaseDriverName;
    
}
/*
 * ************************************************** */
/*
 * Method to get the database-name with all connection-parameters out of the XML-structure */
    public
String getDataBaseName() {
      String locstrDataBaseName = "";
/* 
 * First read the XML-element representing the section for the database-parameters. */
      Element elementDataBaseParameters = XML_RootElement.getChild("DataBaseParameters");
      if (elementDataBaseParameters == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }

/* Get the XML-element with the parameter. */
      Element elementDataBaseName = elementDataBaseParameters.getChild("DataBaseName");
      if (elementDataBaseName == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }
/* Get the content (text) of the XML-element and return it. */
      locstrDataBaseName = elementDataBaseName.getTextTrim();
      return locstrDataBaseName;
    
}

/*
 * ************************************************** */
/*
 * Method to get the User-ID for the connection to the database out of the XML-structure */
    public
String getDataBaseUserID() {
      String locstrDataBaseUserID = "";
/* 
 * First read the XML-element representing the section for the database-parameters. */
      Element elementDataBaseParameters = XML_RootElement.getChild("DataBaseParameters");
      if (elementDataBaseParameters == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }

/* Get the XML-element with the parameter. */
      Element elementDataBaseUserID = elementDataBaseParameters.getChild("DataBaseUserID");
      if (elementDataBaseUserID == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }
/* Get the content (text) of the XML-element and return it. */
      locstrDataBaseUserID = elementDataBaseUserID.getTextTrim();
      return locstrDataBaseUserID;
    
}

/*
 * ************************************************** */
/*
 * Method to get the Password for the connection to the database out of the XML-structure */
    public
String getDataBasePassword() {
      String locstrDataBasePassword = "";
/* 
 * First read the XML-element representing the section for the database-parameters. */
      Element elementDataBaseParameters = XML_RootElement.getChild("DataBaseParameters");
      if (elementDataBaseParameters == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }

/* Get the XML-element with the parameter. */
      Element elementDataBasePassword = elementDataBaseParameters.getChild("DataBasePassword");
      if (elementDataBasePassword == null) {
/* Element not found within the XML-structure. Very critical error. */
        return null;
      }
/* Get the content (text) of the XML-element and return it. */
      locstrDataBasePassword = elementDataBasePassword.getTextTrim();
      return locstrDataBasePassword;
    
}

}