You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Daniel Fagerstrom <da...@nada.kth.se> on 2003/05/01 12:20:42 UTC
[Betwixt] DOM Facade
I'm interested in writing a DOM facade for Betwixt. My use case for such
a facade is for accessing business objects and the data model in Cocoon
as XML from XSLT. We had a long discussion about that at Cocoon-dev
recently [1]. There were also a thread about DOM facades for Java beans
xml-apache-general a while ago [2] where several people expressed
interest in helping although not leading such an effort.
In the thread [2] Domify [3], Betwixt and JXPath were mentioned. Domify
already is a (read only) DOM facade for Java beans, but has a fixed bean
to XML mapping rule. Betwixt provide flexible bean mapping rules but
need some refactoring to make these mapping rules accesible for a DOM
facade. JXPath provide an XML interface for beans, DynaBeans, DOM and
JDOM, but has not any mechanism for flexible bean mapping.
As I like the flexible bean mapping rules in Betwixt, I prefer to base
the DOM facade on Betwixt.
Plan
----
1. In Betwixt there is one class: AbstractBeanWriter, that both includes
the logic for transforming the Java bean structure and the mapping info
to XML nodes and traversing the tree in deep first order and writing the
XML in a serial form (e.g. as text or SAX). I'd like to factor out the
code that creates XML nodes so that the XML structure can be accessed in
any order. The Navigator interface in Jaxen or the interfaces
o.a.c.jxpath.ri.model.NodePointer and o.a.c.jxpath.ri.model.NodeIterator
in JXPath could be used as model, although I'd like to start with a
much more minimal interface.
2. Build a read only DOM facade above the XML node interface from 1.
This could be fairly similar to Domify.
3. Extend the DOM facade so that Java beans can be constructed and
connected through the DOM interface.
- o -
I have started to work on the refactoring of the AbstractBeanWriter and
would like some feedback from the Betwixt team on my design ideas this
far. So let us go into the techical details:
Design
------
My overall design goal is of course to factor out the XML tree traversal
and node access code from the AbstractBeanWriter so that it could be
used in a DOM facade as well. I also want to do this in such a way that
it doesn't affect the performance or memory usage for the SAX or text
generation. Furthermore I would like to move all knowledge about the
intended structure of the generated XML to the descriptors to make the
responsabilities clearer. currently there are some such information in
the AbstractBeanWriter.
Each node in the XML tree that corresponds to the Java bean structure
can be identified by a pair consisting of a Descriptor object and a
Context object. The Descriptor is an ElementDescriptor, an
AtributeDescriptor and so on depending on the node type. To make this
more explicit in the code we define a class where the objects points to
nodes in the XML tree:
class Pointer {
attribute Descriptor descriptor,
attribute Context context
}
In the AbstractBeanWriter the attributes writeIDs and writeEmptyElements
affect the stucture of the generated XML tree. I would prefer that all
information about the prefered tree structure is concentrated to the
descriptors. IMO these attributes should be moved to the XMLIntrospector
which in turn can use it to give the right information to the descriptors.
The AbstractBeanWriter also contains the attributes idMap, idGenerator
and beanStack that are needed for creating id attributes for handling
circular data structures. James Strachan proposed moving the id
generation stuff to expressions [4], I think that it is a good idea. It
would IMO require that the idMap, idGenerator and the beanStack are part
of the Context object. The beanStack could be replaced by letting each
Context object contain a reference to its parent.
There is also a need for accessing the attributes and the children of an
element. I think I would prefer doing that through an Iterator over
Pointers. For attributes, an indexed access structure using the the
attributesDescriptors array would work. But for the children of an
element the relation between indexes in the contenDescriptors array and
positions in the generated XML is much more complicated for the cases
where wrapCollectionsInElement is false or writeEmptyElements is false.
This basically means that to provide indexed access, all the
children of the element need to be created and stored in an array. As I
prefer an as light weight, access structure as possible I think an
iterator over the chidren is better as it can wait to access a child
until it is needed.
Given a Pointer that contains an ElementDescriptor we need some utility
code that provide access to the different parts of an element, and like
wise for attributes and other types of nodes. This could be done by
creating wrappers objects for elements, attributes etc that contain a
Pointer object. But in the interest of keeping things light weight and
avoid the creation of lots of small objects, a better idea IMO, is to
have ElementHelper, AttributeHelper etc, classes that contains static
node access methodes that takes Pointers as an argument.
- o -
I guess that what I wrote about the proposed refactoring might be booth
to vague and to techical to make it easily understandable. I'm working
on implementing the above design, and would be happy to get some
feedback on the proposed design.
/Daniel Fagerstrom
[1] [RT] the quest for the perfect template language,
http://marc.theaimsgroup.com/?t=104930795600004&r=1&w=2
[2] Accessing java beans through DOM,
http://marc.theaimsgroup.com/?t=104933325200002&r=1&w=2
[3] Domify, http://domify.sf.net
[4] IRC chat, http://irc.werken.com/channels/betwixt/2002-12-29.html
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Betwixt] DOM Facade
Posted by Daniel Fagerstrom <da...@nada.kth.se>.
hi Robert
robert burrell donkin wrote:
> hi Daniel
>
> it's a long post (with even longer references)
Then you should see some of my posts on cocoon-dev ;) There is a
tradition over there at cocoon-dev about writing long design documents
and doing distributed design.
> and it'll take a bit to digest in detail. but i thought that it'd be
> better to come back with some initial thoughts now and maybe come back
> to some individual points later.
Yes, seems like a good idea.
> maybe IRC might be a good way to discuss some of your design ideas.
>
> (these comments are unordered and a little disconnected.)
>
> DOM facade would be cool and all help appreciated. some users already
> use betwixt with cocoon - but using SAX rather than DOM.
SAX works well if you want to serialize all of your bean structure to
XML and of course, there are many applications where this is a good
idea. What I have in mind are cases when you want to access only a small
part of a possibly very large bean structure through XSLT. For such
cases it would be very inneficient to serialize all of the data as XML,
a lazy DOM adapter is a much better idea. Furthermore some XSLT
processors e.g. Xalan can work directly on an input DOM document
(through a thin adapter layer). For SAX input however, an internal DOM
like structure has to be build in the XSLT processor.
> betwixt is hard to work with. it's very easy to break and hard to
> understand.
Agreed, I have spent quite some time learning how it works. I think
Betwixt would be much easier to understand with a clearer layering and
clearer responsiblity for the different layers. This is done in JXPath
as an related example. In JXPath all access to the Java beans are made
through two interfaces: NodePointer and NodeIterator. As a consequence,
one can quite easily use JXPath together with new data models and they
have already implemented quite a few: Java Beans, DynaBeans, DOM and
JDOM. For Jaxen there is a similar situation, all data is accesed
through the Navigator interface. We would need such an interface in Betwixt.
As Betwixt currently is structured, the AbstractBeanWriter contains much
knowledge about how the different descriptors together with Java beans
should be translated to XML. All this knowledege should IMO be factored
out from the AbstractBeanWriter to a new layer, like in JXPath or Jaxen.
Furthermore the information about the structure of the produced XML
document is mainly found in the XMLBeanInfo and the Descriptor classes,
but some information (e.g. about ID generation), is found in the
AbstractBeanWriter, IMO it would be much more easy to understand and
mantain Betwixt if all such information could be moved to the
XMLBeanInfo and Descriptor interfaces.
> it needs to be refactored but it's hard to see the right way to do this.
I'm working on refactoring Betwixt along the lines I propsed in my
previous mail and have among other things moved the ID generation
mechanism to Expression classes. Now, I guess it would be a tough task
for you to review a very large patch file that affects several classes,
on the other hand it is hard to know if a design idea works whithout
implementing it.
I propose that we try to formulate a common vision for the improved
internal design. We could do this by working on a design document in the
jakarta-common Wiki. I could start by adding my proposal. Then we could
work towards the high level design goal, in a number of small
refactoring steps and thus avoid breaking anything along the way.
> there is a chronic shortage of good test cases. some stuff is a subtle
> and so it's easy to make mistakes.
I'm aware of this OTH the only certain way to not break anything that
works is to not do anything at all ;) Refactoring often work as a
motivation for writing more test cases.
> maybe supporting DOM might be the key to a better structure but i'd
> prefer it to be thought out properly before hand.
Yes, lets discuss design for a while, but we also should start
incremental refactoring quite soon. Complete upfront design seldom work,
and even worse: it tend to become extremely boring after a while ;)
> even though betwixt is an alpha, we're still pretty hot on
> deprecation and preserving compatibility (betwixt has an existing
> user base).
I'm not talking about changing any external contracts or behaviour (at
least as long as they are correct), I'm only talking about making
clearer internal contracts.
> a few other people have recently volunteered to add features to
> betwixt. i'
> d like to be able to coordinate these effort so that they aren't wasted.
Sounds good.
/Daniel Fagerstrom
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Betwixt] DOM Facade
Posted by Martin van den Bemt <ml...@mvdb.net>.
Hi Robert..
I am back amongst the living, I really need an irc update of what needs
to be done (besides the task list that is).
I agree totally with your view about betwixt and maybe part of the
solution is a rewrite + full test coverage of the current version of
betwixt to see if we can stay backward compatible.
Maybe we can create a proposal directory where we can start with a clean
implementation, so we can get a new perspective on how the structure
could be (more interfaces eg, so it is easier to write extensions).
What I also really would like to see is automatic bean generation from
an xml file (although that is not the initial purpose of betwixt, but
mostly used that way as far as I can tell).The last thing can be
completely independend of anything else though. (I'll add it to the wish
list). Also ignoring .betwixt files should be possible (i'll add that
one too).
I have an internet connection at my girlfriends now and will try to keep
connected during the weekend on irc :)
Btw From 7 till 15 june I will be trying to get to England (sailing that
is). Don't know where we are going yet, but I'll let you know :)
Mvgr,
Martin
On Fri, 2003-05-02 at 11:29, robert burrell donkin wrote:
> hi Daniel
>
> it's a long post (with even longer references) and it'll take a bit to
> digest in detail. but i thought that it'd be better to come back with some
> initial thoughts now and maybe come back to some individual points later.
> maybe IRC might be a good way to discuss some of your design ideas.
>
> (these comments are unordered and a little disconnected.)
>
> DOM facade would be cool and all help appreciated. some users already use
> betwixt with cocoon - but using SAX rather than DOM.
>
> betwixt is hard to work with. it's very easy to break and hard to
> understand. it needs to be refactored but it's hard to see the right way
> to do this. there is a chronic shortage of good test cases. some stuff is
> a subtle and so it's easy to make mistakes. maybe supporting DOM might be
> the key to a better structure but i'd prefer it to be thought out properly
> before hand.
>
> even though betwixt is an alpha, we're still pretty hot on deprecation
> and preserving compatibility (betwixt has an existing user base).
>
> a few other people have recently volunteered to add features to betwixt. i'
> d like to be able to coordinate these effort so that they aren't wasted.
>
> i'd like to hear the opinions of others about any major refactoring before
> it goes ahead.
>
> - robert
>
> On Thursday, May 1, 2003, at 11:20 AM, Daniel Fagerstrom wrote:
>
> > I'm interested in writing a DOM facade for Betwixt. My use case for such
> > a facade is for accessing business objects and the data model in Cocoon
> > as XML from XSLT. We had a long discussion about that at Cocoon-dev
> > recently [1]. There were also a thread about DOM facades for Java beans
> > xml-apache-general a while ago [2] where several people expressed
> > interest in helping although not leading such an effort.
> >
> > In the thread [2] Domify [3], Betwixt and JXPath were mentioned. Domify
> > already is a (read only) DOM facade for Java beans, but has a fixed bean
> > to XML mapping rule. Betwixt provide flexible bean mapping rules but
> > need some refactoring to make these mapping rules accesible for a DOM
> > facade. JXPath provide an XML interface for beans, DynaBeans, DOM and
> > JDOM, but has not any mechanism for flexible bean mapping.
> >
> > As I like the flexible bean mapping rules in Betwixt, I prefer to base
> > the DOM facade on Betwixt.
> >
> > Plan
> > ----
> > 1. In Betwixt there is one class: AbstractBeanWriter, that both includes
> > the logic for transforming the Java bean structure and the mapping info
> > to XML nodes and traversing the tree in deep first order and writing the
> > XML in a serial form (e.g. as text or SAX). I'd like to factor out the
> > code that creates XML nodes so that the XML structure can be accessed in
> > any order. The Navigator interface in Jaxen or the interfaces
> > o.a.c.jxpath.ri.model.NodePointer and o.a.c.jxpath.ri.model.NodeIterator
> > in JXPath could be used as model, although I'd like to start with a
> > much more minimal interface.
> >
> > 2. Build a read only DOM facade above the XML node interface from 1.
> > This could be fairly similar to Domify.
> >
> > 3. Extend the DOM facade so that Java beans can be constructed and
> > connected through the DOM interface.
> >
> > - o -
> >
> > I have started to work on the refactoring of the AbstractBeanWriter and
> > would like some feedback from the Betwixt team on my design ideas this
> > far. So let us go into the techical details:
> >
> > Design
> > ------
> > My overall design goal is of course to factor out the XML tree traversal
> > and node access code from the AbstractBeanWriter so that it could be used
> > in a DOM facade as well. I also want to do this in such a way that it
> > doesn't affect the performance or memory usage for the SAX or text
> > generation. Furthermore I would like to move all knowledge about the
> > intended structure of the generated XML to the descriptors to make the
> > responsabilities clearer. currently there are some such information in
> > the AbstractBeanWriter.
> >
> > Each node in the XML tree that corresponds to the Java bean structure
> > can be identified by a pair consisting of a Descriptor object and a
> > Context object. The Descriptor is an ElementDescriptor, an
> > AtributeDescriptor and so on depending on the node type. To make this
> > more explicit in the code we define a class where the objects points to
> > nodes in the XML tree:
> >
> > class Pointer {
> > attribute Descriptor descriptor,
> > attribute Context context
> > }
> >
> > In the AbstractBeanWriter the attributes writeIDs and writeEmptyElements
> > affect the stucture of the generated XML tree. I would prefer that all
> > information about the prefered tree structure is concentrated to the
> > descriptors. IMO these attributes should be moved to the XMLIntrospector
> > which in turn can use it to give the right information to the descriptors.
> >
> > The AbstractBeanWriter also contains the attributes idMap, idGenerator
> > and beanStack that are needed for creating id attributes for handling
> > circular data structures. James Strachan proposed moving the id
> > generation stuff to expressions [4], I think that it is a good idea. It
> > would IMO require that the idMap, idGenerator and the beanStack are part
> > of the Context object. The beanStack could be replaced by letting each
> > Context object contain a reference to its parent.
> >
> > There is also a need for accessing the attributes and the children of an
> > element. I think I would prefer doing that through an Iterator over
> > Pointers. For attributes, an indexed access structure using the the
> > attributesDescriptors array would work. But for the children of an
> > element the relation between indexes in the contenDescriptors array and
> > positions in the generated XML is much more complicated for the cases
> > where wrapCollectionsInElement is false or writeEmptyElements is
> > false. This basically means that to provide indexed access, all the
> > children of the element need to be created and stored in an array. As I
> > prefer an as light weight, access structure as possible I think an
> > iterator over the chidren is better as it can wait to access a child
> > until it is needed.
> >
> > Given a Pointer that contains an ElementDescriptor we need some utility
> > code that provide access to the different parts of an element, and like
> > wise for attributes and other types of nodes. This could be done by
> > creating wrappers objects for elements, attributes etc that contain a
> > Pointer object. But in the interest of keeping things light weight and
> > avoid the creation of lots of small objects, a better idea IMO, is to
> > have ElementHelper, AttributeHelper etc, classes that contains static
> > node access methodes that takes Pointers as an argument.
> >
> > - o -
> >
> > I guess that what I wrote about the proposed refactoring might be booth
> > to vague and to techical to make it easily understandable. I'm working on
> > implementing the above design, and would be happy to get some feedback on
> > the proposed design.
> >
> > /Daniel Fagerstrom
> >
> >
> > [1] [RT] the quest for the perfect template language,
> > http://marc.theaimsgroup.com/?t=104930795600004&r=1&w=2
> > [2] Accessing java beans through DOM,
> > http://marc.theaimsgroup.com/?t=104933325200002&r=1&w=2
> > [3] Domify, http://domify.sf.net
> > [4] IRC chat, http://irc.werken.com/channels/betwixt/2002-12-29.html
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Betwixt] DOM Facade
Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi Daniel
it's a long post (with even longer references) and it'll take a bit to
digest in detail. but i thought that it'd be better to come back with some
initial thoughts now and maybe come back to some individual points later.
maybe IRC might be a good way to discuss some of your design ideas.
(these comments are unordered and a little disconnected.)
DOM facade would be cool and all help appreciated. some users already use
betwixt with cocoon - but using SAX rather than DOM.
betwixt is hard to work with. it's very easy to break and hard to
understand. it needs to be refactored but it's hard to see the right way
to do this. there is a chronic shortage of good test cases. some stuff is
a subtle and so it's easy to make mistakes. maybe supporting DOM might be
the key to a better structure but i'd prefer it to be thought out properly
before hand.
even though betwixt is an alpha, we're still pretty hot on deprecation
and preserving compatibility (betwixt has an existing user base).
a few other people have recently volunteered to add features to betwixt. i'
d like to be able to coordinate these effort so that they aren't wasted.
i'd like to hear the opinions of others about any major refactoring before
it goes ahead.
- robert
On Thursday, May 1, 2003, at 11:20 AM, Daniel Fagerstrom wrote:
> I'm interested in writing a DOM facade for Betwixt. My use case for such
> a facade is for accessing business objects and the data model in Cocoon
> as XML from XSLT. We had a long discussion about that at Cocoon-dev
> recently [1]. There were also a thread about DOM facades for Java beans
> xml-apache-general a while ago [2] where several people expressed
> interest in helping although not leading such an effort.
>
> In the thread [2] Domify [3], Betwixt and JXPath were mentioned. Domify
> already is a (read only) DOM facade for Java beans, but has a fixed bean
> to XML mapping rule. Betwixt provide flexible bean mapping rules but
> need some refactoring to make these mapping rules accesible for a DOM
> facade. JXPath provide an XML interface for beans, DynaBeans, DOM and
> JDOM, but has not any mechanism for flexible bean mapping.
>
> As I like the flexible bean mapping rules in Betwixt, I prefer to base
> the DOM facade on Betwixt.
>
> Plan
> ----
> 1. In Betwixt there is one class: AbstractBeanWriter, that both includes
> the logic for transforming the Java bean structure and the mapping info
> to XML nodes and traversing the tree in deep first order and writing the
> XML in a serial form (e.g. as text or SAX). I'd like to factor out the
> code that creates XML nodes so that the XML structure can be accessed in
> any order. The Navigator interface in Jaxen or the interfaces
> o.a.c.jxpath.ri.model.NodePointer and o.a.c.jxpath.ri.model.NodeIterator
> in JXPath could be used as model, although I'd like to start with a
> much more minimal interface.
>
> 2. Build a read only DOM facade above the XML node interface from 1.
> This could be fairly similar to Domify.
>
> 3. Extend the DOM facade so that Java beans can be constructed and
> connected through the DOM interface.
>
> - o -
>
> I have started to work on the refactoring of the AbstractBeanWriter and
> would like some feedback from the Betwixt team on my design ideas this
> far. So let us go into the techical details:
>
> Design
> ------
> My overall design goal is of course to factor out the XML tree traversal
> and node access code from the AbstractBeanWriter so that it could be used
> in a DOM facade as well. I also want to do this in such a way that it
> doesn't affect the performance or memory usage for the SAX or text
> generation. Furthermore I would like to move all knowledge about the
> intended structure of the generated XML to the descriptors to make the
> responsabilities clearer. currently there are some such information in
> the AbstractBeanWriter.
>
> Each node in the XML tree that corresponds to the Java bean structure
> can be identified by a pair consisting of a Descriptor object and a
> Context object. The Descriptor is an ElementDescriptor, an
> AtributeDescriptor and so on depending on the node type. To make this
> more explicit in the code we define a class where the objects points to
> nodes in the XML tree:
>
> class Pointer {
> attribute Descriptor descriptor,
> attribute Context context
> }
>
> In the AbstractBeanWriter the attributes writeIDs and writeEmptyElements
> affect the stucture of the generated XML tree. I would prefer that all
> information about the prefered tree structure is concentrated to the
> descriptors. IMO these attributes should be moved to the XMLIntrospector
> which in turn can use it to give the right information to the descriptors.
>
> The AbstractBeanWriter also contains the attributes idMap, idGenerator
> and beanStack that are needed for creating id attributes for handling
> circular data structures. James Strachan proposed moving the id
> generation stuff to expressions [4], I think that it is a good idea. It
> would IMO require that the idMap, idGenerator and the beanStack are part
> of the Context object. The beanStack could be replaced by letting each
> Context object contain a reference to its parent.
>
> There is also a need for accessing the attributes and the children of an
> element. I think I would prefer doing that through an Iterator over
> Pointers. For attributes, an indexed access structure using the the
> attributesDescriptors array would work. But for the children of an
> element the relation between indexes in the contenDescriptors array and
> positions in the generated XML is much more complicated for the cases
> where wrapCollectionsInElement is false or writeEmptyElements is
> false. This basically means that to provide indexed access, all the
> children of the element need to be created and stored in an array. As I
> prefer an as light weight, access structure as possible I think an
> iterator over the chidren is better as it can wait to access a child
> until it is needed.
>
> Given a Pointer that contains an ElementDescriptor we need some utility
> code that provide access to the different parts of an element, and like
> wise for attributes and other types of nodes. This could be done by
> creating wrappers objects for elements, attributes etc that contain a
> Pointer object. But in the interest of keeping things light weight and
> avoid the creation of lots of small objects, a better idea IMO, is to
> have ElementHelper, AttributeHelper etc, classes that contains static
> node access methodes that takes Pointers as an argument.
>
> - o -
>
> I guess that what I wrote about the proposed refactoring might be booth
> to vague and to techical to make it easily understandable. I'm working on
> implementing the above design, and would be happy to get some feedback on
> the proposed design.
>
> /Daniel Fagerstrom
>
>
> [1] [RT] the quest for the perfect template language,
> http://marc.theaimsgroup.com/?t=104930795600004&r=1&w=2
> [2] Accessing java beans through DOM,
> http://marc.theaimsgroup.com/?t=104933325200002&r=1&w=2
> [3] Domify, http://domify.sf.net
> [4] IRC chat, http://irc.werken.com/channels/betwixt/2002-12-29.html
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org