FileDocCategorySizeDatePackage
IteratedExpression.javaAPI DocGlassfish v2 API4812Sat May 05 19:17:14 BST 2007javax.servlet.jsp.jstl.core

IteratedExpression

public final class IteratedExpression extends Object
author
Kin-man Chung
version
$Id: IteratedExpression.java,v 1.7 2007/05/06 02:17:13 tcfujii Exp $

Fields Summary
private static final long
serialVersionUID
protected final ValueExpression
orig
protected final String
delims
private Object
base
private int
index
private Iterator
iter
Constructors Summary
public IteratedExpression(ValueExpression orig, String delims)


         
        this.orig = orig;
        this.delims = delims;
    
Methods Summary
public java.lang.ObjectgetItem(javax.el.ELContext context, int i)
Evaluates the stored ValueExpression and return the indexed item.

param
context The ELContext used to evaluate the ValueExpression
param
i The index of the item to be retrieved


        if (base == null) {
            base = orig.getValue(context);
            if (base == null) {
                return null;
            }
            iter = toIterator(base);
            index = 0;
        }
        if (index > i) {
            // Restart from index 0
            iter = toIterator(base);
            index = 0;
        }
        while (iter.hasNext()) {
            Object item = iter.next();
            if (index++ == i) {
                return item;
            }
        }
        return null;
    
public javax.el.ValueExpressiongetValueExpression()

        return orig;
    
private java.util.IteratortoIterator(java.lang.Object obj)


        Iterator iter;
        if (obj instanceof String) {
            iter = toIterator(new StringTokenizer((String)obj, delims));
        }
        else if (obj instanceof Iterator) {
            iter = (Iterator)obj;
        }
        else if (obj instanceof Collection) {
            iter = toIterator(((Collection) obj).iterator());
        }
        else if (obj instanceof Enumeration) {
            iter = toIterator((Enumeration)obj);
        }
        else if (obj instanceof Map) {
            iter = ((Map)obj).entrySet().iterator();
        } else {
            throw new ELException("Don't know how to iterate over supplied "
                                  + "items in forEach");
        }
        return iter;
    
private java.util.IteratortoIterator(java.util.Enumeration obj)

        return new Iterator() {
            public boolean hasNext() {
                return obj.hasMoreElements();
            }
            public Object next() {
                return obj.nextElement();
            }
            public void remove() {}
        };