/** * Convert the pattern to a typed pattern, in which an element name is treated as * schema-element(N) * * @param val either "strict" or "lax" depending on the value of xsl:mode/@typed * @return either the original pattern unchanged, or a new pattern as the result of the * conversion * @throws net.sf.saxon.trans.XPathException if the pattern cannot be converted */ @Override public Pattern convertToTypedPattern(String val) throws XPathException { Pattern b2 = getBasePattern().convertToTypedPattern(val); if (b2 == getBasePattern()) { return this; } else { return new BasePatternWithPredicate(b2, getPredicate()); } }
public BasePatternWithPredicate(Pattern basePattern, Expression predicate) { basePatternOp = new Operand(this, basePattern, OperandRole.ATOMIC_SEQUENCE); predicateOp = new Operand(this, predicate, OperandRole.FOCUS_CONTROLLED_ACTION); adoptChildExpression(getBasePattern()); adoptChildExpression(getPredicate()); }
@Override public boolean matchesBeneathAnchor(NodeInfo node, NodeInfo anchor, XPathContext context) throws XPathException { return getBasePattern().matchesBeneathAnchor(node, anchor, context) && matchesPredicate(node, context); }
/** * Display the pattern for diagnostics */ public String toString() { return getBasePattern() + "[" + getPredicate() + "]"; }
/** * Replace any calls on current() by a variable reference bound to the supplied binding */ @Override public void bindCurrent(LocalBinding binding) { Expression predicate = getPredicate(); if (predicate.isCallOn(Current.class)) { predicateOp.setChildExpression(new LocalVariableReference(binding)); } else if (ExpressionTool.callsFunction(predicate, Current.FN_CURRENT, false)) { replaceCurrent(predicate, binding); } getBasePattern().bindCurrent(binding); }
/** * Determine the name fingerprint of nodes to which this pattern applies. Used for * optimisation. * * @return A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints, * or it if matches atomic values */ @Override public int getFingerprint() { return getBasePattern().getFingerprint(); }
private boolean matchesPredicate(Item<?> item, XPathContext context) throws XPathException { XPathContext c2 = context.newMinorContext(); ManualIterator<Item<?>> si = new ManualIterator<>(item); c2.setCurrentIterator(si); try { return getPredicate().effectiveBooleanValue(c2); } catch (XPathException.Circularity e) { throw e; } catch (XPathException ex) { handleDynamicError(ex, c2); return false; } }
BasePatternWithPredicate pp = new BasePatternWithPredicate( new NodeTestPattern(new MultipleNodeKindTest(UType.ELEMENT_OR_ATTRIBUTE)), IntegratedFunctionLibrary.makeFunctionCall(new IsIdRef(), new Expression[]{})
/** * Get the dependencies of the pattern. The only possible dependency for a pattern is * on local variables. This is analyzed in those patterns where local variables may appear. * * @return the dependencies, as a bit-significant mask */ @Override public int getDependencies() { return getPredicate().getDependencies(); }
/** * Get the immediate sub-expressions of this expression, with information about the relationship * of each expression to its parent expression. Default implementation * works off the results of iterateSubExpressions() * <p>If the expression is a Callable, then it is required that the order of the operands * returned by this function is the same as the order of arguments supplied to the corresponding * call() method.</p> * * @return an iterator containing the sub-expressions of this expression */ @Override public Iterable<Operand> operands() { return operandList(basePatternOp, predicateOp); }
/** * Display the pattern for diagnostics */ public String toString() { return getBasePattern() + "[" + getPredicate() + "]"; }
/** * Replace any calls on current() by a variable reference bound to the supplied binding */ @Override public void bindCurrent(LocalBinding binding) { Expression predicate = getPredicate(); if (predicate.isCallOn(Current.class)) { predicateOp.setChildExpression(new LocalVariableReference(binding)); } else if (ExpressionTool.callsFunction(predicate, Current.FN_CURRENT, false)) { replaceCurrent(predicate, binding); } getBasePattern().bindCurrent(binding); }
/** * Ask whether the pattern is anchored on a call on current-group() * * @return true if calls on matchesBeneathAnchor should test with all nodes in the * current group as anchor nodes. If false, only the first node in a group is * treated as the anchor node */ public boolean matchesCurrentGroup() { return getBasePattern().matchesCurrentGroup(); }
private boolean matchesPredicate(Item<?> item, XPathContext context) throws XPathException { XPathContext c2 = context.newMinorContext(); ManualIterator<Item<?>> si = new ManualIterator<>(item); c2.setCurrentIterator(si); try { return getPredicate().effectiveBooleanValue(c2); } catch (XPathException.Circularity e) { throw e; } catch (XPathException ex) { handleDynamicError(ex, c2); return false; } }
BasePatternWithPredicate pp = new BasePatternWithPredicate( new NodeTestPattern(new MultipleNodeKindTest(UType.ELEMENT_OR_ATTRIBUTE)), IntegratedFunctionLibrary.makeFunctionCall(new IsIdRef(), new Expression[]{})
/** * Get the dependencies of the pattern. The only possible dependency for a pattern is * on local variables. This is analyzed in those patterns where local variables may appear. * * @return the dependencies, as a bit-significant mask */ @Override public int getDependencies() { return getPredicate().getDependencies(); }
/** * Get the immediate sub-expressions of this expression, with information about the relationship * of each expression to its parent expression. Default implementation * works off the results of iterateSubExpressions() * <p>If the expression is a Callable, then it is required that the order of the operands * returned by this function is the same as the order of arguments supplied to the corresponding * call() method.</p> * * @return an iterator containing the sub-expressions of this expression */ @Override public Iterable<Operand> operands() { return operandList(basePatternOp, predicateOp); }
@Override public boolean equals(Object obj) { return obj instanceof BasePatternWithPredicate && ((BasePatternWithPredicate)obj).getBasePattern().isEqual(getBasePattern()) && ((BasePatternWithPredicate) obj).getPredicate().isEqual(getPredicate()); }
/** * Convert the pattern to a typed pattern, in which an element name is treated as * schema-element(N) * * @param val either "strict" or "lax" depending on the value of xsl:mode/@typed * @return either the original pattern unchanged, or a new pattern as the result of the * conversion * @throws net.sf.saxon.trans.XPathException if the pattern cannot be converted */ @Override public Pattern convertToTypedPattern(String val) throws XPathException { Pattern b2 = getBasePattern().convertToTypedPattern(val); if (b2 == getBasePattern()) { return this; } else { return new BasePatternWithPredicate(b2, getPredicate()); } }
public BasePatternWithPredicate(Pattern basePattern, Expression predicate) { basePatternOp = new Operand(this, basePattern, OperandRole.ATOMIC_SEQUENCE); predicateOp = new Operand(this, predicate, OperandRole.FOCUS_CONTROLLED_ACTION); adoptChildExpression(getBasePattern()); adoptChildExpression(getPredicate()); }