commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Tarkenton <>
Subject Re: [Digester] basic usage problem. Help me understand the stack.
Date Tue, 27 Jul 2004 18:06:46 GMT
Perhaps I spoke too soon in my last response.  I would like to have a
look at the chains source you spoke of for configuration however when
I visit there is a note
stating the source is unreleased.  Do I need to go to CVS to grab the

I did however to manage to get recursion to work in my code with the
*/part idea.  I'll post that code below, but first my issue:

I have run into another behavioral issue that I do not understand; the
problem revolves around the digester.addCallMethod method.  My
understanding is that this method calls a method on the top (parent)
object.  Since the only object I ever deal with in my stack is, I will go ahead and show that code:

public class Part {

    public ArrayList getParts() {
        return parts;

    private ArrayList parts = new ArrayList();

    private String partNumber;
    private String partDescription;
    private String partMaterialCode;
	private String partUM;
	private String quantity;
    private Vector refDes;
	private Vector specCodes;

    public String getPartNumber() {
        return partNumber;

    public void setPartNumber(String partNumber) {
        this.partNumber = partNumber;

    public Vector getSpecCodes() {
        return specCodes;

    public void setSpecCodes(Vector specCodes) {
        this.specCodes = specCodes;

    public Vector getRefDes() {
        return refDes;

    public void setRefDes(Vector refDes) {
        this.refDes = refDes;

    public String getQuantity() {
        return quantity;

    public void setQuantity(String quantity) {
        this.quantity = quantity;

    public String getPartUM() {
        return partUM;

    public void setPartUM(String partUM) {
        this.partUM = partUM;

    public String getPartMaterialCode() {
        return partMaterialCode;

    public void setPartMaterialCode(String partMaterialCode) {
        this.partMaterialCode = partMaterialCode;

    public String getPartDescription() {
        return partDescription;

    public void setPartDescription(String partDescription) {
        this.partDescription = partDescription;

    public boolean isValidSpecCode(String specCode) {
        //TODO find out valid spec codes
        return true;

    public void addRefDes(String refDes) {
        if (refDes == null) return;

    public void addSpecCode(String specCode) {

    public void addPart(Part part) {

Note that this class has addPart(Part part) and addRefDes(String
refDes).  Now when I run my Parser code (below) with the exception of
the addCallMethod line, I get the Part objects I need.  However, when
i have digester.addCallMethod("*/component/refDesignators/refDes",
"addRefDes", 0); in my code, I get a null pointer.  What I don't
understand is that Part object has addRefDes(String x) method.  The
way I've written it, every object in the stack is always a part
object, correct?  So why does the addCallMethod call not grab the body
text of the refDes element and add it to my Part object?

public void parse(String document) throws ParserException {

        Digester digester = new Digester();

        digester.setErrorHandler(new BOMParserErrorHandler());
        digester.addObjectCreate("*/component", Part.class );

        digester.addBeanPropertySetter( "*/component/quantity", "quantity");
"addRefDes", 0);  //this line is my culprit

        digester.addBeanPropertySetter( "*/component/part/partNumber",
"*/component/part/partDescription", "partDescription");
"*/component/part/partMaterialCode", "partMaterialCode");
        digester.addBeanPropertySetter( "*/component/part/partUM", "partUM");
        digester.addSetNext("*/component", "addPart",

        Part dummy = new Part();

        try {
            //catch exceptions

        Iterator iter = dummy.getParts().iterator();
        Part part;
        while (iter.hasNext()) {
            part = (Part);
            parts.put(part.getPartNumber(), part);


    public void addPart(Part root) {

       Part part;
       if (root.getParts() !=null || root.getParts().size() > 0) {
//has children
           System.out.println("part #" + root.getPartNumber() + " has
           Iterator iter = root.getParts().iterator();
           while (iter.hasNext()) {
                part = (Part);
                System.out.println("part.getRefDes() = " + part.getRefDes());
                if (part !=null && part.getPartNumber() !=null) {
                    parts.put(part.getPartNumber(), part);


Anyone have any insight as to why that addCallMethod is blowing up my code?


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

View raw message