1 package net.sf.saxon.pattern; 2 import net.sf.saxon.expr.StaticContext; 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.om.NodeInfo; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.ItemType; 7 import net.sf.saxon.type.Type; 8 9 12 13 public class UnionPattern extends Pattern { 14 15 protected Pattern p1, p2; 16 private int nodeType = Type.NODE; 17 18 23 24 public UnionPattern(Pattern p1, Pattern p2) { 25 this.p1 = p1; 26 this.p2 = p2; 27 if (p1.getNodeKind()==p2.getNodeKind()) { 28 nodeType = p1.getNodeKind(); 29 } 30 } 31 32 35 36 public Pattern simplify(StaticContext env) throws XPathException { 37 p1 = p1.simplify(env); 38 p2 = p2.simplify(env); 39 return this; 40 } 41 42 47 48 public Pattern analyze(StaticContext env, ItemType contextItemType) throws XPathException { 49 p1 = p1.analyze(env, contextItemType); 50 p2 = p2.analyze(env, contextItemType); 51 return this; 52 } 53 54 57 58 public void setOriginalText(String pattern) { 59 super.setOriginalText(pattern); 60 p1.setOriginalText(pattern); 61 p2.setOriginalText(pattern); 62 } 63 64 69 70 public boolean matches(NodeInfo e, XPathContext context) throws XPathException { 71 return p1.matches(e, context) || p2.matches(e, context); 72 } 73 74 79 80 public int getNodeKind() { 81 return nodeType; 82 } 83 84 87 88 public NodeTest getNodeTest() { 89 if (nodeType==Type.NODE) { 90 return AnyNodeTest.getInstance(); 91 } else { 92 return NodeKindTest.makeNodeKindTest(nodeType); 93 } 94 } 95 96 99 100 public Pattern getLHS() { 101 return p1; 102 } 103 104 107 108 public Pattern getRHS() { 109 return p2; 110 } 111 112 115 116 public void setSystemId(String systemId) { 117 super.setSystemId(systemId); 118 p1.setSystemId(systemId); 119 p2.setSystemId(systemId); 120 } 121 122 125 126 public void setLineNumber(int lineNumber) { 127 super.setLineNumber(lineNumber); 128 p1.setLineNumber(lineNumber); 129 p2.setLineNumber(lineNumber); 130 } 131 } 132 133 | Popular Tags |