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: Digester:
Date Wed, 08 May 2002 15:15:53 GMT
See intermixed.

On Wed, 8 May 2002 kris@dotech.com wrote:

> Date: Wed, 08 May 2002 08:58:17 -0400 (EDT)
> From: kris@dotech.com
> Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> Subject: Re: Digester:
>
> Thanks for the feedback. See intermixed comments.
>
> Quoting "Craig R. McClanahan" <craigmcc@apache.org>:
>
> > On Tue, 7 May 2002, Kris Schneider wrote:
> >
> > > Date: Tue, 07 May 2002 21:23:29 -0400
> > > From: Kris Schneider <kris@dotech.com>
> > > Reply-To: Jakarta Commons Developers List
> > <commons-dev@jakarta.apache.org>,
> > >      Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> > > To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> > > Subject: Digester:
> > >
> > > Just started using Digester and can't see built-in support for the
> > > scenario where an attribute name doesn't map directly to a bean
> > property
> > > name. For instance, if I've got an element:
> > >
> > > <proc name="shutdown" proc-type="admin"/>
> > >
> > > and a bean with a procedureType property, how can I get the value of
> > the
> > > proc-type attribute into the procedureType property?
> > >
> > > I've gone ahead and written my own rule to handle it, but it seems
> > like
> > > such a common occurrence that I must have missed something. Thanks for
> > > any pointers.
> > >
> >
> > Digester (well, it's really PropertyUtils underneath) uses standard Java
> > introspection techniques to discover the names of the supported
> > properties
> > of a JavaBean, as well as the names of the getter and setter methods.
> > So,
> > one approach would be to define a BeanInfo class for your bean, which
> > defined the existence of a "proc-type" property, and defined
> > "setProcedureType" as the property setter.
> >
> > See the JavaBeans spec for more details:
> >
> >   http://java.sun.com/products/javabeans/
>
> My only reservation with this approach is that it seems like such a
> global change to the bean. The bean property really is procedureType,
> I just need some way to declare a temporary alias for the duration of
> the parse. Unless I'm missing some way to dynamically
> register/unregister a BeanInfo class...
>

You're correct that this change would be global ... at least to any code
that uses JavaBeans introspection.  For the vast majority of Digester
users, that is a Good Thing.

> > > Ah, apologies for reading Javadoc while composing, but can
> > > CallMethodRule/CallParamRule do this?
> > >
> > > digester.addObjectCreate("procs/proc", "ProcBean");
> > > digester.addSetProperties("procs/proc");
> > > digester.addCallMethod("procs/proc", "setProcedureType", 1);
> > > digester.addCallParam("procs/proc", 0, "proc-type");
> > >
> >
> > Should work, although addSetProperties() probably isn't relevant unless
> > you have other property names that actually do match.
>
> Tried it and it does work. I do have other attribute/property pairs
> that match exactly, so I still need to include it.
>
> I've attached the rule I developed in case it's of interest to anyone.
> If it is, I'm happy to donate it to the project. For my original
> example, the usage would be something like:
>
> digester.addObjectCreate("procs/proc", "ProcBean");
> digester.addSetProperties("procs/proc");
> Map propMap = new HashMap();
> propMap.put("proc-type", "procedureType");
> digester.addRule("procs/proc", new SetMappedPropertiesRule(propMap));
>

I'll take a look ... thanks!

> > Craig McClanahan
>
> --
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <http://www.dotech.com/>

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