commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike J Dougherty <mjdoughe...@gmail.com>
Subject Digester: attribute -> class.field mapping
Date Fri, 01 Sep 2006 02:05:42 GMT
I'm not real sure how to ask this question, so let me post some sample 
code and maybe it will help:


Here are the classes:

public class Top {
        private Foo value = null;
        public void setValue(Foo value) { this.value = value; }
        public Foo  getValue()          { return value; }
}

public class Foo {
        private String bar = null;
        public void   setBar(String str) { this.bar = str; }
        public String getBar()           { return bar; }
}

Here's the input XML:

<root>
  <top foo="MyFoo"><![CDATA[Some text]]></top>
</root>

And here are the rules I've some up with so far:

<digester-rules>
  <pattern value="top">
    <object-create-rule
        classname="Top" />
    <pattern value="@foo">
      <object-create-rule classname="Foo" />
      <set-properties-rule />
      <call-method-rule methodname="setBar" paramcount="0"/>
    </pattern> 
    <set-next-rule methodname="setValue" />
  </pattern>
<digester-rules>

What I want is to map the value of the "foo" attribute ("MyFoo") to 
Foo.bar, and then set that instance of the Foo object to Top.value. In 
the end: topInstance.getFoo().getBar().equals("MyFoo") == true.

I've looked at the docs, example, and googled on this, and do not see an 
obvious way to accomplish my objective. Is this possible? If so, what 
would the rules be?

Thanks for your time.
Mike

-- 
**********************************
 Mike Dougherty
 mjdougherty at gmail dot com

 http://www.google.com/talk
**********************************


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


Mime
View raw message