We've been doing a bit more work on this here - if any of this is useful
and someone wants to include it into Middlegen then feel free to use
whichever bits you like - the code is still a bit ugly in places I'm afraid.
The change I mentioned in the original message generates Value objects
that only contain the CMP fields (which means they aren't that different
to data objects).
We've done some further modifications now that include CMR fields in the
value objects as well.
The changes are larger than the previous set, and involve the following files :
- nrma-entity-cmp-20.vm - CMP template file (derived from entity-cmp-20.vm)
- NrmaEntityPlugin.java - CMP plugin (extends the CMP20 plugin)
- NrmaEntityTable - (extends Entity20Table)
- nrma-details-object.vm - template file for Details objects
Plugin
------
The Plugin class uses a few new parameters that are specified when it is
invoked in the Ant task :
valueObjectPackage specifies the package that Value objects are to be placed in
detailsObjectPackage specifies the package that Details objects are placed in
There should be a parameter to specify the Value object base class as well (currently
its hard coded into the CMP template).
The Plugin class specifies that NrmaEntityTable represents the table data passed
to the velocity templates - this Table class contains a number of new methods that
let us get various names required for specifying the Value object to be generated
in the template.
The Plugin class generates "Details" objects that are simple wrappers for Value
objects. We use these for debugging - the toString method is edited to print out
whatever information we think is necessary - including CMR information, which the
XDoclet generated Value object doesn't do. These are generated in the same directory
as the Bean classes, which isn't so good if the package specified for them is not
the same as the bean package - haven't found a way around this yet. They aren't used
by any of the generated code so you can ignore them if you wish.
Value object changes to the template
------------------------------------
Look at the template file for all the value object changes - XDoclet @ejb.value-object
tags are now included on all CMP and CMR fields.
One "match" value named "all" is used for all fields - this results in a single
Value object being generated for each Bean that contains all the fields and
relationships on the Bean.
The pattern followed is a little different in intent to what seems to be the
standard XDoclet mechanism of defining particular Value object trees (each with
its own "match" name) for different scenarios.
As there is no simple way of defining these, one Value object class is much
easier to generate. In any case, I find the standard mechanism very unwieldy
for complex trees - instead I use a "tree builder" utility to generate particular
trees at runtime that include the desired branches - have a look at the ValueTreeBuilder
class attached if you are interested (its not used by any of the Middlegen related
code).
Example of invocation in build.xml
----------------------------------
These are invoked instead of <cmp20> in the <middlegen> task :
<nrmacmp20
destination="${build.gen-src.dir}"
package="${packageRoot}.entities"
detailsObjectPackage="${packageRoot}.values"
valueObjectPackage="${packageRoot}.entities"
interfacepackage="${packageRoot}.entities"
jndiprefix="${jndiRoot}"
pkclass="false"
dataobject="true"
datasuffix="Details"
viewtype="local"
mergedir="${basedir}/src/middlegen"
readonly="false"
fkcmp="false"
guid="true">
<fileproducer
id="entity-cmp-20"
template="${basedir}/src/templates/nrma-entity-cmp-20.vm"
/>
<jboss/>
</nrmacmp20>
Hope that helps anyone wanting to generate full Value objects.
Cheers,
Gavin.
-----Original Message-----
From: Eivind Waaler [mailto:***@tihlde.org]
Sent: Wednesday, 6 November 2002 6:45 PM
To: Gavin Hughes
Cc: middlegen-***@lists.sourceforge.net
Subject: RE: [Middlegen-user] Value Objects and Middlegen
Good work, I added a ref. to this mail thread as a feature request:
http://sourceforge.net/tracker/index.php?func=detail&aid=634285&group_id=36044&atid=415993
.eivind
Post by Gavin HughesWe've done a quick hack to get Middlegen to generate Value objects
instead of Data objects (or to ask XDoclet to anyway).
The change is a minor modification to the entity CMP template
(entity-cmp-20.vm in the middlegen-entitybean-plugin-2.0-b2-dev.jar
file in lib).
You can do this by modifying the original template or by copying it
and modifying the appropriate section, then overriding the original
template with your modified version. This is done by adding a
<fileproducer> element within the <cmp20> element in your build.xml
<fileproducer
id="entity-cmp-20"
template="${basedir}/src/templates/nrma-entity-cmp-20.vm"
/>
be changed to the following (use your own Value object base class in
#if( ${plugin.dataobject} )
* extends="com.nrma.values.BaseValue"
* match="*"
* instantiation="eager"
*
#end
Obviously it would be better to have a different parameter specifying
that value objects are generated (ie. $(plugin.valueobject)) so that
you can choose one or the other. This would need some changes to one
of the CMP plugin classes I think - I've got no idea which one I'm
afraid...
Cheers,
Gavin.
-----Original Message-----
Sent: Wednesday, 6 November 2002 7:59 AM
Subject: RE: [Middlegen-user] Value Objects and Middlegen
-----Original Message-----
Brian
Cochran
Sent: 5. november 2002 05:28
Subject: [Middlegen-user] Value Objects and Middlegen
Hey Aslak,
I noticed you were one of the primary contributors on Value
Objects
in
Nonono. I have never really looked into them or tried them. -Just
applied some patches.
XDoclet. Is that as simple as I think it is as far as integrating it
into middlegen? (Drop it into the template entitiy-cmp20.vm template.
Moreover, where could I find something about the idea behind Value
Objects. (i.e what do they offer, and how do you use them, etc.)
Thanks a bunch.
It would be great if you would do us the favour to add value-object
support in middlegen. Send a diff/patch when you're done. Value object
is badly documented, so be prepared to dig into XDoclet's mail
archives and sources.
Thanks a bunch,
Brian
Cheers,
Aslak
-------------------------------------------------------
This SF.net email is sponsored by: ApacheCon, November 18-21 in Las
Vegas (supported by COMDEX), the only Apache event to be fully
supported by the ASF. http://www.apachecon.com
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/middlegen-user
-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size! http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/middlegen-user
-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/middlegen-user