commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject [Jelly] Tags to create or transform an object graph
Date Wed, 27 Nov 2002 13:18:47 GMT

Many people are using the DTO "pattern" in their webapps to transfer data back and forth between
their persistence and presentation layers.  For those who decide to adopt this pattern, they
find themselves with two different object models: the persistence (domain) model which is
mapped to an underlying data store and a Java Bean model that is used by the JSPs and Struts
actions or what have you.  The problem with this is that you find yourself writing a tonne
of this kind of get()/set() code:


Additonally, if you are using some kind of O/R mapping runtime, you want to do a set() only
if it required, to limit the number of SQL UPDATE statements, so you have code like this everywhere:

if ( !(domainObject.getName().equals(beanObject.getName())) ) {

I am half way through a set of Jelly tags that allow me succinctly describe the rules involved
in this kind of situation.

The above Java can be stated as

	<graph:set from="name" to="name"/>

(assuming domainObject and beanObject are in the JellyContext and named as "target" and "source").

Sometimes more complex mappings are required:

<graph:map name="" sourceKeys="," targetKeys="country.countryCode,language.languageCode">
        <graph:lookup target="site" sourceKeys=","/>
    <graph:prune objects="site"/>

What this says is "if source.getCountry().getId() and source.getLanguage().getId() are different
to target.getCountry().getCountryCode() and target.getLanguage().getLanguageCode() resp, then
set to the result of a lookup based on specified params.  (lookup uses an ObjectManager.lookup()
instance, available from the context).  Alternatively, if either of the sourceKeys is missing
or valueless, prune".

Now, I guess this is more likely to make sense if, like me, you are using JDO as your persistence
runtime.  This allows the graph mapper to surf references as it needs, driven by the Jelly
script.  But, what I wanted to know is is there a better way to do this, is somebody else
working on something similar and, if not, whether you would consider sucking these tags into
the Jelly dist and allow many minds to make them better ;-)

Thanks a mil,

PS I initially looked at using JXPath to do this, but that is good at pulling data out of
a graph, but not so good at transforming a target graph based on the content of a source graph.
 Pruning is the biggest problem I see, but I am open to correction.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message