/** * Create a collection of a given type. * @param type destination class * @return Collection */ protected Collection allocateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { return (Collection) type.newInstance(); } catch (Exception ex) { throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type, ex); } } if (type == List.class || type == Collection.class) { return new ArrayList(); } if (type == Set.class) { return new HashSet(); } throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type); }
ex = ((InvocationTargetException) ex).getTargetException(); throw new JXPathInvalidAccessException( "Cannot invoke constructor " + constructor, ex);
/** * Throws an exception if you try to change the root element, otherwise * forwards the call to the parent pointer. * @param value to set */ @Override public void setValue(Object value) { this.value = value; if (parent != null) { if (parent.isContainer()) { parent.setValue(value); } else { if (index == WHOLE_COLLECTION) { throw new UnsupportedOperationException( "Cannot setValue of an object that is not " + "some other object's property"); } throw new JXPathInvalidAccessException( "The specified collection element does not exist: " + this); } } else { throw new UnsupportedOperationException( "Cannot replace the root object"); } }
/** * Throws an exception if you try to change the root element, otherwise * forwards the call to the parent pointer. * @param value to set */ public void setValue(Object value) { this.value = value; if (parent != null) { if (parent.isContainer()) { parent.setValue(value); } else { if (index == WHOLE_COLLECTION) { throw new UnsupportedOperationException( "Cannot setValue of an object that is not " + "some other object's property"); } throw new JXPathInvalidAccessException( "The specified collection element does not exist: " + this); } } else { throw new UnsupportedOperationException( "Cannot replace the root object"); } }
/** * Throws an exception if you try to change the root element, otherwise * forwards the call to the parent pointer. * @param value to set */ @Override public void setValue(Object value) { this.value = value; if (parent != null) { if (parent.isContainer()) { parent.setValue(value); } else { if (index == WHOLE_COLLECTION) { throw new UnsupportedOperationException( "Cannot setValue of an object that is not " + "some other object's property"); } throw new JXPathInvalidAccessException( "The specified collection element does not exist: " + this); } } else { throw new UnsupportedOperationException( "Cannot replace the root object"); } }
ex = ((InvocationTargetException) ex).getTargetException(); throw new JXPathInvalidAccessException("Cannot invoke " + method, ex);
@Override public void setValue(Object value) { if (parent == null || parent.isContainer()) { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", the target object is null"); } if (parent instanceof EStructuralFeatureOwnerPointer && ((EStructuralFeatureOwnerPointer) parent) .isDynamicPropertyDeclarationSupported()) { // If the parent property owner can create // a property automatically - let it do so EStructuralFeaturePointer propertyPointer = ((EStructuralFeatureOwnerPointer) parent).getPropertyPointer(); propertyPointer.setPropertyName(propertyName); propertyPointer.setValue(value); } else { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", path does not match a changeable location"); } }
public void setValue(Object value) { if (parent == null || parent.isContainer()) { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", the target object is null"); } if (parent instanceof PropertyOwnerPointer && ((PropertyOwnerPointer) parent) .isDynamicPropertyDeclarationSupported()) { // If the parent property owner can create // a property automatically - let it do so PropertyPointer propertyPointer = ((PropertyOwnerPointer) parent).getPropertyPointer(); propertyPointer.setPropertyName(propertyName); propertyPointer.setValue(value); } else { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", path does not match a changeable location"); } }
@Override public void setValue(Object value) { if (parent == null || parent.isContainer()) { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", the target object is null"); } if (parent instanceof EStructuralFeatureOwnerPointer && ((EStructuralFeatureOwnerPointer) parent) .isDynamicPropertyDeclarationSupported()) { // If the parent property owner can create // a property automatically - let it do so EStructuralFeaturePointer propertyPointer = ((EStructuralFeatureOwnerPointer) parent).getPropertyPointer(); propertyPointer.setPropertyName(propertyName); propertyPointer.setValue(value); } else { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", path does not match a changeable location"); } }
/** * 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; }
/** * 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; }
/** * 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; }
public void remove() { if (actual) { if (index == WHOLE_COLLECTION) { variables.undeclareVariable(name.toString()); } else { if (index < 0) { throw new JXPathInvalidAccessException( "Index is less than 1: " + asPath()); } Object collection = getBaseValue(); if (collection != null && index < getLength()) { collection = ValueUtils.remove(collection, index); variables.declareVariable(name.toString(), collection); } } } }
/** * Create a collection. * @param context JXPathContext * @param index collection index * @return Object */ private Object createCollection(JXPathContext context, int index) { createPath(context); Object collection = getBaseValue(); if (collection == null) { throw new JXPathAbstractFactoryException( "Factory did not assign a collection to variable '" + name + "' for path: " + asPath()); } if (index == WHOLE_COLLECTION) { index = 0; } else if (index < 0) { throw new JXPathInvalidAccessException("Index is less than 1: " + asPath()); } if (index >= getLength()) { collection = ValueUtils.expandCollection(collection, index + 1); variables.declareVariable(name.toString(), collection); } return collection; }
public NodePointer createPath(JXPathContext context) { // Ignore the name passed to us, use our own data Object collection = getBaseValue(); if (collection == null) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, getBean(), getPropertyName(), 0); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create an object for path: " + asPath()); } collection = getBaseValue(); } if (index != WHOLE_COLLECTION) { if (index < 0) { throw new JXPathInvalidAccessException("Index is less than 1: " + asPath()); } if (index >= getLength()) { collection = ValueUtils.expandCollection(collection, index + 1); handler.setProperty(getBean(), getPropertyName(), collection); } } return this; }