You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ray Madigan <ra...@madigans.org> on 2004/11/29 07:35:36 UTC

[digester] Help needed

I have not been using the digester for a long time, but up until now I have
been able to figure out everything on my own.  I have a situation that I
don't know if it can be done the way I want to do it,  So I thought I would
ask.

The xml I want to digest looks like

<tran>
  <processMap>
    <process name="A">
        <top>"AB"</top>
        <top>"AC"</top>
        <top>"AD"</top>
    </process>
    <process name="C">
        <top>"AB"</top>
        <top>"CC"</top>
        <top>"AD"</top>
    </process>
    <process name="F">
        <top>"CB"</top>
        <top>"AC"</top>
        <top>"FD"</top>
    </process>
  </processMap>
</tran>

The class I want to fill in is like

public class processMap {
    private HashMap map;

    public processMap ( ) {
    }

    public void setProcessMap ( HashMap map ) {
        this.map = map;
    }

    public HashMap getProcessMap ( ) {
        return map;
    }
}

The digester rules are like

// Create the HashMap and push it on the stack
addObjectCreate ( "tran/processMap", HashMap.class );

// Create the ArrayList and push it on the stack
addObjectCreate ( "tran/processMap/process", ArrayList );
//
//  Don't know how to get to the process attribute name
//  Don't know how to call HashMap.put with the key as the
//  process attribute name value ant the value as the ArrayList
//  that is currently at the top of the stack

//  Add the top values to the array list
addCallMethod ( "tran/processMap/process/top", add, 1 );
addCallParam ( "tran/processMap/process/top", 0 );


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


RE: [digester] Help needed

Posted by Ray Madigan <ra...@madigans.org>.
I should have posted earlier but I solved the problem very simply.

Digester is a great tool!

addObjectCreate ( "tran/processMap", HashMap.class );

addCallMethod ( "tran/processMap/process/top", put, 2 );
// The first argument is from the name attribute
addCallParam ( "tran/processMap/process/top", 0, "name" );

// Create the HashMap and put it on the stack
addObjectCreate ( "tran/processMap/process", ArrayList );
// The second argument to put is the top of the stack object
addCallParam ( "tran/processMap/process/top", 2, 0 );

addCallMethod ( "tran/processMap/process/top", add, 1 );
addCallParam ( "tran/processMap/process/top", 0 );

-----Original Message-----
From: José Antonio Pérez Testa [mailto:japtesta@indra.es]
Sent: Monday, November 29, 2004 12:42 AM
To: Jakarta Commons Users List
Subject: Re: [digester] Help needed


Hi Ray,
My advice is to create 2 utility classes one to manage the process of
the ArrayList and the Map.

class MyArrayList extends ArrayList {
private String name;
public void setName(String name){this.name=name;}
public String getName() {return name}
}

class MyHashMap extends HashMap {

public void putIt (MyArrayList obj) {
    super.put(obj.getName(), obj);
}
}
and .... (see below) ( the name and parameters of the rules could be
innaccurate ;) )
Ray Madigan wrote:

>I have not been using the digester for a long time, but up until now I have
>been able to figure out everything on my own.  I have a situation that I
>don't know if it can be done the way I want to do it,  So I thought I would
>ask.
>
>The xml I want to digest looks like
>
><tran>
>  <processMap>
>    <process name="A">
>        <top>"AB"</top>
>        <top>"AC"</top>
>        <top>"AD"</top>
>    </process>
>    <process name="C">
>        <top>"AB"</top>
>        <top>"CC"</top>
>        <top>"AD"</top>
>    </process>
>    <process name="F">
>        <top>"CB"</top>
>        <top>"AC"</top>
>        <top>"FD"</top>
>    </process>
>  </processMap>
></tran>
>
>The class I want to fill in is like
>
>public class processMap {
>    private HashMap map;
>
>    public processMap ( ) {
>    }
>
>    public void setProcessMap ( HashMap map ) {
>        this.map = map;
>    }
>
>    public HashMap getProcessMap ( ) {
>        return map;
>    }
>}
>
>The digester rules are like
>
>// Create the HashMap and push it on the stack
>
>
addObjectCreate ( "tran/processMap", MyHashMap.class );

>// Create the ArrayList and push it on the stack
>
>
addObjectCreate ( "tran/processMap/process", MyArrayList );
addSetProperties ("tran/processMap/process");
addSetNext("tran/processMap/process","putIt");

>//
>//  Don't know how to get to the process attribute name
>//  Don't know how to call HashMap.put with the key as the
>//  process attribute name value ant the value as the ArrayList
>//  that is currently at the top of the stack
>
>//  Add the top values to the array list
>addCallMethod ( "tran/processMap/process/top", add, 1 );
>addCallParam ( "tran/processMap/process/top", 0 );
>
>
>---------------------------------------------------------------------
>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] Help needed

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Hi Ray,
My advice is to create 2 utility classes one to manage the process of 
the ArrayList and the Map.

class MyArrayList extends ArrayList {
private String name;
public void setName(String name){this.name=name;}
public String getName() {return name}
}

class MyHashMap extends HashMap {

public void putIt (MyArrayList obj) {
    super.put(obj.getName(), obj);
}
}
and .... (see below) ( the name and parameters of the rules could be 
innaccurate ;) )
Ray Madigan wrote:

>I have not been using the digester for a long time, but up until now I have
>been able to figure out everything on my own.  I have a situation that I
>don't know if it can be done the way I want to do it,  So I thought I would
>ask.
>
>The xml I want to digest looks like
>
><tran>
>  <processMap>
>    <process name="A">
>        <top>"AB"</top>
>        <top>"AC"</top>
>        <top>"AD"</top>
>    </process>
>    <process name="C">
>        <top>"AB"</top>
>        <top>"CC"</top>
>        <top>"AD"</top>
>    </process>
>    <process name="F">
>        <top>"CB"</top>
>        <top>"AC"</top>
>        <top>"FD"</top>
>    </process>
>  </processMap>
></tran>
>
>The class I want to fill in is like
>
>public class processMap {
>    private HashMap map;
>
>    public processMap ( ) {
>    }
>
>    public void setProcessMap ( HashMap map ) {
>        this.map = map;
>    }
>
>    public HashMap getProcessMap ( ) {
>        return map;
>    }
>}
>
>The digester rules are like
>
>// Create the HashMap and push it on the stack
>  
>
addObjectCreate ( "tran/processMap", MyHashMap.class );

>// Create the ArrayList and push it on the stack
>  
>
addObjectCreate ( "tran/processMap/process", MyArrayList );
addSetProperties ("tran/processMap/process");
addSetNext("tran/processMap/process","putIt");

>//
>//  Don't know how to get to the process attribute name
>//  Don't know how to call HashMap.put with the key as the
>//  process attribute name value ant the value as the ArrayList
>//  that is currently at the top of the stack
>
>//  Add the top values to the array list
>addCallMethod ( "tran/processMap/process/top", add, 1 );
>addCallParam ( "tran/processMap/process/top", 0 );
>
>
>---------------------------------------------------------------------
>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