commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Walter Korman <sha...@waywardgeeks.org>
Subject [Digester] class-specific parsing
Date Mon, 20 Dec 2004 02:23:26 GMT
I'm using commons-digester to parse a config file and would like to
set things up in an extensible manner, but am unsure of the best way
to allow an arbitrary number of user-written classes to engage in
their own custom parsing based on arbitrary class-specific data
format.

Appreciate any input from those who have spent more time working with
the Digester than have I.

Example file subset:

<widget className="foo.TrinketBean" valuation="cheap">
    <trinket name="emerald ring" color="green"/>
    <trinket name="donkey" color="gray"/>
</widget>

<widget className="foo.ContainerBean" rarity="common">
    <container name="basket" material="wicker"/>
    <container name="bottle" material="glass"/>
    <locations>
	<location>Williams-Sonoma</location>
	<location>Pottery Barn</location>
    </locations>
</widget>

So, for each widget a className-specified object is to be
instantiated, and its child elements parsed in a class-specific
manner.

TrinketBean might want to create TrinketRecord objects to correspond
to each <trinket> element; or, it might just want to have an
"addTrinket" method on itself called with the element attributes.

The same for ContainerBean, which adds in the whole <locations>
element wrinkle with a list of <location> elements to be stored.

Since I want the widget element attributes, child elements, child
element attributes, and overall parsing approach to be definable by
the widget itself, the main code that configures the Digester doesn't
know these in advance and so they can't be specified in an immediately
straightforward manner.

I see a few possible approaches:

- Have each Widget provide a method to which the Digester is
  passed when being configured to set up the Widget-specific parsing.

- Fiddle around with a custom Rule.

- Constrain the kind of widget-specific parsing permitted so that it
  falls into a specific form that can be specified via up-front
  Digester configuration but that would limit the flexibility of the
  widget data format.

- Walter

---------------------------------------------------------------------
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