On Mon, 2 Apr 2001, Waldhoff, Rodney wrote:

> > With the standard Digester ObjectCreateRule, you could set up rules like
> > this:
> >   digester.addObjectCreate("object", "java.util.Date", "className");
> >   digester.addSetProperties("object");
> 
> This is the part that bothers me.  While it's nice that the resulting XML
> document is relatively concise, self documenting and very readable (none of
> which are features of JOCL), I've got to set up the Digester to be able to
> read the configuration file.  Can I set up a generic ObjectCreateRule that
> works with any class (e.g., classes not known at compile time)? 
> 

It's already there in the "object create" rule above -- I just wasn't
clear about what it does.  The three-arguments version of addObjectCreate
works like this:

* When a matching pattern of XML elements is found on the stack,
  create a new object (of a class to be determined by the following
  rules).

* If the "className" attribute is not specified, the default class
  to create is "java.util.Date".

* If the "className" attribute is specified, it overrides the default
  and a new object of that class is created dynamically (currently, the
  class must have a zero-args constructor).

So, you could use the following to initialize a completely different
object with the same two rules:

  <object className="com.mycompany.mypackage.MyClass"
   foo="1" bar="2" baz="3"/>

which will call the zero-args constructor, and then the three property
setter methods (setFoo, setBar, and setBaz) with appropriate type
conversions for standard Java primitives.

> (I guess I can probably figure that out on my own, let me poke around a bit,
> or feel free to answer.)
> 
>  - Rod
> 

Craig


Reply via email to