I found an alternate solution. I changed the SourceBuilder so that for
elements xxx it creates:

void setXxxCollection(java.util.Collection)
java.util.Collection getXxxCollection()

And then I used the 'get-method' & 'set-method' attributes on the
XML "field" element to select the new methods. Once I changed the
'collection' attribute to 'collection' it worked like a champ.

Attached in the diff of my CVS tree.

Weave


diff -urN --exclude=CVS 
castor/src/main/org/exolab/castor/builder/CollectionInfoJ2.java 
castor.newbuilder/src/main/org/exolab/castor/builder/CollectionInfoJ2.java
--- castor/src/main/org/exolab/castor/builder/CollectionInfoJ2.java     Thu Jul 19 
04:58:13 2001
+++ castor.newbuilder/src/main/org/exolab/castor/builder/CollectionInfoJ2.java  Wed 
+Aug  1 16:21:12 2001
@@ -126,6 +126,10 @@
         jClass.addMethod(method);
         createGetMethod(method);
 
+       method = new JMethod(SGTypes.Collection, "get"+cName+"Collection");
+       jClass.addMethod(method);
+       createGetCollectionMethod(method);
+
           //----------------------/
          //- Create set methods -/
         //----------------------/
@@ -148,6 +152,12 @@
 
         createSetArrayMethod(method);
 
+       //-- collection setter
+       method = new JMethod(null, "set"+cName+"Collection");
+       jClass.addMethod(method);
+       method.addParameter(new JParameter(SGTypes.Collection, getContentName()));
+       createSetCollectionMethod(method);
+
          //---------------------------/
         //- Create Enumerate Method -/
        //---------------------------/
@@ -283,6 +293,22 @@
     } //-- createGetMethod
 
     /**
+     * Creates implementation of Collection get() method.
+     *
+     * @param method the JMethod in which to create the source
+     * code.
+    **/
+    public void createGetCollectionMethod(JMethod method) {
+
+        JSourceCode jsc = method.getSourceCode();
+
+       jsc.add("return ");
+       jsc.append(getName());
+       jsc.append(";");
+
+    } //-- createGetCollectionMethod
+
+    /**
      * Creates implementation of the get(index) method.
      *
      * @param method the JMethod in which to create the source
@@ -359,6 +385,31 @@
             createBoundPropertyCode(jsc);
 
     } //-- createSetArrayMethod
+
+    /**
+     * Creates implementation of set(Collection) method.
+     *
+     * @param method the JMethod in which to create the source
+     * code.
+    **/
+    public void createSetCollectionMethod(JMethod method) {
+
+        JSourceCode jsc = method.getSourceCode();
+
+       jsc.add(getName());
+       jsc.append(".clear();");
+
+       jsc.add(getName());
+       jsc.append(".addAll(");
+       jsc.append(method.getParameter(0).getName());
+       jsc.append(");");
+
+        //-- bound properties
+        if (isBound())
+            createBoundPropertyCode(jsc);
+
+    } //-- createSetCollectionMethod
+
 
     /**
      * Creates implementation of set method.
diff -urN --exclude=CVS castor/src/main/org/exolab/castor/builder/SGTypes.java 
castor.newbuilder/src/main/org/exolab/castor/builder/SGTypes.java
--- castor/src/main/org/exolab/castor/builder/SGTypes.java      Tue Jan  9 21:54:15 
2001
+++ castor.newbuilder/src/main/org/exolab/castor/builder/SGTypes.java   Wed Aug  1 
+16:21:18 2001
@@ -108,6 +108,7 @@
     public static final JClass Hashtable     = new JClass("java.util.Hashtable");
     public static final JClass Stack         = new JClass("java.util.Stack");
     public static final JClass Vector        = new JClass("java.util.Vector");
+    public static final JClass Collection    = new JClass("java.util.Collection");
     
     
 } //-- SGTypes
diff -urN --exclude=CVS 
castor/src/main/org/exolab/castor/builder/castorbuilder.properties 
castor.newbuilder/src/main/org/exolab/castor/builder/castorbuilder.properties
--- castor/src/main/org/exolab/castor/builder/castorbuilder.properties  Wed Jul 11 
07:12:09 2001
+++ castor.newbuilder/src/main/org/exolab/castor/builder/castorbuilder.properties      
+ Wed Aug  1 16:22:00 2001
@@ -8,7 +8,7 @@
 # when enabled. This will change in the future when we introduce
 # fine grained control over each class and it's properties.
 #
-#org.exolab.castor.builder.boundproperties=true
+org.exolab.castor.builder.boundproperties=true
 
 # Java class mapping of <xsd:element>'s and <xsd:complexType>'s 
 #
@@ -22,13 +22,13 @@
 # XML namespace mapping to Java packages
 #
 #org.exolab.castor.builder.nspackages=\
-  http://www.xyz.com/schemas/project=com.xyz.schemas.project,\
-  http://www.xyz.com/schemas/person=com.xyz.schemas.person
+#  http://www.xyz.com/schemas/project=com.xyz.schemas.project,\
+#  http://www.xyz.com/schemas/person=com.xyz.schemas.person
 
 # Set to true if you want to generate the equals method
 # for each generated class
 # false by default
-#org.exolab.castor.builder.equalsmethod=true
+org.exolab.castor.builder.equalsmethod=true
 
 # Set to true if you want to use Object Wrappers instead
 # of primitives (e.g Float instead of float).
diff -urN --exclude=CVS castor/src/main/org/exolab/castor/castor.properties 
castor.newbuilder/src/main/org/exolab/castor/castor.properties
--- castor/src/main/org/exolab/castor/castor.properties Wed Jan 10 21:24:35 2001
+++ castor.newbuilder/src/main/org/exolab/castor/castor.properties      Wed Aug  1 
+16:23:09 2001
@@ -62,7 +62,7 @@
 
 # True if all documents should be indented on output by default
 #
-#org.exolab.castor.indent=true
+org.exolab.castor.indent=true
 
 
 # True if xml documents should be validated by the SAX Parser

Reply via email to