You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Frank Schaare <fs...@htp-tel.de> on 2003/11/04 17:58:43 UTC

[Digester]How to access created objects

Hi,

i try to get familiar with the digester. Therefore i read all three (not 
very much) articles mentioned on digester´s homesite and tried some code 
like this:

 public void initSQLRules()
 {
  try
  {
  Digester digester = new Digester();
  digester.push(this);
  
  digester.addObjectCreate("Abfragen",Abfragen.class);
  
  digester.addObjectCreate("Abfragen/Abfrage",Abfrage.class);
  digester.addBeanPropertySetter("Abfragen/Abfrage/Name","name");
  digester.addBeanPropertySetter("Abfragen/Abfrage/SQL","wert");
  digester.addSetNext("Abfragen/Abfrage","addAbfrage");
  
  digester.parse("my.xml");  
 
  }
  catch (Exception e)
  {
  e.printStackTrace();
  }
  
 }

This seems to work, what exactly happen here ? Obviously, the digester 
gets some rules an delegates xml parsing to a SAXParser.

How do i access (get) the generatet Bean ?
Where is the bean object createt ?

Who has information about this mysterios stack ? The Code 
'digester.push(this);' seems to put the servlet instance on a stack. 
What for ?

Are there any sites that gain a little more information as jakarta does ?

thx for your answers.


---------------------------------------------------------------------
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 access created objects

Posted by José Antonio Pérez Testa <ja...@indra.es>.
If this solution is not the best way to solve the problem, particularily 
in a servlet context, ... this is a question to another thread :)
José Antonio Pérez Testa wrote:

> You are messing up things,
> Digester knows anything about servlets, contexts, session or requests.
> I supose you have
>     public void addAbfrage(Abfrage beanObject)
> in the Abfragen class.
>
> You have ONLY to do 2 things:
> 1. put that  in your servlet ( the class that contains your 
> initSQLRules() method)
>        protected Hashtable abfragenContainer = new Hashtable();
>        public void addAbfragen(Abfragen beanContainerObject) {
>            abfragenContainer.put("Abfragen", beanContainerObject);
>        }
>
>    public void initSQLRules()
>    {
>     try
>     {
>     Digester digester = new Digester();
>     digester.push(this);
>         digester.addObjectCreate("Abfragen",Abfragen.class);
>         digester.addObjectCreate("Abfragen/Abfrage",Abfrage.class);
>     digester.addBeanPropertySetter("Abfragen/Abfrage/Name","name");
>     digester.addBeanPropertySetter("Abfragen/Abfrage/SQL","wert");
>     digester.addSetNext("Abfragen/Abfrage","addAbfrage");
>     digester.addSetNext("Abfragen","addAbfragen");
>         digester.parse("my.xml");     }
>     catch (Exception e)
>     {
>     e.printStackTrace();
>     }
>        }
>
> 2.  to get the Abfragen object :
> .........
> Abfragen myAbfragen = (Abfragen)abfragenContainer.get("Abfragen");
> ...........
>
> Frank Schaare wrote:
>
>> Hi José,
>>
>>>
>>> I'll try to explain as far as my knowdledge of Digester and my 
>>> english skills could.
>>
>>
>>
>> Your english seems to be much better then mine ;-)
>>
>> My article of reference is O'Reilly's one :
>> http://www.onjava.com/lpt/a/2746
>>
>> This is the first of three articles found on digesters home. In fact, 
>> most of my code ist taken from this article
>>
>> digester.addObjectCreate("Abfragen",Abfragen.class);
>> When <Abfragen> is found create a new Abfragen object and put it on 
>> top of stack ( above 'this' )
>>
>> I´m totally confused about this stack . How can i access this 
>> Abfragen(Bean) ? I expectet something like:
>> getServletContext().getAttribute("Abfragen");
>> seesion.getAttribute("Abfragen"); or
>> request.getAttribute("Abfragen");
>>
>> But what about the stack ?
>>
>>> if  the Abfragen class has a method called
>>> public void addAbfrage(Abfrage beanObject)
>>> you will found your beans there.
>>
>>
>>
>> hmm, but therefore, i need the Abfragen-instance. Is there a getter 
>> for the stack ?
>>
>>>     digester.addSetNext("Abfragen","addAbfragen");
>>> and add that method
>>>     public void addAbfragen(Abfragen beanContainerObject)
>>> to your servlet.
>>> Digester will call it and pass the newly created Abfragen instance 
>>> and you will have everything at your disposition.
>>
>>
>>
>> do you have a code example for this ? When i digest the xml file, i´m 
>> in ActionServlets init() method. Do i have to add another method like 
>> your description ?
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>


-------------------------------------------------------------------------------------------------------------------
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 access created objects

Posted by Frank Schaare <fs...@htp-tel.de>.
José Antonio Pérez Testa schrieb:

> You are messing up things,
> Digester knows anything about servlets, contexts, session or requests.

ok, though i can´t expect any getAttribute-methods...

> 2.  to get the Abfragen object :
> .........
> Abfragen myAbfragen = (Abfragen)abfragenContainer.get("Abfragen");
> ...........
>
i will try this tomorrow at work. Thank you very much for your fast 
replies.
muchas gracias


---------------------------------------------------------------------
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 access created objects

Posted by José Antonio Pérez Testa <ja...@indra.es>.
You are messing up things,
Digester knows anything about servlets, contexts, session or requests.
I supose you have
     public void addAbfrage(Abfrage beanObject)
in the Abfragen class.

You have ONLY to do 2 things:
 1. put that  in your servlet ( the class that contains your 
initSQLRules() method)
        protected Hashtable abfragenContainer = new Hashtable();
        public void addAbfragen(Abfragen beanContainerObject) {
            abfragenContainer.put("Abfragen", beanContainerObject);
        }

    public void initSQLRules()
    {
     try
     {
     Digester digester = new Digester();
     digester.push(this);
     
     digester.addObjectCreate("Abfragen",Abfragen.class);
     
     digester.addObjectCreate("Abfragen/Abfrage",Abfrage.class);
     digester.addBeanPropertySetter("Abfragen/Abfrage/Name","name");
     digester.addBeanPropertySetter("Abfragen/Abfrage/SQL","wert");
     digester.addSetNext("Abfragen/Abfrage","addAbfrage");
     digester.addSetNext("Abfragen","addAbfragen");
     
     digester.parse("my.xml"); 
     }
     catch (Exception e)
     {
     e.printStackTrace();
     }
     
    }

 2.  to get the Abfragen object :
.........
Abfragen myAbfragen = (Abfragen)abfragenContainer.get("Abfragen");
...........

Frank Schaare wrote:

> Hi José,
>
>>
>> I'll try to explain as far as my knowdledge of Digester and my 
>> english skills could.
>
>
> Your english seems to be much better then mine ;-)
>
> My article of reference is O'Reilly's one :
> http://www.onjava.com/lpt/a/2746
>
> This is the first of three articles found on digesters home. In fact, 
> most of my code ist taken from this article
>
> digester.addObjectCreate("Abfragen",Abfragen.class);
> When <Abfragen> is found create a new Abfragen object and put it on 
> top of stack ( above 'this' )
>
> I´m totally confused about this stack . How can i access this 
> Abfragen(Bean) ? I expectet something like:
> getServletContext().getAttribute("Abfragen");
> seesion.getAttribute("Abfragen"); or
> request.getAttribute("Abfragen");
>
> But what about the stack ?
>
>> if  the Abfragen class has a method called
>> public void addAbfrage(Abfrage beanObject)
>> you will found your beans there.
>
>
> hmm, but therefore, i need the Abfragen-instance. Is there a getter 
> for the stack ?
>
>>     digester.addSetNext("Abfragen","addAbfragen");
>> and add that method
>>     public void addAbfragen(Abfragen beanContainerObject)
>> to your servlet.
>> Digester will call it and pass the newly created Abfragen instance 
>> and you will have everything at your disposition.
>
>
> do you have a code example for this ? When i digest the xml file, i´m 
> in ActionServlets init() method. Do i have to add another method like 
> your description ?
>
>
>
>
> ---------------------------------------------------------------------
> 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 access created objects

Posted by Frank Schaare <fs...@htp-tel.de>.
Hi José,

>
> I'll try to explain as far as my knowdledge of Digester and my english 
> skills could.

Your english seems to be much better then mine ;-)

My article of reference is O'Reilly's one :
http://www.onjava.com/lpt/a/2746

This is the first of three articles found on digesters home. In fact, 
most of my code ist taken from this article

digester.addObjectCreate("Abfragen",Abfragen.class);
When <Abfragen> is found create a new Abfragen object and put it on top 
of stack ( above 'this' )

I´m totally confused about this stack . How can i access this 
Abfragen(Bean) ? I expectet something like:
getServletContext().getAttribute("Abfragen");
seesion.getAttribute("Abfragen"); or
request.getAttribute("Abfragen");

But what about the stack ?

> if  the Abfragen class has a method called
> public void addAbfrage(Abfrage beanObject)
> you will found your beans there.

hmm, but therefore, i need the Abfragen-instance. Is there a getter for 
the stack ?

>     digester.addSetNext("Abfragen","addAbfragen");
> and add that method
>     public void addAbfragen(Abfragen beanContainerObject)
> to your servlet.
> Digester will call it and pass the newly created Abfragen instance and 
> you will have everything at your disposition.

do you have a code example for this ? When i digest the xml file, i´m in 
ActionServlets init() method. Do i have to add another method like your 
description ?




---------------------------------------------------------------------
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 access created objects

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Hi Frank,
I'll try to explain as far as my knowdledge of Digester and my english 
skills could.
My article of reference is O'Reilly's one :
http://www.onjava.com/lpt/a/2746

Frank Schaare wrote:

> Hi,
>
> i try to get familiar with the digester. Therefore i read all three 
> (not very much) articles mentioned on digester´s homesite and tried 
> some code like this:
>
> public void initSQLRules()
> {
>  try
>  {
>  Digester digester = new Digester();
>  digester.push(this);

Put 'this' on top of the stack.

>  
>  digester.addObjectCreate("Abfragen",Abfragen.class);

When <Abfragen> is found create a new Abfragen object and put it on top 
of stack ( above 'this' )

>  
>  digester.addObjectCreate("Abfragen/Abfrage",Abfrage.class);

When <Abfragen><Abfrage> is found create a new Abfrage object and put it 
on top of stack ( above the Abfragen instance )

>  digester.addBeanPropertySetter("Abfragen/Abfrage/Name","name");

When found the path "Abfragen/Abfrage/Name" call setter method 
'setName()' on current stack top object ( that is the Abfrage instance)
passing the value taken from the xml element Name converted to the 
argument type of the setName method.

>  digester.addBeanPropertySetter("Abfragen/Abfrage/SQL","wert");

idem

>  digester.addSetNext("Abfragen/Abfrage","addAbfrage");

When </Abfrage> is found, remove current stack top object ( that is the 
Abfrage instance) and pass it as parameter to the addAbfrage() method of 
the actual
stack top object  ( the Abfragen instance )

>  
>  digester.parse("my.xml"); 

Tell digester to parse the file my.xml.

>  }
>  catch (Exception e)
>  {
>  e.printStackTrace();
>  }
>  
> }
>
> This seems to work, what exactly happen here ? Obviously, the digester 
> gets some rules an delegates xml parsing to a SAXParser.

Digester gets the rules that you are set in code

>
> How do i access (get) the generatet Bean ?

if  the Abfragen class has a method called
public void addAbfrage(Abfrage beanObject)
you will found your beans there.
Otherwise Digester will write a log saying that it couldn't find the method

> Where is the bean object createt ?

I think I've explained that above.

>
> Who has information about this mysterios stack ? 

If you enable tracing, you will get detailed information of what is 
going on during the parsing of the xml file.

> The Code 'digester.push(this);' seems to put the servlet instance on a 
> stack. What for ?

In order to keep track of the last object taken from the stack. You have 
to put another rule like

     digester.addSetNext("Abfragen","addAbfragen");
and add that method
     public void addAbfragen(Abfragen beanContainerObject)
to your servlet.
Digester will call it and pass the newly created Abfragen instance and 
you will have everything at your disposition.

>
> Are there any sites that gain a little more information as jakarta does ?
>
> thx for your answers.
>
>
> ---------------------------------------------------------------------
> 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 access created objects

Posted by Frank Schaare <fs...@htp-tel.de>.
Hi Simon,

>You may wish to check out the current digester source code from the cvs
>repository, or use CVSWeb to browse it.
>
>You will find code in src/examples/api which may be useful to you.
>  
>
that is a very goog tip, i´ll try it. It is definetly a good idea to add 
some examples to next release because all three articles don´t deal with 
accessing the objects.

>The way digester is generally used is that you give it some rules and
>some input xml, and it generates a tree of objects. You never need to
>access the digester "stack" from your code; you just get the object
>representing the root of the tree and use its methods.
>  
>
yes, that was a little confusing to me. I actually saw some Java code 
before 'crawling' through the commons sources, but never this stack 
stuff. I just dealt with stacks by handling exceptions without any need 
to get closer as e.printStackTrace(). I don´t remenber any other class 
pushing and polling objects to/from stack, so i just expectet some 
methods like getStack(i) or whatever. Time to learn something new ;-)


---------------------------------------------------------------------
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 access created objects

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi Frank,

You may wish to check out the current digester source code from the cvs
repository, or use CVSWeb to browse it.

You will find code in src/examples/api which may be useful to you.

These examples were added since the last release, so you'll need to
access them from the cvs repository. See the jakarta website for
instructions on how to do this.

Just a general note: Digester is not related to servlets in any way. It
can be used within a servlet if you wish, or used in applications that
have nothing to do with servlets. 

The way digester is generally used is that you give it some rules and
some input xml, and it generates a tree of objects. You never need to
access the digester "stack" from your code; you just get the object
representing the root of the tree and use its methods.

Note that by "tree" I don't mean that Digester generates an explicit
tree. If your objects represent the data in the xml input file, then by
definition your objects represent a tree, because that is how xml is
structured. All the articles you reference demonstrate this, as do the
examples in cvs.

Regards,

Simon

On Wed, 2003-11-05 at 05:58, Frank Schaare wrote:
> Hi,
> 
> i try to get familiar with the digester. Therefore i read all three (not 
> very much) articles mentioned on digester´s homesite and tried some code 
> like this:
> 
>  public void initSQLRules()
>  {
>   try
>   {
>   Digester digester = new Digester();
>   digester.push(this);
>   
>   digester.addObjectCreate("Abfragen",Abfragen.class);
>   
>   digester.addObjectCreate("Abfragen/Abfrage",Abfrage.class);
>   digester.addBeanPropertySetter("Abfragen/Abfrage/Name","name");
>   digester.addBeanPropertySetter("Abfragen/Abfrage/SQL","wert");
>   digester.addSetNext("Abfragen/Abfrage","addAbfrage");
>   
>   digester.parse("my.xml");  
>  
>   }
>   catch (Exception e)
>   {
>   e.printStackTrace();
>   }
>   
>  }
> 
> This seems to work, what exactly happen here ? Obviously, the digester 
> gets some rules an delegates xml parsing to a SAXParser.
> 
> How do i access (get) the generatet Bean ?
> Where is the bean object createt ?
> 
> Who has information about this mysterios stack ? The Code 
> 'digester.push(this);' seems to put the servlet instance on a stack. 
> What for ?
> 
> Are there any sites that gain a little more information as jakarta does ?
> 
> thx for your answers.
> 
> 
> ---------------------------------------------------------------------
> 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