commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [digester] how to use peek() to get object from top of stack ? bug??
Date Mon, 05 Jul 2004 22:54:28 GMT
On Tue, 2004-07-06 at 04:50, Marc Lustig wrote:
> Hi,
> I'm having trouble to use peek() to get the object from top of the stack.
> I say 
> digester.push(this);
> Alright, peek() is returning the object from the stack properly. 
> Now I add another object to the stack:
> digester.addObjectCreate("pattern", TemplateMappingEntity.class);
> ... and now peek() is NOT giving me back an instance of TemplateMappingEntity!
> WHY ?   (of course the pattern exists)

I don't know why you're not seeing the correct object. What you are
describing seems to be the correct way to use the digester. And peek
works fine - if it didn't, the Digester simply wouldn't work at all, and
quite a lot of people would notice that :-)

When exactly are you doing the peek? I hope you're aware that the object
will be on the stack only between the start tag of the element specified
by the pattern and the matching end tag.

eg for
  digester.addObjectCreate("foo/bar", MyClass.class);
and input

the MyClass instance is created and pushed on the stack when <bar> is
encountered in the input, and popped when </bar> is encountered. If you
need to refer to the object after its end tag, you need to use
SetNextRule to tell the parent object to store a reference to the

> I tried also using a factory to add an object to the stack:
> digester.addFactoryCreate("pattern", new MappingEntityFactory());
> In this case as well peek() is NOT returning the instance that is delivered by 
> the createObject() method of my factory.

It should.

> What is wrong with the peek() method??

There definitely isn't anything wrong with the peek method. There must
be something odd in your code or environment, but I can't think what it
might be.

I suggest you enable debugging output for digester and have a look at
the generated information. The simplest way to enable logging is to run
java with:
  java \
 -D org.apache.commons.logging.Log=\
     org.apache.commons.logging.impl.SimpleLog \
 -D org.apache.commons.logging.simplelog.defaultlog=debug \

Alternatives include putting log4j.jar in the classpath, and then also
putting a log4j.xml or file in the classpath.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message