Hi Kieth,
Yeah, I have run into this before. I wrote the Java SecurityManager implementation
for Tomcat which required Java 2, yet Tomcat 3.x had to maintain compatability to
both compile and run under JDK 1.1. It was a real pain implementing support for that.
Java 2 is becoming pretty ubiquitous. Are you planning at some point requiring
Java 2 for Castor? Perhaps a survey of users to determine who still uses JDK 1.1
is in order.
For now, any who are interested can use the patch I posted. And I will maintain
it for my own build of castor.
Regards,
Glenn
Keith Visco wrote:
>
> Hi Glenn,
>
> We can't use your patch at this point. The reason we haven't done this
> ourselves is that the due to some of our users, the Marshaller needs to
> be JDK 1.1 compliant.
>
> We will be adding a way to directly support JDK 1.2 collections, without
> breaking the JDK 1.1 compliancy.
>
> JDK 1.2 collections are handled already in the Source Generator, because
> the user can choose the appropriate CollectionHandler.
>
> Thanks,
>
> --Keith
>
> Glenn Nielsen wrote:
> >
> > Attached is an updated patch for elements with maxOccurs > 1 which
> > switches the public {type} [] get method to public ArrayList get.
> >
> > Regards,
> >
> > Glenn
> >
> > Glenn Nielsen wrote:
> > >
> > > Attached is a patch which switchs the code generated for a get to
> > > return an ArrayList instead of converting the ArrayList to an object []
> > > array.
> > >
> > > Regards,
> > >
> > > Glenn
> > >
> > > Glenn Nielsen wrote:
> > >
> > > > I use Castor to generate java source for elements which have maxOccurs > 1.
> > > > I pass the arg -types j2 on the command line so that Castor will use Java 2
> > > > Collection types. Internally the code generated uses an ArrayList to store
> > > > the element values. But the get method for that element converts the
> > > > ArrayList
> > > > to an array, then returns the array. Shouldn't the get method just
> > > > return the
> > > > ArrayList if you specify -types j2 to the source generator?
> > > >
> > > > Regards,
> > > >
> > > > Glenn
> > > >
> > > > ----------------------------------------------------------------------
> > > > Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
> > > > MOREnet System Programming | * if iz ina coment. |
> > > > Missouri Research and Education Network | */ |
> > > > ----------------------------------------------------------------------
> > > >
> > > > ----------------------------------------------------------- If you wish
> > > > to unsubscribe from this mailing, send mail to
> > > > [EMAIL PROTECTED] with a subject of:
> > > > unsubscribe castor-dev
> > >
> > > --
> > > ----------------------------------------------------------------------
> > > Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
> > > MOREnet System Programming | * if iz ina coment. |
> > > Missouri Research and Education Network | */ |
> > > ----------------------------------------------------------------------
> > >
> > >
>------------------------------------------------------------------------------------------
> > > Name: castor-collectionj2.patch
> > > castor-collectionj2.patch Type: Plain Text (text/plain)
> > > Encoding: 7bit
> >
> > --
> > ----------------------------------------------------------------------
> > Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
> > MOREnet System Programming | * if iz ina coment. |
> > Missouri Research and Education Network | */ |
> > ----------------------------------------------------------------------
> >
> > ------------------------------------------------------------------------
> > diff -ur castor/src/main/org/exolab/castor/builder/CollectionInfoJ2.java
>castor-patched/src/main/org/exolab/castor/builder/CollectionInfoJ2.java
> > --- castor/src/main/org/exolab/castor/builder/CollectionInfoJ2.java Thu Aug 30
>14:49:24 2001
> > +++ castor-patched/src/main/org/exolab/castor/builder/CollectionInfoJ2.java
>Wed Nov 14 06:59:40 2001
> > @@ -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
> >
> > /**
> > diff -ur castor/src/main/org/exolab/castor/xml/Marshaller.java
>castor-patched/src/main/org/exolab/castor/xml/Marshaller.java
> > --- castor/src/main/org/exolab/castor/xml/Marshaller.java Mon Oct 29
>15:45:39 2001
> > +++ castor-patched/src/main/org/exolab/castor/xml/Marshaller.java Wed Nov 14
>09:00:38 2001
> > @@ -72,8 +72,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;
> >
> > /**
> > @@ -526,6 +528,7 @@
> > if (_debug) {
> > System.out.println("Marshalling " + object.getClass().getName());
> > }
> > +
> > if (object instanceof AnyNode) {
> > try{
> > AnyNode2SAX.fireEvents((AnyNode)object, _handler);
> > @@ -694,6 +697,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) {
> > // When the type of the instance of the field is not the
> > @@ -968,6 +974,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
--
----------------------------------------------------------------------
Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
MOREnet System Programming | * if iz ina coment. |
Missouri Research and Education Network | */ |
----------------------------------------------------------------------
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev