commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Bare <christopherb...@yahoo.com>
Subject [digester] help with multi-argument constructor
Date Sat, 24 May 2003 01:30:47 GMT
Hi,

I'm trying to parse XML something like this:

  <user>
    <id>1</id>
    <name>chris</name>
  </user>

As a result, I would like the following constructor to
be called:

   public User( long id, String username )
   {
      //...
   }

I read in the javadocs that "FactoryCreateRule" is
used to create instances of classes without a
no-argument constructor, but, as far as I can tell, an
ObjectCreationFactory is set up to use attributes, and
not enclosed elements, for constructor parameters.
Please correct me if I'm wrong here.

Otherwise, is there a way to do this? Sorry if I'm
missing something totally obvious, and thanks for any
insight.

I know... I could just add "set" methods and an empty
constructor, but I hate to expose public "set" methods
for the world to use and abuse where it's not really
appropriate.

If there's not already an obvious way to do this, and
I'm just clueless, I think something like the
following would be cool:

   digester.addCallConstructor( "users/user",
User.class, 2 );
   digester.addCallParam( "users/user/id", 0 );
   digester.addCallParam( "users/user/name", 1 );


-Chris





__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

Mime
View raw message