View Javadoc

1   /*
2   Copyright (c) 2005 The European Bioinformatics Institute, and others.
3   All rights reserved. Please see the file LICENSE
4   in the root directory of this distribution.
5   */
6   package uk.ac.ebi.intenz.tools.sib;
7   
8   import org.apache.log4j.Logger;
9   
10  import java.util.PropertyResourceBundle;
11  import java.io.InputStream;
12  import java.io.IOException;
13  import java.io.FileInputStream;
14  
15  
16  /**
17   * ApplicationResources provides various property resources required to
18   * run the applications.<br/>
19   * The application will not run unless their is a file called
20   * <em>application.properties</em>. In it the following properties are
21   * required.<br/>
22   * application.export.fileName<br/>
23   * application.input.fileName<br/>
24   * application.db.config<br/>
25   * application.xml.file<br/>
26   *
27   * @author P. de Matos
28   * @version $id 19-Jul-2005 13:50:34
29   *          <p/>
30   *          History:<br>
31   *          <table>
32   *          <tr><th>Developer</th><th>Date</th><th>Description</th></tr>
33   *          <tr><td>P.de Matos</td><td>19-Jul-2005</td><td>Created class</td></tr>
34   *          </table>
35   */
36  public class ApplicationResources extends PropertyResourceBundle {
37  
38     private static Logger LOGGER =
39  	   Logger.getLogger(ApplicationResources.class.getName());
40  
41     static ApplicationResources resources;
42  
43     /**
44      * Creates a property resource bundle.
45      *
46      * @param stream property file to read from.
47      */
48     private ApplicationResources (InputStream stream) throws IOException {
49        super(stream);
50     }
51  
52     /**
53      * Singleton method to create a single instance of the application
54      * resources.<br/>
55      * The system will exit if the application resources is unable to be created.<br/>
56      * @return
57      */
58     public static ApplicationResources getInstance () {
59        if ( resources == null ) {
60           synchronized ( ApplicationResources.class ) {
61              if ( resources == null ) {
62                 try {
63  				   //FileInputStream in = new FileInputStream(
64                     //     ApplicationResources.class.getClassLoader().getResource("application.properties").getPath());
65  				   InputStream in = ApplicationResources.class.getClassLoader()
66  					   .getResourceAsStream("application.properties");
67                    resources = new ApplicationResources(in);
68                 } catch ( IOException e ) {
69                    LOGGER.fatal("Application properties file could not be loaded.", e);
70                    System.exit(1);
71                 }
72              }
73           }
74        }
75        return resources;
76     }
77  
78     // GETTERS //
79  
80     public String getDbUrl(){
81         return resources.getString("application.db.url");
82     }
83  
84     public String getDbUserName(){
85        return resources.getString("application.db.login");
86     }
87  
88     public String getDbPassword(){
89        return resources.getString("application.db.password");
90     }
91  
92      public String getDbConfig(){
93          return resources.getString("application.db.config");
94      }
95  
96     public String getInputFlatFileName(){
97        return resources.getString("application.input.fileName");
98     }
99  
100    public String getExportFlatFileName(){
101       return resources.getString("application.export.fileName");
102    }
103 
104    public String getSpecialCharactersFileName(){
105       return resources.getString("application.xml.file");
106    }
107 
108 }