Hi all,


I've got a few small contributions dealing with Value Objects that I'm willing to submit, if you'd like it.

I understand Brian Topping is the main Value Objects guy (Hi Brian, long time no chat!).

Here's a description of my changes, which are all only changes to the "valueobject.xdt" file.

1- introduce new attribute for the @ejb.value-object tag named "concrete-type". This lets the user specify the actual type to be produced within the VO for a composition set/collection. Currently the "type" attribute lets you specify "Set" or "Collection" and that's great, but what if I want the set to be a TreeSet instead of a HashSet (the default)? that's where "concrete-type" comes in. Note that the way I've coded it, the new attribute is not mandatory, and the default is still used in that case.

Is there another way to accomplish this? If not, there's a patch that you can use at the end of the e-mail if you'd like to incorporate it into the main source (which I'd obviously like so that I don't have to maintain my own).

2- I've written some additional xdt "scriptlets" to use as a merge file with value objects, but I think that once again, this functionality could be useful to others, so the code code be inserted write into the main "valueobject.xdt" file if you agree. One method marks all of the
dirty flags (the hasBeenSet flags) to false. The other merges all of the properties that "have been set" from one instance of the VO to another.


Once again, the code is below...

3- Finally, the (obvious) main reason I want to have my Set be a TreeSet rather than a HashSet is so that it can be sorted. This leads to the need to have the VO implement Comparable. I'm achieving this with the "implements" attribute of the VO, and with the contents of my merge file (which is a bit tricky because the same merge file is used for all VOs that are created, so my compare() function has to be a bit smart about using the primary key fields to do the comparison). I can also contribute this if you're interested.


Thanks for a great tool, and please let me know if there is (was) a better way for me to accomplish what I've done.


Also, I would be happy to re-submit patches against CVS head if you decide you want this functionality.

james



Patch (against 1.2b2) for Value object "concrete-type" attribute:
=============================================================
--- valueobject.xdt 2003-06-03 15:17:25.000000000 -0600
+++ valueobject.xdt_1.2b2 2003-06-03 15:00:57.000000000 -0600
@@ -23,12 +23,7 @@
private boolean <XDtEjbValueObj:currentAggregateName/>HasBeenSet = false;
</XDtMethod:ifDoesntHaveMethodTag>
<XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="type">
- <XDtMethod:ifDoesntHaveMethodTag tagName="ejb:value-object" paramName="concrete-type">
private <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> <XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
- </XDtMethod:ifDoesntHaveMethodTag>
- <XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="concrete-type">
- private <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> <XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- </XDtMethod:ifHasMethodTag>
</XDtMethod:ifHasMethodTag>
</XDtEjbValueObj:forAllRelations>


@@ -154,17 +149,9 @@
}
</XDtMethod:ifDoesntHaveMethodTag>
<XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="type">
-
- <XDtMethod:ifDoesntHaveMethodTag tagName="ejb:value-object" paramName="concrete-type">
protected <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> added<XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
protected <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> removed<XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
protected <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> updated<XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
- </XDtMethod:ifDoesntHaveMethodTag>
- <XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="concrete-type">
- protected <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> added<XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- protected <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> removed<XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- protected <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> updated<XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- </XDtMethod:ifHasMethodTag>


public <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> getAdded<XDtEjbValueObj:currentAggregateName/>s() { return added<XDtEjbValueObj:currentAggregateName/>s; }
public <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="type"/> getRemoved<XDtEjbValueObj:currentAggregateName/>s() { return removed<XDtEjbValueObj:currentAggregateName/>s; }
@@ -229,18 +216,9 @@
}


public void clean<XDtEjbValueObj:currentAggregateName/>(){
-
- <XDtMethod:ifDoesntHaveMethodTag tagName="ejb:value-object" paramName="concrete-type">
this.added<XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
this.removed<XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
this.updated<XDtEjbValueObj:currentAggregateName/>s = new <XDtEjbValueObj:concreteCollectionType/>();
- </XDtMethod:ifDoesntHaveMethodTag>
- <XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="concrete-type">
- this.added<XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- this.removed<XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- this.updated<XDtEjbValueObj:currentAggregateName/>s = new <XDtMethod:methodTagValue tagName="ejb:value-object" paramName="concrete-type"/>();
- </XDtMethod:ifHasMethodTag>
-
}


public void copy<XDtEjbValueObj:currentAggregateName/>sFrom(<XDtEjbValueObj:valueObjectClass/> from)

=============================================================


Additional code for "valueobject.xdt" to be put above the "valueobject-custom.xdt" merge point.
=============================================================
/**
* Marks all data members (including collections) as not dirty (sets the
* 'hasBeenSet' fields to <code>false</code>). Clears the "added", "removed",
* and "updated" collections as well.
*/
public void markClean() {


<XDtEjbPersistent:forAllPersistentFields superclasses="false" valueobject="<XDtEjbValueObj:valueObjectMatch/>">
<XDtMethod:propertyName/>HasBeenSet = false;
</XDtEjbPersistent:forAllPersistentFields>


<XDtEjbValueObj:forAllRelations superclasses="false" valueobject="<XDtEjbValueObj:valueObjectMatch/>">
<XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="type">
this.added<XDtEjbValueObj:currentAggregateName/>s.clear();
this.removed<XDtEjbValueObj:currentAggregateName/>s.clear();
this.updated<XDtEjbValueObj:currentAggregateName/>s.clear();
</XDtMethod:ifHasMethodTag>
</XDtEjbValueObj:forAllRelations>


}

/**
* Moves all data members (including collections) that are marked as dirty
* from the source instance to this instance.
*/
public void mergeDirty(<XDtClass:classOf><XDtEjbValueObj:valueObjectClass/></XDtClass:classOf> src) {


<XDtEjbPersistent:forAllPersistentFields superclasses="false" valueobject="<XDtEjbValueObj:valueObjectMatch/>">
<XDtMethod:ifHasMethod name="<XDtMethod:setterMethod/>" parameters="<XDtMethod:methodType/>">
if(src.<XDtMethod:propertyName/>HasBeenSet())
<XDtMethod:setterMethod/>(src.<XDtMethod:getterMethod/>());
</XDtMethod:ifHasMethod>
</XDtEjbPersistent:forAllPersistentFields>


<XDtEjbValueObj:forAllRelations superclasses="false" valueobject="<XDtEjbValueObj:valueObjectMatch/>">
<XDtMethod:ifHasMethodTag tagName="ejb:value-object" paramName="type">


setAdded<XDtEjbValueObj:currentAggregateName/>s(src.getAdded<XDtEjbValueObj:currentAggregateName/>s());

setRemoved<XDtEjbValueObj:currentAggregateName/>s(src.getRemoved<XDtEjbValueObj:currentAggregateName/>s());

setUpdated<XDtEjbValueObj:currentAggregateName/>s(src.getUpdated<XDtEjbValueObj:currentAggregateName/>s());
    </XDtMethod:ifHasMethodTag>
  </XDtEjbValueObj:forAllRelations>

  }
=============================================================





-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to