KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > espada > bugtracker > util > PropertyFactory


1 /*
2  * PropertyFactory.java
3  *
4  * Created on April 17, 2001, 1:10 AM
5  */

6
7 package com.espada.bugtracker.util;
8 import java.util.*;
9 import java.io.*;
10
11 /**
12  *This class serves as a container for the bugtracker properties file.
13  *This has to be initialized the first time the application is run.
14  *
15  *An example would be to put the following in your Start servlet (the
16  *entry point into the application).
17  *
18  *<pre>
19  *
20  *if ( ! PropertyFactory.isInitialized() )
21  * PropertyFactory.readProperties(
22  * getServletContext().getRealPath(
23  * getServletContext().getInitParameter("propfile")
24  * )
25  * );
26  *
27  *</pre>
28  *
29  *The applications would need to be restarted any time any of the
30  *properties have been changed.
31  *
32  *
33  * @author Manik Surtani (manik@post1.com)
34  * @version 0.2beta3
35  */

36 public class PropertyFactory extends java.lang.Object JavaDoc {
37
38     private static Properties _props;
39     /** Creates new PropertyFactory */
40     public PropertyFactory() {
41     }
42     
43     public static Properties getInstance()
44         throws PropertiesNotReadException
45     {
46         if (! isInitialized() )
47             throw new PropertiesNotReadException("have you set the properties file using readProperties() at least once in the instance of this app?");
48         return _props;
49     }
50     
51     public static boolean isInitialized()
52     {
53         return (_props != null);
54     }
55     
56     public static void readProperties( String JavaDoc fname )
57         throws IOException
58     {
59         readProperties(new FileInputStream(fname));
60     }
61     
62     public static void readProperties( InputStream ips )
63         throws IOException
64     {
65         _props = new Properties();
66         _props.load(ips);
67     }
68     
69     public static void readProperties( Properties p )
70     {
71         _props = new Properties(p);
72     }
73
74 }
75
Popular Tags