commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: earth to digester
Date Fri, 02 Nov 2001 17:54:44 GMT


On Thu, 1 Nov 2001, Jason van Zyl wrote:

> Date: Thu, 01 Nov 2001 21:59:18 -0500
> From: Jason van Zyl <jvanzyl@zenplex.com>
> Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> Subject: Re: earth to digester
>
> On 11/1/01 9:22 PM, "Scott Sanders" <sanders@totalsync.com> wrote:
>
> >
> > Are you saying you want Castor's capabilities, at least on the XML->Java
> > side?
>
> I don't know exactly what Castor does, I've only looked at it for an hour.
>
> > Something like on an element, try to find an attribute on the object at the
> > top of the stack that corresponds by name to that element, and set the
> > attribute appropriately?
>
> The XML documents would probably have to attributes, all elements:
>
> <bean>
>   <attribute1>value1</attribute1>
>   <attribute2>value2</attribute2>
> </bean>
>
> and
>
> bean.setAttribute1(value1)
> bean.setAttribute2(value2)
>
> would be called. it obviously will get more complicated with nested elements
> but that's the general idea.
>

You can actually do this with Digester today:

  digester.addObjectCreate("bean", "com.mycompany.MyClass");
  digester.addCallMethod("bean/attribute1", "setAttribute1", 0);
  digester.addCallMethod("bean/attribute2", "setAttribute2", 0);

The "zero parameters" value is a (sort of) kludge that says "take the
actual parameter value from the body of this element".

It might be more concise to add some sort of a rule to make this easier to
say, perhaps:

  digester.addBeanPropertySetter("bean/attribute1");
  digester.addBeanPropertySetter("bean/attribute2");

that would infer the property name from the final element of the matching
pattern, but it would be functionally equivalent to the existing
capability.


> > Scott
> >

Craig


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message