protected boolean isActualProperty() { return getPropertyDescriptor() != null; }
/** * Get the name of the currently selected property. * @return String property name */ public String getPropertyName() { if (propertyName == null) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd != null) { propertyName = pd.getName(); } } return propertyName != null ? propertyName : "*"; }
/** * Get the value of the currently selected property. * @return Object value */ public Object getBaseValue() { if (baseValue == UNINITIALIZED) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return null; } baseValue = ValueUtils.getValue(getBean(), pd); } return baseValue; }
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); }
/** * 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; }
/** * If index == WHOLE_COLLECTION, change the value of the property, otherwise * change the value of the index'th element of the collection * represented by the property. * @param value value to set */ public void setValue(Object value) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { throw new JXPathInvalidAccessException( "Cannot set property: " + asPath() + " - no such property"); } if (index == WHOLE_COLLECTION) { ValueUtils.setValue(getBean(), pd, value); } else { ValueUtils.setValue(getBean(), pd, index, value); } this.value = 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); } }