struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Geary <sabrew...@tri-lakesonline.net>
Subject Re: JDK 1.1 support (was RE: Java2 Compatibility)
Date Mon, 03 Jul 2000 19:44:12 GMT
Marius Sorin Barduta wrote:

> Maybe I don't get the point but the proposed IteratorAdapter doesn't compile
> nor run under JDK 1.1. (because it uses Iterator which is defined in JDK
> 1.2)
> So, under JDK 1.1,  how can I use the tag that use this Adapter?

It compiles under Java2 ... see Craig's first sentence below.


david

> Marius
>
> > "Craig R. McClanahan" wrote:
> >
> > > Struts requires Java2 for compilation, but runs on JDK 1.1 platforms if
> you avoid
> > > the custom tags that utilize the collections classes.  In most cases,
> there are
> > > substitute tags available that are JDK 1.1 compatible (enmerate instead
> of
> > > iterate).  If you find any cases where this is not the case, I'd
> certainly like to
> > > have one (such as a new "options1" tag that is like "options" but uses
> JDK 1.1
> > > collections instead of Java2 collections.
> >
> > I think we can have struts work with both types of collections without
> duplicate tags;
> > here's how:
> >
> > The tag classes would use an adapter that converts a 1.1 interface into a
> Java2
> > collections interface. For example, the enumerate and iterate tags differ
> in how they
> > traverse their collections; enumerate uses java.util.Enumeration and
> iterate uses
> > java.util.Iterator. The enumerate and iterate tags could be collapsed into
> one tag and
> > that tag would use an IteratorAdapter. The adapter is listed below:
> >
> > package org.apache.struts.util;
> >
> > import java.util.*;
> >
> > public class IteratorAdapter implements Iterator {
> >  private Object collection;
> >  private Iterator iterator=null;
> >  private Enumeration enumeration=null;
> >
> >  public IteratorAdapter(Object collection) {
> >   this.collection = collection;
> >
> >   // extract iterator from collection with code that
> >   // is currently in IterateTag.doStartTag() and
> >   // EnumerateTag.doStartTag(), ie:
> >   //
> >   // if (collection.getClass().isArray())
> >     //    collection = Arrays.asList((Object[]) collection);
> >     // if (collection instanceof Collection)
> >     //   iterator = ((Collection) collection).iterator();
> >   // else if (collection instanceof Iterator)
> >   //    ...
> >   //
> >   // assign EITHER iterator or enumeration, one is left null
> >  }
> >  public boolean hasNext() {
> >   if(iterator != null)
> >    return iterator.hasNext();
> >   else
> >    return enumeration.hasMoreElements();
> >  }
> >  public Object next() {
> >   if(iterator != null)
> >    return iterator.next();
> >   else
> >    return enumeration.nextElement();
> >  }
> >  public void remove() {
> >   throw new Error("IteratorAdapter.remove() not implemented");
> >  }
> > }
> >
> >
> > david
> >
> >


Mime
View raw message