commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [digester] Need help with simple digester usage
Date Tue, 21 Dec 2010 03:53:37 GMT
I'm trying to use Digester for a simple application.  I want to define
the structure of a binary tree in XML, and then construct that node tree
using Digester.

The trivial "Node" class is just this:
    public static class Node {
        private Node left;
        private Node right;
        private String value;
        public Node getLeft() { return left; }
        public Node getRight() { return right; }
        public String getValue() { return value; }
        public void setLeft(Node left) { this.left = left; }
        public void setRight(Node right) { this.right = right; }
        public void setValue(String value) { this.value = value; }

The XML is composed of nested "node" elements.  The first "node" child
gets set as the "left" property of the root, and the second gets set as
the "right" property.

For instance:

  <node value="abc">
    <node value="def"/>

Should result in a root Node with a "left" property referring to the
second node.

So, going through the Digester documentation, which I haven't looked at
in many years, I figured it would be something like this:

        digester.addRule("*/node", new
        digester.addRule("*/node", new SetPropertiesRule());
        digester.addRule("*/node", new SetNextRule("addChild",

Where "AugmentedNode" extends "Node", adding:

       public void addChild(Node node) {
            if (getLeft() == null)

For those well steeped in Digester lore, I imagine you can immediately
tell this won't work.  You're right, of course.  This dies with an NPE
in "MethodUtils.invokeMethod()" (object is null).  I have no clue what's
wrong with this, or what I should be doing instead.

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

View raw message