public boolean isCollection() { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return false; } if (pd instanceof IndexedPropertyDescriptor) { return true; } int hint = ValueUtils.getCollectionHint(pd.getPropertyType()); if (hint == -1) { return false; } if (hint == 1) { return true; } Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); }
public void remove() { if (index == WHOLE_COLLECTION) { setValue(null); } else if (isCollection()) { Object o = getBaseValue(); Object collection = ValueUtils.remove(getBaseValue(), index); if (collection != o) { ValueUtils.setValue(getBean(), getPropertyDescriptor(), collection); } } else if (index == 0) { index = WHOLE_COLLECTION; setValue(null); } }
/** * If the property contains a collection, then the length of that * collection, otherwise - 1. * @return int length */ public int getLength() { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return 1; } if (pd instanceof IndexedPropertyDescriptor) { return ValueUtils.getIndexedPropertyLength( getBean(), (IndexedPropertyDescriptor) pd); } int hint = ValueUtils.getCollectionHint(pd.getPropertyType()); if (hint == -1) { return 1; } return ValueUtils.getLength(getBaseValue()); }
/** * If index == WHOLE_COLLECTION, the value of the property, otherwise * the value of the index'th element of the collection represented by the * property. If the property is not a collection, index should be zero * and the value will be the property itself. * @return Object */ public Object getImmediateNode() { if (value == UNINITIALIZED) { if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(getBaseValue()); } else { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { value = null; } else { value = ValueUtils.getValue(getBean(), pd, index); } } } return value; }