|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.locomotive.server.MultiConfig
A handy config file that allows the specification of multiple values per name and the reading of data either from the method call data passed in or from a file path specified. After parsing the config data you can then get them with the traditional getString and getInt methods found in org.locomotive.server.Config or you can ask for specific indexes. You should extend this class and override the setupDefaults function to make your own configs. This version does not use string constraints. Nor does it have any command line stuff. Nor does it print to standard out. As such, errors are reported (as they kind of are in the old Config) with exceptions and the like, so watch those ConfigInitializationException's and ConfigNotFoundException's. It does some constraining based on type. The strings that represent integers have to be Integer.parseInt'able, the strings have to be non-null and non-emptystring. Right now the email constraints are the same as strings, though we may put in a x@x constraint for it... It also allows you to turn off the name-checking... that is, you can have "unknown" config variables be read in and set. Override enforceConfigTypes to do this (see it for more info.) Override getDefaultConfigTypes to tell this parser what to expect on this unfamiliar lines (it won't try to guess for you...)
Field Summary | |
static int |
EMAIL
|
static int |
INTEGER
|
static int[] |
ONE_EMAIL_TYPE
|
static int[] |
ONE_INT_TYPE
|
static int[] |
ONE_STRING_TYPE
These three members are the type arrays, provided for convenience only. I.e. |
static int |
STRING
These three members STRING, INTEGER, and EMAIL are type values you can use when specifying an array of types for the addConfig method. |
static int[] |
TWO_EMAIL_TYPE
|
static int[] |
TWO_INT_TYPE
|
static int[] |
TWO_STRING_TYPE
Same as above, only containing two-in-a-row, just in case it's handy. |
Constructor Summary | |
MultiConfig(java.lang.String string_data,
boolean isFile)
Make the config object with the file path or the string data as specified. |
Method Summary | |
protected boolean |
addConfig(java.lang.String name,
java.lang.String[] vals,
int[] types,
java.lang.String desc)
Create and add a config entry to the cache we're maintaining. |
boolean |
enforceConfigTypes()
Override this function to simply return true or false. |
java.lang.String |
getConfigFilePath()
Gives us the file path this config file was constructed with (null if it was actually constructed with string config data passed in...) |
java.util.Enumeration |
getConfigNamesEnumeration()
Returns the enumeration of all the config entry names (i.e. |
java.lang.String |
getConfigStringData()
Gives us the string config data given to the config object when it was created (null if it was actually created with a file path.) |
int[] |
getDefaultConfigTypes()
If the enforceConfigNames method you implement returns false, then when the parser encoutners a strange line it will use the types specified in this method as the default form of the line. |
int |
getInt(java.lang.String name)
Gets the first element of the array of integers that come from the config entry that matches the key (i.e. |
int[] |
getIntArray(java.lang.String name)
Returns the array of integer values for the config entry matching the supplied name (i.e. |
int |
getIntByIndex(java.lang.String name,
int index)
Gets the array of integers matching the key passed in in "name" and returns the value found at the index specified - will throw an exception if the index specified is invalid for this config entry or "name" is null or "" or if the config entry found is the null object. |
java.lang.String |
getString(java.lang.String name)
Gets the first element of the array of strings that come from the config entry that matches the key (i.e. |
java.lang.String[] |
getStringArray(java.lang.String name)
Returns the array of string objects for the config entry matching the supplied name (i.e. |
java.lang.String |
getStringByIndex(java.lang.String name,
int index)
Gets the array of strings matching the key passed in in "name" and returns the string found at the index specified - will throw an exception if the index specified is invalid for this config entry or "name" is null or "" or the config entry found is the null object. |
boolean |
isFromFile()
Tells us if this config file came from a file path that we loaded. |
boolean |
isFromString()
Tells us if this config file came from string information given to it in the constructor method call. |
protected java.lang.String[] |
oneString(java.lang.String instring)
Give a string array of one element as provided. |
abstract boolean |
setupDefaults()
Override this method as shown below to set up your own configs. |
java.lang.String |
toString()
Calls the other toString with false. |
java.lang.String |
toString(boolean verbose)
Standard toString with a twist - the boolean determines if the descriptive text comes out as well. |
protected java.lang.String[] |
twoString(java.lang.String instringone,
java.lang.String instringtwo)
Give a string array of two elements as provided. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int STRING
public static final int INTEGER
public static final int EMAIL
public static final int[] ONE_STRING_TYPE
public static final int[] ONE_INT_TYPE
public static final int[] ONE_EMAIL_TYPE
public static final int[] TWO_STRING_TYPE
public static final int[] TWO_INT_TYPE
public static final int[] TWO_EMAIL_TYPE
Constructor Detail |
public MultiConfig(java.lang.String string_data, boolean isFile) throws ConfigInitializationException
string_data
- a filepath or a buffer of data in the config formatisFile
- true if string_data is a fileMethod Detail |
public abstract boolean setupDefaults()
public boolean enforceConfigTypes()
public int[] getDefaultConfigTypes()
public boolean isFromFile()
public boolean isFromString()
public java.lang.String getConfigFilePath()
public java.lang.String getConfigStringData()
protected boolean addConfig(java.lang.String name, java.lang.String[] vals, int[] types, java.lang.String desc)
name
- the name, or key, of the entry you wish to createvals
- the array of strings that represent the values you
wish to addtypes
- the array of types that describe the values you are
adding (see INTEGER, STRING, EMAIL, et. al. above for info about types).
Each type value in this array should correspond to the string value
in the same position of the array.desc
- the string description of the config entry, perhaps
containing info about each value in the array, perhaps not.public java.lang.String[] getStringArray(java.lang.String name) throws ConfigNotFoundException
name
- the name of the configpublic int[] getIntArray(java.lang.String name) throws ConfigNotFoundException
name
- the name of the configpublic java.lang.String getStringByIndex(java.lang.String name, int index) throws ConfigNotFoundException
name
- the name of the configindex
- - the position of the requested data in the string arraypublic int getIntByIndex(java.lang.String name, int index) throws ConfigNotFoundException
name
- the name of the configindex
- - the position of the requested data in the int arraypublic java.lang.String getString(java.lang.String name) throws ConfigNotFoundException
name
- the name of the configuration valuegetStringByIndex
public int getInt(java.lang.String name) throws ConfigNotFoundException
name
- the name of the configuration valuegetIntByIndex
public java.lang.String toString(boolean verbose)
public java.lang.String toString()
public java.util.Enumeration getConfigNamesEnumeration()
protected java.lang.String[] oneString(java.lang.String instring)
protected java.lang.String[] twoString(java.lang.String instringone, java.lang.String instringtwo)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |