Is there a reason to do that ? JDK 1.1 is long gone now. Sun is not even
maintaining it. Should castor rejected patches just because of this ?
- Navneet
----- Original Message -----
From: "Keith Visco" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, February 10, 2002 4:17 AM
Subject: Re: [castor-dev] Castor patch to generate Java2 Collections
ArrayList code instead of Array []
>
> Hi Glenn,
>
> We can't use your patch. Castor XML is maintaining JDK 1.1
> compatability. The Marshaller cannot include JDK 1.2+ collections.
>
> Thanks,
>
> --Keith
>
>
> Glenn Nielsen wrote:
> >
> > Attached is the patch I am maintaining for Castor which generates
get/set methods
> > which using Java2 Collections rather than Array []. This patch can be
applied
> > to the HEAD of CVS for castor.
> >
> > Regards,
> >
> > Glenn
> >
> > ----------------------------------------------------------------------
> > Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
> > MOREnet System Programming | * if iz ina coment. |
> > Missouri Research and Education Network | */ |
> > ----------------------------------------------------------------------
> >
>
------------------------------------------------------------------------
> > Index: src/main/org/exolab/castor/builder/CollectionInfoJ2.java
> > ===================================================================
> > RCS file:
/cvs/castor/castor/src/main/org/exolab/castor/builder/CollectionInfoJ2.java,
v
> > retrieving revision 1.18
> > diff -u -r1.18 CollectionInfoJ2.java
> > --- src/main/org/exolab/castor/builder/CollectionInfoJ2.java 24 Jan
2002 08:18:14 -0000 1.18
> > +++ src/main/org/exolab/castor/builder/CollectionInfoJ2.java 9 Feb
2002 22:19:09 -0000
> > @@ -129,8 +129,8 @@
> > method.addParameter(new JParameter(JType.Int, "index"));
> > createGetByIndexMethod(method);
> >
> > - //-- {type}[] get{Name}
> > - method = new JMethod(jType.createArray(), "get"+cName);
> > + //-- ArrayList get{Name}
> > + method = new JMethod(getSchemaType().getJType(), "get"+cName);
> > jClass.addMethod(method);
> > createGetMethod(method);
> >
> > @@ -276,7 +276,7 @@
> > } //-- createEnumerateMethod
> >
> > /**
> > - * Creates implementation of object[] get() method.
> > + * Creates implementation of ArrayList get() method.
> > *
> > * @param method the JMethod in which to create the source
> > * code.
> > @@ -286,40 +286,9 @@
> > JSourceCode jsc = method.getSourceCode();
> > JType jType = method.getReturnType();
> >
> > - jsc.add("int size = ");
> > + jsc.add("return ");
> > jsc.append(getName());
> > - jsc.append(".size();");
> > -
> > - String variableName = getName()+".get(index)";
> > -
> > - JType compType = jType.getComponentType();
> > -
> > - jsc.add(compType.toString());
> > - jsc.append("[] mArray = new ");
> > - jsc.append(compType.toString());
> > - jsc.append("[size]");
> > - //-- if component is an array, we must add [] after setting
> > - //-- size
> > - if (compType.isArray()) jsc.append("[]");
> > - jsc.append(";");
> > -
> > - jsc.add("for (int index = 0; index < size; index++) {");
> > - jsc.indent();
> > - jsc.add("mArray[index] = ");
> > - if (getContentType().getType() == XSType.CLASS) {
> > - jsc.append("(");
> > - jsc.append(jType.getLocalName());
> > - jsc.append(") ");
> > - jsc.append(variableName);
> > - }
> > - else {
> > - jsc.append(getContentType()
> > - .createFromJavaObjectCode(variableName));
> > - }
> > jsc.append(";");
> > - jsc.unindent();
> > - jsc.add("}");
> > - jsc.add("return mArray;");
> > } //-- createGetMethod
> >
> > /**
> > Index: src/main/org/exolab/castor/xml/Marshaller.java
> > ===================================================================
> > RCS file:
/cvs/castor/castor/src/main/org/exolab/castor/xml/Marshaller.java,v
> > retrieving revision 1.92
> > diff -u -r1.92 Marshaller.java
> > --- src/main/org/exolab/castor/xml/Marshaller.java 9 Feb 2002
02:04:09 -0000 1.92
> > +++ src/main/org/exolab/castor/xml/Marshaller.java 9 Feb 2002
22:19:43 -0000
> > @@ -71,8 +71,10 @@
> > import java.io.Serializable;
> > import java.io.Writer;
> > import java.lang.reflect.*;
> > +import java.util.ArrayList;
> > import java.util.Enumeration;
> > import java.util.Hashtable;
> > +import java.util.Iterator;
> > import java.util.Vector;
> >
> > /**
> > @@ -774,6 +776,9 @@
> > if (saveType && (descriptor.getHandler() instanceof
DateFieldHandler))
> > saveType = false;
> > //-- XXXX end Date fix
> > + //-- Suppress 'xsi:type' attributes when object is an ArrayList
> > + if (saveType && object instanceof ArrayList)
> > + saveType = false;
> >
> > if (saveType) {
> >
> > @@ -1093,6 +1098,15 @@
> > if (item != null)
> > marshal(item, elemDescriptor, handler);
> > }
> > + }
> > + //-- handle ArrayList
> > + else if (obj instanceof java.util.ArrayList) {
> > + Iterator it = ((ArrayList)obj).iterator();
> > + while (it.hasNext()) {
> > + Object item = it.next();
> > + if (item != null)
> > + marshal(item, elemDescriptor, handler);
> > + }
> > }
> >
> > else marshal(obj, elemDescriptor, handler);
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev