oracle.otnsamples.cmsxdb.ConnParams (Java2HTML)
/*
 * @author  : Elangovan
 * @version : 1.0
 *
 * Development Environment : Oracle9i JDeveloper

 * Name of the File        : ConnParams.java
 *
 * Creation / Modification History
 *    Elangovan           12-Dec-2002        Created
 *
 */


package oracle.otnsamples.cmsxdb;

import java.io.IOException;

import java.util.Properties;
import java.util.Enumeration;
import java.util.ResourceBundle;


/**
 * This class, loads the connection parameters from 'Connection.properties' file
 * and initializes the static members of the class.
 */
public class ConnParams  {

  
  public static String datasourceName  = null;


  public static String dbUsername      = null;

  public static String dbPassword      = null;

  public static String siteRootPath    = null;

  // Host Name of the Database Server with Http port
  public static String dbWebURL        = null;

  // Context root for CMS Servlet

  public static String dbCMSServlet    = null;

  // Context root of Transform Servlet
  public static String dbTransServlet  = null;

  // Context root of Search Servlet
  public static String dbSearchServlet = null;

  static {

    // If properties are not initialised

    if (datasourceName == null) {

      Properties conValues = null;

      try {

        // Parse the Connection.properties file and extract the details
        // Connection.properties is searched in CLASSPATH
        conValues = loadParams("Connection");

        // Get the details from the Properties
        datasourceName     = (String) conValues.getProperty("DataSourceName");

        dbWebURL           = (String) conValues.getProperty("DBWebURL");
        dbUsername         = (String) conValues.getProperty("DBUsername"); 
        dbPassword         = (String) conValues.getProperty("DBPassword");
        siteRootPath       = (String) conValues.getProperty("siteRootPath");
        
        // Prepend database hostname and port to servlet context root
        dbCMSServlet       = dbWebURL + (String) conValues.getProperty("CMSServletContextRoot");
        dbTransServlet     = dbWebURL + (String) conValues.getProperty("TransServletContextRoot");
        dbSearchServlet    = dbWebURL + (String) conValues.getProperty("SearchServletContextRoot");

      } catch (Exception ex) {
        System.out.println(" Fatal Error : Could not Read Properties file : "
                           + ex.toString());

      } finally {

        if( conValues != null ) {
        // Clear properties
        conValues.clear();
        conValues = null;
        }

      }
    }
  }

  /**
   * This method reads a properties file which is passed as

   * the parameter to it and load it into a java Properties
   * object and returns it.
   * 
   * @param file File path 
   * @return Properties The properties object
   * @exception IOException if loading properties file fails
   * @since 1.0
   */
  public static Properties loadParams(String file) 
      throws IOException {

    // Loads a ResourceBundle and creates Properties from it
    Properties     prop   = new Properties();
    ResourceBundle bundle = ResourceBundle.getBundle(file);


    // Retrieve the keys and populate the properties object
    Enumeration enum = bundle.getKeys();
    String      key  = null;
    while (enum.hasMoreElements()) {
      key = (String) enum.nextElement();

      prop.put(key, bundle.getObject(key));
    }

    return prop;
  }
  
}
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy