i'd recommend using a custom Rule implementation for something like this.
for example, given a class like (say)
public class Globals
{
public static String SOME_GLOBAL_SETTING;
}a custom rule to set it from the 'some' attribute would be something like this:
public SetGlobalsRule extends Rule {
public void begin(String namespace, String name, Attributes attributes) {
Globals.SOME_GLOBAL_SETTING = attribute.getValue("some");
}
}
- robert
On 27 Jan 2004, at 16:09, Samuel Cheung wrote:
Hi,
I would like to use Digester to set attribute in my static class. So I create my own ObjectCreationFactory (child class of AbstractObjectCreationFactory) to return the static object.
But when I set the attribute of the Static object by using addCallParam(), I
got exception:
Jan 27, 2004 12:32:49 AM org.apache.commons.digester.Digester peekParams
WARNING: Empty stack (returning null)
Jan 27, 2004 12:32:49 AM org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
java.lang.NullPointerException
at org.apache.commons.digester.CallParamRule.end(CallParamRule.java:288)
at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
at org.apache.crimson.parser.Parser2.content(Unknown Source)
at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
at org.apache.crimson.parser.Parser2.content(Unknown Source)
at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
Here is my code to load the config:
public void loadConfig(File configFile) throws IOException, SAXException
{
Digester digester = new Digester();
digester.addFactoryCreate("sysconfig",
sysconfigObjCreationFactory);
digester.addFactoryCreate("sysconfig/comp1", comp1configObjCreationFactory);
digester.addCallParam( "sysconfig/comp1/parameter1", 0 );
SysConfig sysConfig = (SysConfig) digester.parse(configFile); }
I appreciate if anyone can help me on this issue.
Thanks in advance.
Sam
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
