public AtomicValue next() throws XPathException { while (true) { if (results != null) { if (atomicPosition < results.getLength()) { return results.itemAt(atomicPosition++); } else { results = null; continue; } } AtomicSequence atomized = base.nextAtomizedValue(); if (atomized == null) { results = null; return null; } if (atomized instanceof AtomicValue) { // common case (the atomized value of the node is a single atomic value) results = null; return (AtomicValue) atomized; } else { results = atomized; atomicPosition = 0; // continue } } }
public AtomicValue next() throws XPathException { while (true) { if (results != null) { if (atomicPosition < results.getLength()) { return results.itemAt(atomicPosition++); } else { results = null; continue; } } AtomicSequence atomized = base.nextAtomizedValue(); if (atomized == null) { results = null; return null; } if (atomized instanceof AtomicValue) { // common case (the atomized value of the node is a single atomic value) results = null; return (AtomicValue) atomized; } else { results = atomized; atomicPosition = 0; // continue } } }
/** * Ask whether an element is an ID element. (The represents the * is-id property in the data model) * * @param nr the element node whose is-id property is required * @return true if the node has the is-id property */ public boolean isIdElement(int nr) { try { return getSchemaType(nr).isIdType() && getTypedValueOfElement(nr).getLength() == 1; } catch (XPathException e) { return false; } }
/** * Ask whether an element is an ID element. (The represents the * is-id property in the data model) * * @param nr the element node whose is-id property is required * @return true if the node has the is-id property */ public boolean isIdElement(int nr) { try { return getSchemaType(nr).isIdType() && getTypedValueOfElement(nr).getLength() == 1; } catch (XPathException e) { return false; } }
public static XdmValue wrap(AtomicSequence value) { switch (value.getLength()) { case 0: return XdmEmptySequence.getInstance(); case 1: return new XdmAtomicValue(value.head(), true); default: return fromGroundedValue(value); } }
public static XdmValue wrap(AtomicSequence value) { switch (value.getLength()) { case 0: return XdmEmptySequence.getInstance(); case 1: return new XdmAtomicValue(value.head(), true); default: return fromGroundedValue(value); } }
public AtomicValue next() throws XPathException { while (true) { if (currentValue != null) { if (currentValuePosition < currentValueSize) { return currentValue.itemAt(currentValuePosition++); } else { currentValue = null; } } Item nextSource = base.next(); if (nextSource != null) { AtomicSequence v = nextSource.atomize(); if (v instanceof AtomicValue) { return (AtomicValue) v; } else { currentValue = v; currentValuePosition = 0; currentValueSize = currentValue.getLength(); // now go round the loop to get the first item from the atomized value } } else { currentValue = null; return null; } } }
@Override public GroundedValue evaluate(Item item, XPathContext context) throws XPathException { SystemFunction f = SystemFunction.makeFunction(getDetails().name.getLocalPart(), getRetainedStaticContext(), 1); AtomicSequence val = item.atomize(); switch (val.getLength()) { case 0: return DoubleValue.NaN; case 1: return f.call(context, new Sequence[]{val.head()}).materialize(); default: XPathException err = new XPathException( "When number() is called with no arguments, the atomized value of the context node must " + "not be a sequence of several atomic values", "XPTY0004"); err.setIsTypeError(true); throw err; } }
currentValue = v; currentValuePosition = 0; currentValueSize = currentValue.getLength();
@Override public GroundedValue evaluate(Item item, XPathContext context) throws XPathException { SystemFunction f = SystemFunction.makeFunction(getDetails().name.getLocalPart(), getRetainedStaticContext(), 1); AtomicSequence val = item.atomize(); switch (val.getLength()) { case 0: return DoubleValue.NaN; case 1: return f.call(context, new Sequence[]{val.head()}).materialize(); default: XPathException err = new XPathException( "When number() is called with no arguments, the atomized value of the context node must " + "not be a sequence of several atomic values", "XPTY0004"); err.setIsTypeError(true); throw err; } }
/** * Evaluate as an Item. This should only be called if a singleton or empty sequence is required; * it throws a type error if the underlying sequence is multi-valued. */ public AtomicValue evaluateItem(XPathContext context) throws XPathException { int found = 0; AtomicValue result = null; SequenceIterator iter = getBaseExpression().iterate(context); Item item; while ((item = iter.next()) != null) { AtomicSequence seq = item.atomize(); found += seq.getLength(); if (found > 1) { typeError( "A sequence of more than one item is not allowed as the " + role.getMessage() + CardinalityChecker.depictSequenceStart(getBaseExpression().iterate(context), 3), role.getErrorCode(), context); } if (found == 1) { result = seq.head(); } } if (found == 0 && !allowEmpty) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), null); } return result; }
/** * Evaluate as an Item. This should only be called if a singleton or empty sequence is required; * it throws a type error if the underlying sequence is multi-valued. */ public AtomicValue evaluateItem(XPathContext context) throws XPathException { int found = 0; AtomicValue result = null; SequenceIterator iter = getBaseExpression().iterate(context); Item item; while ((item = iter.next()) != null) { AtomicSequence seq = item.atomize(); found += seq.getLength(); if (found > 1) { typeError( "A sequence of more than one item is not allowed as the " + role.getMessage() + CardinalityChecker.depictSequenceStart(getBaseExpression().iterate(context), 3), role.getErrorCode(), context); } if (found == 1) { result = seq.head(); } } if (found == 0 && !allowEmpty) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), null); } return result; }