The point is where are you calling peek(), I guess.
When you call addFactoryCreate() you are only setting the rules for parsing.
The effective call to the FactoryCreateRule is made during the parsing of a XML. At that time, the only chance to call peek() is inside a method call or object constructor or any code the parsing triggers for execution.
Maybe I am pointing the obvious but you can not write :
digester.addObjectCreate("pattern", TemplateMappingEntity.class);
Object obj=digester.peek();
digester.addSetNext(....);
and expect peek() to be called between the instantiation of the two rules!
Regards, Testa Marc Lustig wrote:
Thanks Simon for reply. It's really weird because the log trace seems to properly instantiate my class:
74458 [main] DEBUG org.apache.commons.digester.Digester - New match='TemplateMappingProcessor/MappingEntity'
74460 [main] DEBUG org.apache.commons.digester.Digester - Fire begin() for FactoryCreateRule[className=null, attributeName=null, [EMAIL PROTECTED]
74463 [main] DEBUG org.apache.commons.digester.Digester - [FactoryCreateRule]
{TemplateMappingProcessor/MappingEntity} New com.infodesire.v20.templating.mappingprocessor.TemplateMappingEntity
but still when I call peek _immediately_ after the call to addFactoryCreate()
I do get not this object , but the object that was formerly added to the stack via push() method.
Anymore hint ? Thanks. Marc
Am Dienstag, 6. Juli 2004 00:54 schrieb Simon Kitching:
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 <root> <foo> <bar> ... </bar> </foo> </root>
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 object.
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 log4j.properties file in the classpath.
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
------------------------------------------------------------------------------------------------------------------- Este correo electr�nico y, en su caso, cualquier fichero anexo al mismo, contiene informaci�n de car�cter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgaci�n, copia o distribuci�n a terceros sin la previa autorizaci�n escrita de Indra. En el caso de haber recibido este correo electr�nico por error, se ruega notificar inmediatamente esta circunstancia mediante reenv�o a la direcci�n electr�nica del remitente.
The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
