KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > igfay > jfig > JFigIF


1 package org.igfay.jfig;
2
3 import java.util.List JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.util.Properties JavaDoc;
6
7 /**
8  * Interface for JFig
9  *
10  * The JFig package provides very simple, flexible and powerful
11  * functionality for managing one or more configurations in a java environment.
12  *
13  * <P>It allows for a combination of a hierarchy of configuration files,
14  * substitution variables and property variables. Methods are provided to get
15  * values stored in a configuration dictionary with a variety of types (String,
16  * array, integer, float, boolean, etc) and default values.
17  *<P>
18  * Usage:
19  * <BR>To get an instance of the JFig singleton, use:
20  * JFig. getInstance();
21  *
22  * <P>There are a number of helper methods to retrieve configuration values. The
23  * most common is:
24  * <BR>String value = JFig. getInstance().getValue ("aSection","aKey","aDefaultValue");
25  *
26  * <P>See the javadocs for additional helper methods to retrieve values as
27  * different java types and with different exception handling.
28  *
29  *@author bconrad
30  *@created July 10, 2003
31  */

32 public interface JFigIF {
33     /**
34      * Add ConfigEvent listeners to vector so they can be notified when there
35      * is a significant change in the configuration.
36      *
37      *@param listener The feature to be added to the ConfigEventListener
38      * attribute
39      */

40     public abstract void addConfigEventListener(JFigListener listener);
41     /**
42      * Print the values in the configuration dictionary.
43      */

44     public abstract void print();
45     /**
46      * Print the values in the configuration dictionary.
47      * @deprecated
48      */

49     public abstract void printConfigurationDictionary();
50     /**
51      * reprocess the configuration creating a new config dictionary
52      */

53     public abstract void reprocessConfiguration() throws JFigException;
54     /**
55      * reprocess the configuration creating a new config dictionary
56      */

57     public abstract void reprocessConfiguration(JFigLocator locator) throws JFigException;
58     /**
59      * return the ConfigurationDictionary
60      * Made public so we can access this from a jsp and show the configuration
61      * via html.
62      */

63     public abstract JFigDictionary getConfigDictionary();
64     /**
65      * convenience method for getting values as array
66      * The value is tokenized depending on the first token found in
67      * the following order: comma, semicolon, colon, space
68      *
69      */

70     public abstract String JavaDoc[] getArrayValue(String JavaDoc section, String JavaDoc key)
71         throws JFigException;
72     /**
73       * convenience method for getting values as boolean
74       */

75     public abstract boolean getBooleanValue(
76         String JavaDoc section,
77         String JavaDoc key,
78         String JavaDoc notFoundValue);
79     /**
80      * getFloatValue() convenience method for getting values as float
81      *
82      *@param section Description of Parameter
83      *@param key Description of Parameter
84      *@param notFoundValue Description of Parameter
85      *@return The FloatValue value
86      *@exception JFigException Description of Exception
87      */

88     public abstract float getFloatValue(
89         String JavaDoc section,
90         String JavaDoc key,
91         String JavaDoc notFoundValue)
92         throws JFigException;
93     /**
94      * convenience method for getting values as int
95      */

96     public abstract int getIntegerValue(String JavaDoc section, String JavaDoc key)
97         throws JFigException;
98     /**
99      * convenience method for getting values as int, with default value
100      */

101     public abstract int getIntegerValue(
102         String JavaDoc section,
103         String JavaDoc key,
104         String JavaDoc notFoundValue);
105     /**
106      * First look in given section. Try again for default section.
107      *
108      *@param section Description of Parameter
109      *@param key Description of Parameter
110      *@param defaultValue Description of Parameter
111      *@return The Value value
112      */

113     public abstract String JavaDoc getValue(
114         String JavaDoc section,
115         String JavaDoc key,
116         String JavaDoc defaultValue);
117     /**
118      * Return a list of all values starting with "key" in the scetcion.
119      * If section xxx contains x.1, x.2, and x.3,
120      * getValuesStartingWith("xxx", "x.") returns a list containing
121      * x.1, x.2, and x.3.
122      *
123      * @param section
124      * @param key
125      * @param defaultValue
126      * @return List
127      */

128     public abstract List JavaDoc getValuesStartingWith(String JavaDoc section, String JavaDoc key);
129     /**
130      * Return a map of all values starting with "key" in the scetcion.
131      * If section xxx contains x.1=a, x.2=b, and x.3=c,
132      * getValuesStartingWith("xxx", "x.") returns a map containing
133      * x.1,a x.2,b and x.3,c.
134      *
135      * @param section
136      * @param key
137      * @param defaultValue
138      * @return List
139      */

140     public Map JavaDoc getEntriesStartingWith(String JavaDoc section, String JavaDoc key);
141
142     /**
143      * Call configParser to get the value for a key in a given section.
144      *
145      */

146     public abstract String JavaDoc getValue(String JavaDoc section, String JavaDoc key)
147         throws JFigException;
148
149     /**
150      * Return an entire section
151      * @param section
152      * @return
153      */

154     public Map JavaDoc getSection(String JavaDoc section);
155
156
157     /**
158      * Return a section converted to a Properties object (but not system properties)
159      * @param section
160      * @return
161      */

162     public abstract Properties JavaDoc getSectionAsProperties(String JavaDoc section);
163     
164     /**
165      * Return a section added to the supplied Properties object
166      * @param section
167      * @return
168      */

169     public abstract Properties JavaDoc getSectionAsProperties(String JavaDoc section, Properties JavaDoc properties);
170
171     /**
172      * Set a configuration value.
173      * Most values are set during initial parsing so this is rarely used.
174      */

175     public abstract void setConfigurationValue(
176         String JavaDoc sectionName,
177         String JavaDoc keyString,
178         String JavaDoc valueString);
179     /**
180      * convenience method for getting values as array with default value
181      */

182     public abstract String JavaDoc[] getArrayValue(
183         String JavaDoc section,
184         String JavaDoc key,
185         String JavaDoc notFoundValue);
186 }
Popular Tags