You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Marc Lustig <ma...@infodesire.com> on 2004/07/05 18:50:53 UTC

[digester] how to use peek() to get object from top of stack ? bug??

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 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.

What is wrong with the peek() method??
How can I get the object that is on top of the stack?

Regards
  Marc




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [digester] how to use peek() to get object from top of stack ? bug??

Posted by Marc Lustig <ma...@infodesire.com>.
Thanks much Testa. I wasn't really aware that there are actually two different 
kinds of runtime levels to operate on. One the event definition and the other 
the actual processing.
What I did is putting my peek() statement into my factory method and now it 
seems to work properly.
public Object createObject(Attributes attributes) throws Exception {
		TemplateMappingEntity e = (TemplateMappingEntity) getDigester().peek();
		return e.new PropertyMapping();
}

The whole issue was arising because I need to instaniate an inner class of an 
object that is build on parsing runtime.

Regards
Marc

Am Dienstag, 6. Juli 2004 10:38 schrieb José Antonio Pérez Testa:
> Hi Marc,
> 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,
> >creationFactory=com.infodesire.v20.templating.mappingprocessor.MappingEnti
> >tyFactory@1681ea] 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: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------------
>---------------------------------------- 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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [digester] how to use peek() to get object from top of stack ? bug??

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Hi Marc,
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, 
>creationFactory=com.infodesire.v20.templating.mappingprocessor.MappingEntityFactory@1681ea]
>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: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>
-------------------------------------------------------------------------------------------------------------------
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [digester] how to use peek() to get object from top of stack ? bug??

Posted by Marc Lustig <ma...@infodesire.com>.
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, 
creationFactory=com.infodesire.v20.templating.mappingprocessor.MappingEntityFactory@1681ea]
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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [digester] how to use peek() to get object from top of stack ? bug??

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org