Source code: org/acs/damsel/srvr/Damsel.java
1 package org.acs.damsel.srvr;
2
3 import java.sql.*;
4
5 import org.acs.damsel.srvr.db.*;
6 import org.apache.log4j.*;
7
8 /**
9 * <p>Title: Damsel</p>
10 * <p>Description: Damsel is a singleton class (i.e., only one copy of it
11 * exists at a time) that mediates between the application and services layers.</p>
12 * @version 1.0
13 */
14 public class Damsel {
15
16 private static Damsel instance = null;
17 private Logger log = Logger.getLogger(Damsel.class);
18
19 private Damsel() {
20 BasicConfigurator.resetConfiguration();
21 PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
22 }
23
24 /**
25 * The instance() method is used instead of a constructor to get a handle on
26 * the Damsel object. If the Damsel instance is null, then it is initialized
27 * using the default constructor.
28 * @return a handle on the Damsel object
29 */
30 public synchronized static Damsel instance() {
31 if(instance == null) {
32 instance = new Damsel();
33 }
34 return instance;
35 }
36
37 /**
38 * getAssetDB() returns a handle on the AssetDB using that class's instance()
39 * method because AssetDB is a singleton.
40 * @return a handle on the AssetDB object, null if a SQLException is thrown
41 */
42 public AssetDB getAssetDB() {
43 try {
44 return AssetDB.instance();
45 }
46 catch (SQLException ex) {
47 log.error("Unexpected SQLException getting AssetDB instance.");
48 return null;
49 }
50 }
51 }