/** * Gather the component (non-union) patterns of this union pattern * @param set the set into which the components will be added */ public void gatherComponentPatterns(Set set) { if (p1 instanceof UnionPattern) { ((UnionPattern)p1).gatherComponentPatterns(set); } else { set.add(p1); } if (p2 instanceof UnionPattern) { ((UnionPattern)p2).gatherComponentPatterns(set); } else { set.add(p2); } }
/** * Constructor * * @param p1 the left-hand operand * @param p2 the right-hand operand */ public UnionPattern(Pattern p1, Pattern p2) { super(p1, p2); // default is to take the priority from the component patterns setPriority(Double.NaN); }
/** * Register a handler for a particular pattern. The priority of the rule * is the default priority for the pattern, which depends on the syntax of * the pattern suppllied. * @param pattern A match pattern * @param eh The ElementHandler to be used * @param mode The processing mode * @param precedence The import precedence (use 0 by default) */ public void setHandler(Pattern pattern, Template eh, Mode mode, int precedence) { // for a union pattern, register the parts separately (each with its own priority) if (pattern instanceof UnionPattern) { UnionPattern up = (UnionPattern)pattern; Pattern p1 = up.getLHS(); Pattern p2 = up.getRHS(); setHandler(p1, eh, mode, precedence); setHandler(p2, eh, mode, precedence); return; } double priority = pattern.getDefaultPriority(); setHandler(pattern, eh, mode, precedence, priority); }
/** * 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 np1 = p1.convertToTypedPattern(val); Pattern np2 = p2.convertToTypedPattern(val); if (p1 == np1 && p2 == np2) { return this; } else { return new UnionPattern(np1, np2); } }
/** * Register a handler for a particular pattern. The priority of the rule * is the default priority for the pattern, which depends on the syntax of * the pattern suppllied. * @param pattern A match pattern * @param eh The ElementHandler to be used * @param mode The processing mode * @param precedence The import precedence (use 0 by default) */ public void setHandler(Pattern pattern, Template eh, Mode mode, int precedence) { // for a union pattern, register the parts separately (each with its own priority) if (pattern instanceof UnionPattern) { UnionPattern up = (UnionPattern)pattern; Pattern p1 = up.getLHS(); Pattern p2 = up.getRHS(); setHandler(p1, eh, mode, precedence); setHandler(p2, eh, mode, precedence); return; } double priority = pattern.getDefaultPriority(); setHandler(pattern, eh, mode, precedence, priority); }
/** * 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 np1 = p1.convertToTypedPattern(val); Pattern np2 = p2.convertToTypedPattern(val); if (p1 == np1 && p2 == np2) { return this; } else { return new UnionPattern(np1, np2); } }
/** * Register a handler for a particular pattern. The priority of the rule * is the default priority for the pattern, which depends on the syntax of * the pattern suppllied. * @param pattern A match pattern * @param eh The ElementHandler to be used * @param mode The processing mode * @param precedence The import precedence (use 0 by default) */ public void setHandler(Pattern pattern, Template eh, Mode mode, int precedence) { // for a union pattern, register the parts separately (each with its own priority) if (pattern instanceof UnionPattern) { UnionPattern up = (UnionPattern)pattern; Pattern p1 = up.getLHS(); Pattern p2 = up.getRHS(); setHandler(p1, eh, mode, precedence); setHandler(p2, eh, mode, precedence); return; } double priority = pattern.getDefaultPriority(); setHandler(pattern, eh, mode, precedence, priority); }
/** * Copy a pattern. This makes a deep copy. * * @return the copy of the original pattern * @param rebindings variables that need to be re-bound */ /*@NotNull*/ public Pattern copy(RebindingMap rebindings) { UnionPattern n = new UnionPattern(p1.copy(rebindings), p2.copy(rebindings)); ExpressionTool.copyLocationInfo(this, n); return n; }
/** * Determine whether this pattern is the same as another pattern * @param other the other object */ public boolean equals(Object other) { if (other instanceof UnionPattern) { Set s0 = new HashSet(10); gatherComponentPatterns(s0); Set s1 = new HashSet(10); ((UnionPattern)other).gatherComponentPatterns(s1); return s0.equals(s1); } else { return false; } }
/** * Constructor * * @param p1 the left-hand operand * @param p2 the right-hand operand */ public UnionPattern(Pattern p1, Pattern p2) { super(p1, p2); // default is to take the priority from the component patterns setPriority(Double.NaN); }
/** * Copy a pattern. This makes a deep copy. * * @return the copy of the original pattern * @param rebindings variables that need to be re-bound */ /*@NotNull*/ public Pattern copy(RebindingMap rebindings) { UnionPattern n = new UnionPattern(p1.copy(rebindings), p2.copy(rebindings)); ExpressionTool.copyLocationInfo(this, n); return n; }
/** * Determine whether this pattern is the same as another pattern * * @param other the other object */ public boolean equals(/*@NotNull*/ Object other) { if (other instanceof UnionPattern) { Set<Pattern> s0 = new HashSet<>(10); gatherComponentPatterns(s0); Set<Pattern> s1 = new HashSet<>(10); ((UnionPattern) other).gatherComponentPatterns(s1); return s0.equals(s1); } else { return false; } }
/** * Parse a Union Pattern:<br> * pathPattern ( | pathPattern )* * * @throws XPathException if any error is encountered * @return the pattern that results from parsing */ private Pattern parseUnionPattern() throws XPathException { Pattern exp1 = parsePathPattern(); while (t.currentToken == Token.UNION ) { if (t.currentTokenValue.equals("union")) { grumble("Union operator in a pattern must be written as '|'"); } nextToken(); Pattern exp2 = parsePathPattern(); exp1 = new UnionPattern(exp1, exp2); } return exp1; }
/** * Determine whether this pattern is the same as another pattern * * @param other the other object */ public boolean equals(/*@NotNull*/ Object other) { if (other instanceof UnionPattern) { Set<Pattern> s0 = new HashSet<>(10); gatherComponentPatterns(s0); Set<Pattern> s1 = new HashSet<>(10); ((UnionPattern) other).gatherComponentPatterns(s1); return s0.equals(s1); } else { return false; } }
/** * Parse a Union Pattern:<br> * pathPattern ( | pathPattern )* * * @throws XPathException if any error is encountered * @return the pattern that results from parsing */ private Pattern parseUnionPattern() throws XPathException { Pattern exp1 = parsePathPattern(); while (t.currentToken == Token.UNION ) { if (t.currentTokenValue.equals("union")) { grumble("Union operator in a pattern must be written as '|'"); } nextToken(); Pattern exp2 = parsePathPattern(); exp1 = new UnionPattern(exp1, exp2); } return exp1; }
return new UnionPattern( getLhsExpression().toPattern(config), getRhsExpression().toPattern(config));