public NodePointer createChild( JXPathContext context, QName name, int index) { Object collection = createCollection(context, index); if (!isActual() || (index != 0 && index != WHOLE_COLLECTION)) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, collection, getName().toString(), index); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create object path: " + asPath()); } NodePointer cln = (NodePointer) clone(); cln.setIndex(index); return cln; } return this; }
public NodePointer createPath(JXPathContext context, Object value) { if (actual) { setValue(value); return this; } NodePointer ptr = createPath(context); ptr.setValue(value); return ptr; }
public NodePointer createPath(JXPathContext context) { if (!actual) { AbstractFactory factory = getAbstractFactory(context); if (!factory.declareVariable(context, name.toString())) { throw new JXPathAbstractFactoryException( "Factory cannot define variable '" + name + "' for path: " + asPath()); } findVariables(context); // Assert: actual == true } return this; }
public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = null; if (actual) { value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, null, value); } else { return new NullPointer(this, getName()) { public Object getImmediateNode() { throw new JXPathException( "Undefined variable: " + name); } }; } } return valuePointer; }
public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { Object collection = createCollection(context, index); ValueUtils.setValue(collection, index, value); NodePointer cl = (NodePointer) clone(); cl.setIndex(index); return cl; }
/** * 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 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); } } } }
public int getLength() { if (actual) { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } return 0; }
public NodePointer createNodePointer(QName name, Object object, Locale locale) { if (object instanceof VariableContextWrapper) { JXPathContext varCtx = ((VariableContextWrapper) object).getContext(); while (varCtx != null) { Variables vars = varCtx.getVariables(); if (vars.isDeclaredVariable(name.toString())) { return new VariablePointer(vars, name); } varCtx = varCtx.getParentContext(); } // The variable is not declared, but we will create // a pointer anyway in case the user wants to set, rather // than get, the value of the variable. return new VariablePointer(name); } return null; }
public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); }
public Object getImmediateNode() { Object value = getBaseValue(); return index == WHOLE_COLLECTION ? ValueUtils.getValue(value) : ValueUtils.getValue(value, index); }
public void setValue(Object value) { if (!actual) { throw new JXPathException("Cannot set undefined variable: " + name); } valuePointer = null; if (index != WHOLE_COLLECTION) { Object collection = getBaseValue(); ValueUtils.setValue(collection, index, value); } else { variables.declareVariable(name.toString(), value); } }