FileDocCategorySizeDatePackage
ArrayELResolver.javaAPI DocApache Tomcat 6.0.144866Fri Jul 20 04:20:32 BST 2007javax.el

ArrayELResolver

public class ArrayELResolver extends ELResolver

Fields Summary
private final boolean
readOnly
Constructors Summary
public ArrayELResolver()

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

		this.readOnly = readOnly;
	
Methods Summary
private static final voidcheckBounds(java.lang.Object base, int idx)

		if (idx < 0 || idx >= Array.getLength(base)) {
			throw new PropertyNotFoundException(
					new ArrayIndexOutOfBoundsException(idx).getMessage());
		}
	
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.getClass().isArray()) {
			return Integer.class;
		}
		return null;
	
public java.util.IteratorgetFeatureDescriptors(javax.el.ELContext context, java.lang.Object base)

		if (base != null && base.getClass().isArray()) {
			FeatureDescriptor[] descs = new FeatureDescriptor[Array.getLength(base)];
			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 != null && base.getClass().isArray()) {
			context.setPropertyResolved(true);
			int idx = coerce(property);
			checkBounds(base, idx);
			return base.getClass().getComponentType();
		}

		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 != null && base.getClass().isArray()) {
			context.setPropertyResolved(true);
			int idx = coerce(property);
            if (idx < 0 || idx >= Array.getLength(base)) {
                return null;
            } else {
                return Array.get(base, 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 != null && base.getClass().isArray()) {
			context.setPropertyResolved(true);
			int idx = coerce(property);
			checkBounds(base, idx);
		}

		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 != null && base.getClass().isArray()) {
			context.setPropertyResolved(true);

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

			int idx = coerce(property);
			checkBounds(base, idx);
			Array.set(base, idx, value);
		}