1 package net.sf.saxon.pattern; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.instruct.Executable; 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 import net.sf.saxon.event.LocationProvider; 9 10 import java.io.Serializable ; 11 import java.util.Iterator ; 12 import java.util.Collections ; 13 14 19 20 public abstract class Pattern implements Serializable , Container { 21 22 private String originalText; 23 private Executable executable; 24 private String systemId; private int lineNumber; 27 33 34 public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException { 35 36 Pattern pat = (new ExpressionParser()).parsePattern(pattern, env); 37 pat.setSystemId(env.getSystemId()); 38 pat.setLineNumber(env.getLineNumber()); 39 pat.setOriginalText(pattern); 42 pat.setExecutable(exec); 43 pat = pat.simplify(env); 44 return pat; 45 } 46 47 48 public Executable getExecutable() { 49 return executable; 50 } 51 52 public void setExecutable(Executable executable) { 53 this.executable = executable; 54 } 55 56 59 60 public LocationProvider getLocationProvider() { 61 return executable.getLocationMap(); 62 } 63 64 65 68 69 public void setOriginalText(String text) { 70 originalText = text; 71 } 72 73 78 79 public Pattern simplify(StaticContext env) throws XPathException { 80 return this; 81 } 82 83 89 90 public Pattern analyze(StaticContext env, ItemType contextItemType) throws XPathException { 91 return this; 92 } 93 94 98 99 public int getDependencies() { 100 return 0; 101 } 102 103 106 107 public Iterator iterateSubExpressions() { 108 return Collections.EMPTY_LIST.iterator(); 109 } 110 111 129 130 public void promote(PromotionOffer offer) throws XPathException { 131 } 133 134 137 138 public void setSystemId(String systemId) { 139 this.systemId = systemId; 140 } 141 142 145 146 public void setLineNumber(int lineNumber) { 147 this.lineNumber = lineNumber; 148 } 149 150 158 159 public abstract boolean matches(NodeInfo node, XPathContext context) throws XPathException; 160 161 170 171 protected boolean internalMatches(NodeInfo node, XPathContext context) throws XPathException { 172 return matches(node, context); 173 } 174 175 180 181 public int getNodeKind() { 182 return Type.NODE; 183 } 184 185 190 191 public int getFingerprint() { 192 return -1; 193 } 194 195 198 199 public abstract NodeTest getNodeTest(); 200 201 205 206 public double getDefaultPriority() { 207 return 0.5; 208 } 209 210 213 214 public String getSystemId() { 215 return systemId; 216 } 217 218 221 222 public int getLineNumber() { 223 return lineNumber; 224 } 225 226 229 230 public int getColumnNumber() { 231 return -1; 232 } 233 234 237 238 public String getPublicId() { 239 return null; 240 } 241 244 245 public String toString() { 246 return originalText; 247 } 248 249 } 250 251 | Popular Tags |