1 package com.icl.saxon.expr; 2 import com.icl.saxon.Context; 3 import com.icl.saxon.om.NodeEnumeration; 4 5 6 9 10 class UnionExpression extends NodeSetExpression { 11 12 15 protected Expression p1, p2; 16 17 22 23 public UnionExpression(Expression p1, Expression p2) { 24 this.p1 = p1; 25 this.p2 = p2; 26 } 27 28 32 33 public Expression simplify() throws XPathException { 34 p1 = p1.simplify(); 35 p2 = p2.simplify(); 36 if (p1 instanceof EmptyNodeSet) return p2; 37 if (p2 instanceof EmptyNodeSet) return p1; 38 return this; 39 } 40 41 48 49 public NodeEnumeration enumerate(Context c, boolean sort) throws XPathException { 50 return new UnionEnumeration(p1.enumerate(c, true), 51 p2.enumerate(c, true), 52 c.getController()); 53 } 54 55 60 61 public int getDependencies() { 62 return p1.getDependencies() | p2.getDependencies(); 63 } 64 65 70 71 public boolean isContextDocumentNodeSet() { 72 return p1.isContextDocumentNodeSet() && p2.isContextDocumentNodeSet(); 73 } 74 75 83 84 public Expression reduce(int dependencies, Context context) throws XPathException { 85 if ((getDependencies() & dependencies) != 0 ) { 86 Expression e = new UnionExpression( 87 p1.reduce(dependencies, context), 88 p2.reduce(dependencies, context)); 89 e.setStaticContext(getStaticContext()); 90 return e; 91 } else { 92 return this; 93 } 94 } 95 96 99 100 public void display(int level) { 101 System.err.println(indent(level) + "union"); 102 p1.display(level+1); 103 p2.display(level+1); 104 } 105 106 } 107 108 | Popular Tags |