FileDocCategorySizeDatePackage
ListELResolver.javaAPI DocApache Tomcat 6.0.145145Fri Jul 20 04:20:32 BST 2007javax.el

ListELResolver

public class ListELResolver extends ELResolver

Fields Summary
private final boolean
readOnly
private static final Class
UNMODIFIABLE
Constructors Summary
public ListELResolver()


	  
		this.readOnly = false;
	
public ListELResolver(boolean readOnly)

		this.readOnly = readOnly;
	
Methods Summary
private static final intcoerce(java.lang.Object property)

		if (property instanceof Number) {
			return ((Number) property).intValue();
		}
		if (property instanceof Character) {
			return ((Character) property).charValue();
		}
		if (property instanceof Boolean) {
			return (((Boolean) property).booleanValue() ? 1 : 0);
		}
        if (property instanceof String) {
            return Integer.parseInt((String) property);
        }
		throw new IllegalArgumentException(property != null ? property
				.toString() : "null");
	
public java.lang.ClassgetCommonPropertyType(javax.el.ELContext context, java.lang.Object base)

		if (base != null && base instanceof List) {
			return Integer.class;
		}
		return null;
	
public java.util.IteratorgetFeatureDescriptors(javax.el.ELContext context, java.lang.Object base)

		if (base instanceof List) {
			FeatureDescriptor[] descs = new FeatureDescriptor[((List) base).size()];
			for (int i = 0; i < descs.length; i++) {
				descs[i] = new FeatureDescriptor();
				descs[i].setDisplayName("["+i+"]");
				descs[i].setExpert(false);
				descs[i].setHidden(false);
				descs[i].setName(""+i);
				descs[i].setPreferred(true);
				descs[i].setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.FALSE);
				descs[i].setValue(TYPE, Integer.class);
			}
			return Arrays.asList(descs).iterator();
		}
		return null;
	
public java.lang.ClassgetType(javax.el.ELContext context, java.lang.Object base, java.lang.Object property)

		if (context == null) {
			throw new NullPointerException();
		}

		if (base instanceof List) {
			context.setPropertyResolved(true);
			List list = (List) base;
			int idx = coerce(property);
			if (idx < 0 || idx >= list.size()) {
				return null;
			}
			Object obj = list.get(idx);
			return (obj != null) ? obj.getClass() : null;
		}

		return null;
	
public java.lang.ObjectgetValue(javax.el.ELContext context, java.lang.Object base, java.lang.Object property)

		if (context == null) {
			throw new NullPointerException();
		}

		if (base instanceof List) {
			context.setPropertyResolved(true);
			List list = (List) base;
			int idx = coerce(property);
			if (idx < 0 || idx >= list.size()) {
				return null;
			}
			return list.get(idx);
		}

		return null;
	
public booleanisReadOnly(javax.el.ELContext context, java.lang.Object base, java.lang.Object property)

		if (context == null) {
			throw new NullPointerException();
		}

		if (base instanceof List) {
			context.setPropertyResolved(true);
			List list = (List) base;
			int idx = coerce(property);
			if (idx < 0 || idx >= list.size()) {
				throw new PropertyNotFoundException(
						new ArrayIndexOutOfBoundsException(idx).getMessage());
			}
			return this.readOnly || UNMODIFIABLE.equals(list.getClass());
		}

		return this.readOnly;
	
public voidsetValue(javax.el.ELContext context, java.lang.Object base, java.lang.Object property, java.lang.Object value)

		if (context == null) {
			throw new NullPointerException();
		}

		if (base instanceof List) {
			context.setPropertyResolved(true);
			List list = (List) base;

			if (this.readOnly) {
				throw new PropertyNotWritableException(message(context,
						"resolverNotWriteable", new Object[] { base.getClass()
								.getName() }));
			}

			int idx = coerce(property);
			try {
				list.set(idx, value);
			} catch (UnsupportedOperationException e) {
				throw new PropertyNotWritableException(e);
			} catch (IndexOutOfBoundsException e) {
				throw new PropertyNotFoundException(e);
			}
		}