betwixt uses digester as a layer above the SAX parser. digester is based heavily on stacks. most digester rules work on the main (or object) stack. betwixt pushes the objects it creates onto the digester stack and so they are available for interaction when the sub-tree rooted at the node they are mapped to is being parsed.
so (for example) here's a sub-tree rooted at element alpha
...
<alpha>
<beta>
<gamma/>
</beta>
</alpha>
...it contains beta and gamma elements. if a bean is mapped by betwixt (could be a nested secondary mapping) for alpha, then betwixt will create the bean when the alpha element is encountered and push it onto the main digester stack. the bean will be available for interaction by digester rules until it is popped off the stack when the end tag for alpha is parsed.
so, let's say you have something like:
...
<alpha>
<dimension>
<x>1.0</x>
<y>1.0</y>
</dimension>
</alpha>
...and you have the alpha element mapped (by betwixt) to a bean.
you then create Digester rule(s) which call the appropriate method on the bean with appropriate values. if you have a method like setDimension(int x, int y) then you can use two CallParamRule's and a CallMethodRule. i don't think that there's a rule that constructs a method from parameters (but that's probably an oversight which should be corrected soon) so you'll either need to wait or create your own rule implementation.
- robert
On 10 Mar 2004, at 22:21, Smith, Pamela wrote:
Can I add Digester rules to do this? I'm new to both Betwixt and Digester so any examples would be great!
-----Original Message----- From: robert burrell donkin [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 10, 2004 4:12 PM To: Jakarta Commons Users List Subject: Re: [betwixt] - Handling java.awt.Point, Dimension and KeyStroke
hi pamela
betwixt is bean-centric. it's support for other types is pretty basic at the moment (i'm afraid). i don't know of any way to do this in betwixt at the moment.
but this is a pretty common use case so there's a chance that something like this could get implemented sooner rather than later. i'll have a think about the design.
- robert
On 10 Mar 2004, at 21:25, Smith, Pamela wrote:
I have a bean with properties whose types are non bean compliant Java classes -- java.awt.Point, java.awt.Dimension and java.awt.KeyStroke. The xml is written correctly, but after parsing, the resulting instances don't have the right values since Point, Dimension and KeyStroke are not beans.
Has anyone already solved this problem?
Thanks, Pam
Ex:
<?xml version="1.0" encoding="UTF-8"?> <Point> <x>10.0</x> <y>15.0</y> </Point>
BeanReader reader = new BeanReader(); reader.registerBeanClass("Point", java.awt.Point.class); Point p = (Point)reader.parse...
The resulting point is not [10,15] since there is no setX() and setY() on java.awt.Point.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
