Project

General

Profile

1
/**
2
 *      Name: MetaCatUtil.java
3
 *   Purpose: A Class that implements utility methods for a metadata catalog
4
 * Copyright: 2000 Regents of the University of California and the
5
 *            National Center for Ecological Analysis and Synthesis
6
 *   Authors: Matt Jones
7
 * 
8
 *   Version: '$Id: MetaCatUtil.java 184 2000-06-21 02:57:19Z jones $'
9
 */
10

    
11
package edu.ucsb.nceas.metacat;
12

    
13
import java.sql.Connection;
14
import java.sql.DriverManager;
15
import java.sql.SQLException;
16
import java.util.PropertyResourceBundle;
17

    
18
/**
19
 * A suite of utility classes for the metadata catalog server
20
 */
21
public class MetaCatUtil {
22

    
23
  private PropertyResourceBundle options = null;
24
  private static String propertiesFile = "edu.ucsb.nceas.metacat.metacat";
25

    
26
  /**
27
   * Construct an instance of the utility class
28
   */
29
  public MetaCatUtil() {
30
    options = (PropertyResourceBundle)
31
          PropertyResourceBundle.getBundle(propertiesFile);
32
  }
33

    
34
  /** 
35
   * Utility method to establish a JDBC database connection using connection
36
   * info from the properties file
37
   */
38
  public Connection openDBConnection()
39
                throws SQLException, ClassNotFoundException {
40
    return openDBConnection(getOption("dbDriver"), getOption("defaultDB"),
41
                     getOption("user"), getOption("password"));
42
  }
43

    
44
  /** 
45
   * Utility method to establish a JDBC database connection 
46
   *
47
   * @param dbDriver the string representing the database driver
48
   * @param connection the string representing the database connectin parameters
49
   * @param user name of the user to use for database connection
50
   * @param password password for the user to use for database connection
51
   */
52
  public static Connection openDBConnection(String dbDriver, String connection,
53
                String user, String password)
54
                throws SQLException, ClassNotFoundException {
55

    
56
     // Load the Oracle JDBC driver
57
     Class.forName (dbDriver);
58

    
59
     // Connect to the database
60
     Connection conn = DriverManager.getConnection( connection, user, password);
61
     return conn;
62
  }
63

    
64
  /** 
65
   * Utility method to get an option value from the properties file
66
   *
67
   * @param option_name the name of the option requested
68
   */
69
  public String getOption(String option_name) {
70
      // Get the configuration file information
71
      if (options == null) {
72
        options = (PropertyResourceBundle)
73
          PropertyResourceBundle.getBundle(propertiesFile);
74
      }
75
      String value = (String)options.handleGetObject(option_name);
76
      return value;
77
  }
78
}
(17-17/20)