commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Samuel Cheung <SChe...@Novarra.com>
Subject RE: [digester] Set attribute in a static class
Date Tue, 27 Jan 2004 21:47:18 GMT
Thanks Robert.

But if I have 50 static attributes in my Globals, do I need to create 1
custom Rule per attribute?


-----Original Message-----
From: robert burrell donkin
[mailto:robertburrelldonkin@blueyonder.co.uk]
Sent: Tuesday, January 27, 2004 3:43 PM
To: Jakarta Commons Users List
Subject: Re: [digester] Set attribute in a static class


hi samual

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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message