/** * * @param context * @param base * @param property * @return If the <code>propertyResolved</code> property of * <code>ELContext</code> was set to <code>true</code>, then * the value at the given index or <code>null</code> * if the index was out of bounds. Otherwise, undefined. */ @Override public Object getValue(ELContext context, Object base, Object property) { if (base instanceof List) { List list = (List) base; context.setPropertyResolved(true); int index = ArrayELResolver.getIndex(property); if (0 <= index && index < list.size()) return list.get(index); else return null; } else { return null; } }
@Override public boolean isReadOnly(ELContext context, Object base, Object property) { if (base instanceof List) { context.setPropertyResolved(true); int index = ArrayELResolver.getIndex(property); if (index < 0 || index >= ((List) base).size()) throw new PropertyNotFoundException("list index '" + index + "' is invalid"); return _isReadOnly; } else return false; }
/** * * @param context * @param base * @param property * @return If the <code>propertyResolved</code> property of * <code>ELContext</code> was set to <code>true</code>, then * the value at the given index or <code>null</code> * if the index was out of bounds. Otherwise, undefined. */ @Override public Object getValue(ELContext context, Object base, Object property) { if (base == null) return null; else if (base.getClass().isArray()) { context.setPropertyResolved(true); int index = getIndex(property); if (0 <= index && index < Array.getLength(base)) return Array.get(base, index); else return null; } else { return null; } }
@Override public Class<?> getType(ELContext context, Object base, Object property) { if (base == null) return null; else if (base.getClass().isArray()) { context.setPropertyResolved(true); int index = getIndex(property); if (index < 0 || Array.getLength(base) <= index) throw new PropertyNotFoundException("array index '" + index + "' is invalid"); return base.getClass().getComponentType(); } else return null; }
@Override public boolean isReadOnly(ELContext context, Object base, Object property) { if (base == null) return false; else if (base.getClass().isArray()) { context.setPropertyResolved(true); int index = getIndex(property); if (index < 0 || index >= Array.getLength(base)) throw new PropertyNotFoundException("array index '" + index + "' is invalid"); return _isReadOnly; } else return false; }
@Override public Class<?> getType(ELContext context, Object base, Object property) { if (context == null) throw new NullPointerException(); if (base instanceof List) { context.setPropertyResolved(true); int index = ArrayELResolver.getIndex(property); if (index < 0 || ((List) base).size() <= index) throw new PropertyNotFoundException("list index '" + index + "' is invalid"); return Object.class; } else return null; }
@Override public void setValue(ELContext context, Object base, Object property, Object value) { if (base == null) { } else if (base.getClass().isArray()) { context.setPropertyResolved(true); if (_isReadOnly) throw new PropertyNotWritableException("resolver is read-only"); int index = getIndex(property); Class componentType = base.getClass().getComponentType(); if (value != null && ! componentType.isAssignableFrom(value.getClass())) { throw new ClassCastException(value.getClass().getName() + " cannot be cast to " + componentType.getName()); } else if (0 <= index && index < Array.getLength(base)) Array.set(base, index, value); else throw new PropertyNotFoundException("array index '" + index + "' is invalid"); } }
@Override public void setValue(ELContext context, Object base, Object property, Object value) { if (base instanceof List) { List list = (List) base; context.setPropertyResolved(true); int index = ArrayELResolver.getIndex(property); if (_isReadOnly) throw new PropertyNotWritableException("resolver is read-only"); if (index < 0 || list.size() < index) throw new PropertyNotFoundException("list index '" + index + "' is invalid"); list.set(index, value); } } }