Added instantiateValue() to facilitate instantiating a class via
Class.forName() where the class name is obtained from a config value. git-svn-id: https://samskivert.googlecode.com/svn/trunk@200 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Config.java,v 1.2 2001/07/12 18:13:19 mdb Exp $
|
// $Id: Config.java,v 1.3 2001/07/21 00:50:28 shaper Exp $
|
||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ public class Config
|
|||||||
* integer, not in proper array specification), a warning message will
|
* integer, not in proper array specification), a warning message will
|
||||||
* be logged and the default value will be returned.
|
* be logged and the default value will be returned.
|
||||||
*
|
*
|
||||||
* @param the fully qualified name of the property (fully qualified
|
* @param key the fully qualified name of the property (fully qualified
|
||||||
* meaning that it contains the namespace identifier as well), for
|
* meaning that it contains the namespace identifier as well), for
|
||||||
* example: <code>foo.bar.baz</code>.
|
* example: <code>foo.bar.baz</code>.
|
||||||
* @param defval the value to return if the property is not specified
|
* @param defval the value to return if the property is not specified
|
||||||
@@ -188,6 +188,26 @@ public class Config
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks up the specified string-valued configuration entry,
|
||||||
|
* loads the class with that name and instantiates a new instance
|
||||||
|
* of that class, which is returned.
|
||||||
|
*
|
||||||
|
* @param key the fully qualified name of the property (fully qualified
|
||||||
|
* meaning that it contains the namespace identifier as well), for
|
||||||
|
* example: <code>foo.bar.baz</code>.
|
||||||
|
* @param defcname the class name to use if the property is not
|
||||||
|
* specified in the config file.
|
||||||
|
*
|
||||||
|
* @exception Exception thrown if any error occurs while loading
|
||||||
|
* or instantiating the class.
|
||||||
|
*/
|
||||||
|
public Object instantiateValue (String name, String defcname)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
return Class.forName(getValue(name, defcname)).newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator that returns all of the configuration keys that
|
* Returns an iterator that returns all of the configuration keys that
|
||||||
* match the specified prefix. The prefix should at least contain a
|
* match the specified prefix. The prefix should at least contain a
|
||||||
|
|||||||
Reference in New Issue
Block a user