|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcern.cmw.Config
public final class Config
This class maintains a set of the configuration properties that can be used
to customize the CMW behaviour.
The property set includes the current system properties and the properties
loaded from the CMW configuration file. The location of the configuration
file (an absolute or relative file path or a URL) can be defined using the
cmw.config or cmw.defaultConfig system properties - see load()
for
more details.
Example: the main(java.lang.String[])
method of this class
Method Summary | |
---|---|
static String |
configFile()
If loaded, returns a path or a URL of the configuration file that was used, otherwise returns null. |
static Properties |
getProperties()
Returns the current Config property set. |
static String |
getProperty(String key)
Returns the value of the property with the specified key. |
static void |
load()
Loads the CMW configuration file: the file specified by the cmw.config or cmw.defaultConfig property). |
static void |
load(String configFile)
Adds properties defined in the specified file to the Config property set. |
static boolean |
loaded()
Returns true if the configuration file has been loaded. |
static void |
main(String[] args)
For test. |
static void |
setProperty(String key,
String value)
Assigns the value to the property with the specified key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Properties getProperties()
public static String getProperty(String key)
public static void setProperty(String key, String value)
public static boolean loaded()
public static String configFile()
public static void load() throws InternalException
InternalException
- thrown if an error occured when reading from the fileload(String)
public static void load(String configFile) throws InternalException
configFile
- an absolute or relative file path, or a URL of the configuration file
InternalException
- thrown if an error occured when reading from the filepublic static void main(String[] args)
public static void main(String[] args)
{
String prefix = null;
if (args.length > 0) prefix = args[0];
//
// Load the CMW configuration file
//
try
{
Config.load();
}
catch(cern.cmw.InternalException ex)
{
System.out.println(ex.getMessage());
System.exit(0);
}
if (loaded()) System.out.println("Config loaded from: "+configFile());
else System.out.println("CMW configuration file not specified");
//
// Print properties.
// If 'prefix' is not specified print all properties, otherwise print
// only the properties with a key starting with 'prefix'.
//
System.out.println("\nPROPERTIES:\n");
java.util.Properties props = Config.getProperties();
java.util.Enumeration e = props.propertyNames();
while(e.hasMoreElements())
{
String key = (String)e.nextElement();
if (prefix != null && !key.startsWith(prefix)) continue;
System.out.println(key+" = "+Config.getProperty(key));
}
}
This function can be used to check values of the configuration
properties in your current environment.
For example:
java cern.cmw.Config
will print all configuration properties, and
java cern.cmw.Config cmw
will print properties of the "cmw" group.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |