|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--grace.util.Properties
This class wraps and augments the behaviour of the java.util.Properties class. It is not inherited from the java class because bonheaded Javasoft made the properties class inherit from Hashtable. This has many problems which I will not go into here.
Anyway, this class allows a more flexible management of properties than the java version and allows a regular expression query mechanism. Note that this mechanism is a linear search as opposed to the get functions which use the hashtable lookup.
All properties loaded into this class are copied from their original list. This makes it easier to layer properties where different priorities are intended for differernt sources of properties. Typically, one would like to make default properties from the user's home directory the lowest priority, properties from a local file the next priority, properties from the command line the next, and properties set within the application the highest.
This class also manages parameters of an Applet so that users can treat properties and parameters as the same.
So, here is a typical use:
grace.util.Properties properties = new grace.util.Properties(); properties.loadParameters(anApplet); properties.loadHomeFile(".my-home-props"); properties.loadFile(".my-local-props"); properties.loadSystem(); Vector someProps = properties.getRegexp("log.*");
Constructor Summary | |
Properties()
A new empty list. |
|
Properties(Properties properties)
Constructs a property list that is a copy of the given list. |
|
Properties(Properties properties)
Constructs a property list that is a copy of the given list. |
Method Summary | |
java.lang.String |
get(java.lang.String name)
Returns the value of the property referred to by name or null if the named property does not exist. |
java.lang.String |
get(java.lang.String[] names)
Returns a property by searching linearly for each name in the array of names. |
java.lang.String |
get(java.lang.String[] names,
java.lang.String defaultValue)
Returns a property value by searching linearly for each name in array of names. |
java.lang.String |
get(java.lang.String name,
java.lang.String defaultValue)
Returns the value of the property referred to by name or defaultValue if the named property does not exist. |
java.util.Properties |
getJavaProperties()
Returns a list of the properties. |
void |
integrateWithSystemProperties()
If this set of properties is currently not a view of the System properties, then the System properties are loaded into this (just to make sure it doesn't wipe out any System properties), and the System properties are set to this collection. |
void |
load(Properties properties)
Loads the given properties into this list by coping each property out of the given list and into this list. |
void |
load(Properties properties)
Loads the given properties into this list by coping each property out of the given list and into this list. |
boolean |
loadFile(java.lang.String propertyFilename)
Reads properties from the given file into this list. |
void |
loadHomeFile(java.lang.String basePropertyFilename)
Reads properties from the given file into this list where the given file is assumed to be located in the user.home directory. |
void |
loadSystem()
Loads a copy of the System properties (System.getProperties()) into this list. |
java.util.Enumeration |
names()
Allows interation over all of the names of properties held by this class. |
java.util.Vector |
names(gnu.regexp.RE regexp)
This returns a vector or names that match the given regular expression. |
java.util.Vector |
names(java.lang.String regexp)
This returns a vector or properties names that match the given regular expression. |
void |
put(java.lang.String name,
java.lang.String value)
Sets the value of the property referred to by name. |
void |
segregateFromSystemProperties()
If this set of properties is currently a view of the System properties, then a new interal property collection is created and the System properties are copied into the newly created collection. |
void |
set(java.util.Properties list)
Sets the list of the properties maintained by this class. |
static void |
setApplet(java.applet.Applet a)
Remembers the given applet such that all subsequent get() functions on this class will query the applet for a named parameter using the Applet.getParameter(String) call. |
void |
setSystemProperties()
This sets the System properties to the set managed by this class. |
Properties |
subset(gnu.regexp.RE regexp)
Returns a subset of this Properties list narrowed by the given regular expression. |
Properties |
subset(gnu.regexp.RE regexp,
java.lang.String nameSubstitution)
Returns a subset of this Properties list narrowed by the given regular expression but with the names substituted with the given nameSubstitution. |
Properties |
subset(java.lang.String regexp)
Returns a subset of this Properties list narrowed by the given regular expression. |
Properties |
subset(java.lang.String regexp,
java.lang.String nameSubstitution)
|
java.lang.String |
toString()
Formats all of the properties as a String. |
java.util.Enumeration |
values()
Allows interation over all of the values of properties held by this class. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public Properties()
public Properties(Properties properties)
public Properties(Properties properties)
Method Detail |
public void load(Properties properties)
public void load(Properties properties)
public static void setApplet(java.applet.Applet a)
This is static right now because I can't figure out how to handle applets.
public void loadSystem()
public boolean loadFile(java.lang.String propertyFilename)
public void loadHomeFile(java.lang.String basePropertyFilename)
public void put(java.lang.String name, java.lang.String value)
name
- of property to setpublic java.lang.String get(java.lang.String name)
name
- of property to getpublic java.lang.String get(java.lang.String name, java.lang.String defaultValue)
Note: This calls grace.util.Properties.get(String);
name
- of property to getdefaultValue
- to return if named property doesn't existpublic java.lang.String get(java.lang.String[] names)
Note: This calls grace.util.Properties.get(String[], String);
names
- sequential list of names for which to searchpublic java.lang.String get(java.lang.String[] names, java.lang.String defaultValue)
Note: This calls grace.util.Properties.get(String);
names
- sequential list of names for which to searchdefaultValue
- to return if no properties are foundpublic java.util.Vector names(java.lang.String regexp) throws gnu.regexp.REException
These results do not include parameters held by an applet. This is because of general lame design of Javasoft.
Note: calls grace.util.Properties.names(RE);
public java.util.Vector names(gnu.regexp.RE regexp)
These results do not include parameters held by an applet. This is because of general lame design of Javasoft.
public Properties subset(java.lang.String regexp) throws gnu.regexp.REException
public Properties subset(gnu.regexp.RE regexp)
public Properties subset(gnu.regexp.RE regexp, java.lang.String nameSubstitution)
For example, given a properties list of:
The call subset("variable\\.([^\.]+)\\.value",
"$1");
would result in a properties list of:
public Properties subset(java.lang.String regexp, java.lang.String nameSubstitution) throws gnu.regexp.REException
subset(RE, String)
public java.util.Enumeration names()
public java.util.Enumeration values()
public void setSystemProperties()
public void segregateFromSystemProperties()
public void integrateWithSystemProperties()
public java.lang.String toString()
public java.util.Properties getJavaProperties()
public void set(java.util.Properties list)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |