[EMAIL PROTECTED] wrote:
> Hello,
>
> I noticed that you return an Enumeration instead of Iterator. I would
> prefer that it returned an Iterator. Is this change planned and if so
> when?
Since I need the same feature, I sligthly modified castor to obtain an iterateXXX()
method on
classes generated by SourceGenerator when it uses Java 2 collections.
The patch is attached.
Files modified :
org.exolab.castor.builder.CollectionInfoJ2
org.exolab.castor.builder.SGTypes
to apply the patch, just type (in the root of your castor tree) : "patch -p6 <
iterator.patch"
then rebuild everything (ant) and make the jar (ant jar)
Hope this helps
--
Sebastien Stormacq
Chief Architect
Aubay Luxembourg
***
/home/store/java/castor/castor-0.9.3/src/main/org/exolab/castor/builder/CollectionInfoJ2.java
Wed Jul 4 02:48:09 2001
--- main/org/exolab/castor/builder/CollectionInfoJ2.java Thu Aug 30 12:43:18
2001
***************
*** 152,162 ****
--- 152,174 ----
//- Create Enumerate Method -/
//---------------------------/
+
+ /*
+ * Removed to comply to the Java 1.2 Collection framework.
+ * replaced by an iterateXXX() method - see below
+
+ //-- enumerated type
method = new JMethod(SGTypes.Enumeration, "enumerate"+cName);
jClass.addMethod(method);
createEnumerateMethod(method);
+ */
+
+ //--iterated type
+ method = new JMethod(SGTypes.Iterator, "iterate"+cName);
+ jClass.addMethod(method);
+ createIteratedMethod(method);
//-------------------/
//- getCount method -/
***************
*** 236,241 ****
--- 248,269 ----
} //-- createEnumerateMethod
/**
+ * Creates implementation of Iterate method.
+ *
+ * @param method the JMethod in which to create the source
+ * code.
+ **/
+ public void createIteratedMethod(JMethod method) {
+
+ JSourceCode jsc = method.getSourceCode();
+
+ jsc.add("return ");
+ jsc.append(getName());
+ jsc.append(".iterator();");
+
+ } //-- createIterateMethod
+
+ /**
* Creates implementation of object[] get() method.
*
* @param method the JMethod in which to create the source
***************
*** 349,355 ****
jsc.indent();
jsc.add(getName());
jsc.append(".add(");
!
jsc.append(getContentType().createToJavaObjectCode(paramName+'['+index+']'));
jsc.append(");");
jsc.unindent();
jsc.add("}");
--- 377,383 ----
jsc.indent();
jsc.add(getName());
jsc.append(".add(");
! jsc.append(getContentType().createToJavaObjectCode(paramName+'['+index+']'));
jsc.append(");");
jsc.unindent();
jsc.add("}");
***
/home/store/java/castor/castor-0.9.3/src/main/org/exolab/castor/builder/SGTypes.java
Wed Jul 4 02:48:01 2001
--- main/org/exolab/castor/builder/SGTypes.java Thu Aug 30 11:55:08 2001
***************
*** 53,100 ****
* @version $Revision: 1.7 $ $Date: 2001/01/10 02:54:15 $
**/
public class SGTypes {
!
//-----------------------/
//- org.xml.sax Objects -/
//-----------------------/
!
! public static final JClass SAXException
= new JClass("org.xml.sax.SAXException");
!
!
//---------------------------/
//- org.exolab.castor types -/
//---------------------------/
!
! public static final JClass UnmarshalException =
new JClass("org.exolab.castor.xml.UnmarshalException");
!
public static final JClass MarshalException =
new JClass("org.exolab.castor.xml.MarshalException");
!
! public static final JClass ValidationException =
new JClass("org.exolab.castor.xml.ValidationException");
!
//---------------/
//- JDK Objects -/
//---------------/
!
//-- java.lang
public static final JClass IllegalStateException
= new JClass("java.lang.IllegalStateException");
!
public static final JClass IndexOutOfBoundsException
= new JClass("java.lang.IndexOutOfBoundsException");
!
! public static final JClass InstantiationException
= new JClass("java.lang.InstantiationException");
!
!
public static final JClass Class = new JClass("java.lang.Class");
public static final JClass Object = new JClass("java.lang.Object");
public static final JClass String = new JClass("java.lang.String");
public static final JClass StringBuffer = new JClass("java.lang.StringBuffer");
!
//-- java.io
public static final JClass FileReader = new JClass("java.io.FileReader");
public static final JClass FileWriter = new JClass("java.io.FileWriter");
--- 53,100 ----
* @version $Revision: 1.7 $ $Date: 2001/01/10 02:54:15 $
**/
public class SGTypes {
!
//-----------------------/
//- org.xml.sax Objects -/
//-----------------------/
!
! public static final JClass SAXException
= new JClass("org.xml.sax.SAXException");
!
!
//---------------------------/
//- org.exolab.castor types -/
//---------------------------/
!
! public static final JClass UnmarshalException =
new JClass("org.exolab.castor.xml.UnmarshalException");
!
public static final JClass MarshalException =
new JClass("org.exolab.castor.xml.MarshalException");
!
! public static final JClass ValidationException =
new JClass("org.exolab.castor.xml.ValidationException");
!
//---------------/
//- JDK Objects -/
//---------------/
!
//-- java.lang
public static final JClass IllegalStateException
= new JClass("java.lang.IllegalStateException");
!
public static final JClass IndexOutOfBoundsException
= new JClass("java.lang.IndexOutOfBoundsException");
!
! public static final JClass InstantiationException
= new JClass("java.lang.InstantiationException");
!
!
public static final JClass Class = new JClass("java.lang.Class");
public static final JClass Object = new JClass("java.lang.Object");
public static final JClass String = new JClass("java.lang.String");
public static final JClass StringBuffer = new JClass("java.lang.StringBuffer");
!
//-- java.io
public static final JClass FileReader = new JClass("java.io.FileReader");
public static final JClass FileWriter = new JClass("java.io.FileWriter");
***************
*** 102,113 ****
public static final JClass PrintWriter = new JClass("java.io.PrintWriter");
public static final JClass Reader = new JClass("java.io.Reader");
public static final JClass Writer = new JClass("java.io.Writer");
!
//-- java.util
public static final JClass Enumeration = new JClass("java.util.Enumeration");
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");
!
!
} //-- SGTypes
--- 102,114 ----
public static final JClass PrintWriter = new JClass("java.io.PrintWriter");
public static final JClass Reader = new JClass("java.io.Reader");
public static final JClass Writer = new JClass("java.io.Writer");
!
//-- java.util
public static final JClass Enumeration = new JClass("java.util.Enumeration");
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 Iterator = new JClass("java.util.Iterator");
!
!
} //-- SGTypes