@Override public EStructuralFeaturePointer getPropertyPointer() { return new EObjectPropertyPointer(this, beanInfo); }
@Override 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); } }
/** * Select a property by name. * @param propertyName String name */ @Override public void setPropertyName(String propertyName) { setPropertyIndex(UNSPECIFIED_PROPERTY); this.propertyName = propertyName; }
/** * Get the value of the currently selected property. * @return Object value */ @Override public Object getBaseValue() { if (baseValue == UNINITIALIZED) { EStructuralFeature pd = getPropertyDescriptor(); if (pd == null) { return null; } baseValue = ValueUtils.getValue(getBean(), pd); } return baseValue; }
/** * 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 */ @Override public Object getImmediateNode() { if (value == UNINITIALIZED) { if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(getBaseValue()); } else { EStructuralFeature 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 */ @Override public void setValue(Object value) { EStructuralFeature 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; }
/** * Finds the property descriptor corresponding to the current property * index. * @return PropertyDescriptor */ private EStructuralFeature getPropertyDescriptor() { if (propertyDescriptor == null) { int inx = getPropertyIndex(); if (inx == UNSPECIFIED_PROPERTY) { propertyDescriptor = beanInfo.getPropertyDescriptor(propertyName); } else { EStructuralFeature[] propertyDescriptors = getPropertyDescriptors(); if (inx >= 0 && inx < propertyDescriptors.length) { propertyDescriptor = propertyDescriptors[inx]; } else { propertyDescriptor = null; } } } return propertyDescriptor; }
@Override public boolean isCollection() { EStructuralFeature pd = getPropertyDescriptor(); if (pd == null) { return false; } if( pd.isMany() ) { return true; } // if (pd instanceof IndexedPropertyDescriptor) { // return true; // } // int hint = ValueUtils.getCollectionHint(pd.getEType().getInstanceClass()); if (hint == -1) { return false; } if (hint == 1) { return true; } Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); }
@Override public int getPropertyCount() { if (beanInfo.isAtomic()) { return 0; } return getPropertyDescriptors().length; }
@Override protected boolean isActualProperty() { return getPropertyDescriptor() != null; }
@Override public NodePointer createPath(JXPathContext context) { if (getImmediateNode() == null) { super.createPath(context); baseValue = UNINITIALIZED; value = UNINITIALIZED; } return this; }
@Override public void setIndex(int index) { if (this.index == index) { return; } // When dealing with a scalar, index == 0 is equivalent to // WHOLE_COLLECTION, so do not change it. if (this.index != WHOLE_COLLECTION || index != 0 || isCollection()) { super.setIndex(index); value = UNINITIALIZED; } }
/** * 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 */ @Override public Object getImmediateNode() { if (value == UNINITIALIZED) { if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(getBaseValue()); } else { EStructuralFeature 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 */ @Override public void setValue(Object value) { EStructuralFeature 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; }
/** * Get the value of the currently selected property. * @return Object value */ @Override public Object getBaseValue() { if (baseValue == UNINITIALIZED) { EStructuralFeature pd = getPropertyDescriptor(); if (pd == null) { return null; } baseValue = ValueUtils.getValue(getBean(), pd); } return baseValue; }
/** * Finds the property descriptor corresponding to the current property * index. * @return PropertyDescriptor */ private EStructuralFeature getPropertyDescriptor() { if (propertyDescriptor == null) { int inx = getPropertyIndex(); if (inx == UNSPECIFIED_PROPERTY) { propertyDescriptor = beanInfo.getPropertyDescriptor(propertyName); } else { EStructuralFeature[] propertyDescriptors = getPropertyDescriptors(); if (inx >= 0 && inx < propertyDescriptors.length) { propertyDescriptor = propertyDescriptors[inx]; } else { propertyDescriptor = null; } } } return propertyDescriptor; }
@Override public boolean isCollection() { EStructuralFeature pd = getPropertyDescriptor(); if (pd == null) { return false; } if( pd.isMany() ) { return true; } // if (pd instanceof IndexedPropertyDescriptor) { // return true; // } // int hint = ValueUtils.getCollectionHint(pd.getEType().getInstanceClass()); if (hint == -1) { return false; } if (hint == 1) { return true; } Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); }
@Override public int getPropertyCount() { if (beanInfo.isAtomic()) { return 0; } return getPropertyDescriptors().length; }
@Override protected boolean isActualProperty() { return getPropertyDescriptor() != null; }
@Override public NodePointer createPath(JXPathContext context) { if (getImmediateNode() == null) { super.createPath(context); baseValue = UNINITIALIZED; value = UNINITIALIZED; } return this; }