1 package net.sf.saxon.expr; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.Controller; 4 import net.sf.saxon.instruct.*; 5 import net.sf.saxon.om.AxisIterator; 6 import net.sf.saxon.om.Item; 7 import net.sf.saxon.om.SingletonIterator; 8 import net.sf.saxon.om.ValueRepresentation; 9 import net.sf.saxon.sort.GroupIterator; 10 import net.sf.saxon.trace.InstructionInfoProvider; 11 import net.sf.saxon.trans.Mode; 12 import net.sf.saxon.trans.XPathException; 13 14 19 20 public class XPathContextMajor extends XPathContextMinor { 21 22 private StackFrame stackFrame = null; 23 private ParameterSet localParameters = null; 24 private XSLTContext xsltContext = null; 25 26 30 31 public XPathContextMajor(Controller c) { 32 controller = c; 33 stackFrame = StackFrame.EMPTY; 34 origin = controller; 35 } 36 37 40 41 private XPathContextMajor() { 42 } 43 44 47 48 public XPathContextMajor(Item item, Configuration config) { 49 Executable exec = new Executable(); 50 exec.setHostLanguage(Configuration.JAVA_APPLICATION); 51 controller = new Controller(config, exec); 52 AxisIterator iter = SingletonIterator.makeIterator(item); 53 iter.next(); 54 currentIterator = iter; 55 origin = controller; 56 } 57 58 62 63 public XPathContextMajor newContext() { 64 XPathContextMajor c = new XPathContextMajor(); 65 c.controller = controller; 66 c.currentIterator = currentIterator; 67 c.stackFrame = stackFrame; 68 c.localParameters = localParameters; 69 c.last = last; 70 c.currentReceiver = currentReceiver; 71 c.isTemporaryDestination = isTemporaryDestination; 72 c.xsltContext = xsltContext; 73 c.caller = this; 74 return c; 75 } 76 77 public static XPathContextMajor newContext(XPathContextMinor p) { 78 XPathContextMajor c = new XPathContextMajor(); 79 c.controller = p.getController(); 80 c.currentIterator = p.getCurrentIterator(); 81 c.stackFrame = p.getStackFrame(); 82 c.localParameters = p.getLocalParameters(); 83 84 c.last = p.last; 85 c.currentReceiver = p.currentReceiver; 86 c.isTemporaryDestination = p.isTemporaryDestination; 87 c.xsltContext = p.getXSLTContext(); 88 c.caller = p; 89 return c; 90 } 91 92 95 96 public XSLTContext getXSLTContext() { 97 return xsltContext; 98 } 99 100 104 105 public ParameterSet getLocalParameters() { 106 return localParameters; 107 } 108 109 113 114 public void setLocalParameters(ParameterSet localParameters) { 115 this.localParameters = localParameters; 116 } 117 118 122 123 public ParameterSet getTunnelParameters() { 124 if (xsltContext != null) { 125 return xsltContext.tunnelParameters; 126 } else { 127 return null; 128 } 129 } 130 131 135 136 public void setTunnelParameters(ParameterSet tunnelParameters) { 137 xsltContext = new XSLTContext(xsltContext); 138 xsltContext.tunnelParameters = tunnelParameters; 139 } 140 141 147 148 public void setOrigin(InstructionInfoProvider expr) { 149 origin = expr; 150 } 151 152 158 159 public StackFrame getStackFrame() { 160 return stackFrame; 161 } 162 163 164 169 170 public void setStackFrame(SlotManager map, ValueRepresentation[] variables) { 171 stackFrame = new StackFrame(map, variables); 172 if (map != null && variables.length != map.getNumberOfVariables()) { 173 stackFrame.slots = new ValueRepresentation[map.getNumberOfVariables()]; 174 System.arraycopy(variables, 0, stackFrame.slots, 0, variables.length); 175 } 176 } 177 178 183 public void openStackFrame(SlotManager map) { 184 int slots = map.getNumberOfVariables(); 185 if (slots == 0) { 186 stackFrame = StackFrame.EMPTY; 187 } else { 188 stackFrame = new StackFrame(map, new ValueRepresentation[slots]); 189 } 190 } 191 192 198 199 public void openStackFrame(int numberOfVariables) { 200 stackFrame = new StackFrame(null, new ValueRepresentation[numberOfVariables]); 201 } 202 203 206 207 public ValueRepresentation evaluateLocalVariable(int slotnumber) { 208 return stackFrame.slots[slotnumber]; 209 } 210 211 214 215 public void setLocalVariable(int slotnumber, ValueRepresentation value) { 216 stackFrame.slots[slotnumber] = value; 217 } 218 219 220 224 225 public void setCurrentMode(Mode mode) { 226 if ((mode != null && !mode.isDefaultMode()) || (getCurrentMode() != null)) { 227 xsltContext = new XSLTContext(xsltContext); 228 xsltContext.currentMode = mode; 229 } 230 } 231 232 236 237 public Mode getCurrentMode() { 238 if (xsltContext != null) { 239 return xsltContext.currentMode; 240 } else { 241 return null; 242 } 243 } 244 245 252 253 public void setCurrentTemplate(Template template) { 254 xsltContext = new XSLTContext(xsltContext); 255 xsltContext.currentTemplate = template; 256 } 257 258 263 264 public Template getCurrentTemplate() { 265 if (xsltContext != null) { 266 return xsltContext.currentTemplate; 267 } else { 268 return null; 269 } 270 } 271 272 277 278 public void setCurrentGroupIterator(GroupIterator collection) { 279 xsltContext = new XSLTContext(xsltContext); 280 xsltContext.currentGroupIterator = collection; 281 } 282 283 288 289 public GroupIterator getCurrentGroupIterator() { 290 if (xsltContext != null) { 291 return xsltContext.currentGroupIterator; 292 } else { 293 return null; 294 } 295 } 296 297 302 303 public void setCurrentRegexIterator(RegexIterator currentRegexIterator) { 304 xsltContext = new XSLTContext(xsltContext); 305 xsltContext.currentRegexIterator = currentRegexIterator; 306 } 307 308 313 314 public RegexIterator getCurrentRegexIterator() { 315 if (xsltContext != null) { 316 return xsltContext.currentRegexIterator; 317 } else { 318 return null; 319 } 320 } 321 322 331 332 public boolean useLocalParameter(int fingerprint, 333 LocalParam binding, 334 boolean isTunnel) throws XPathException { 335 336 ParameterSet params = (isTunnel ? getTunnelParameters() : localParameters); 337 if (params==null) return false; 338 ValueRepresentation val = params.get(fingerprint); 339 stackFrame.slots[binding.getSlotNumber()] = val; 340 return (val != null); 341 } 342 343 349 350 protected static class XSLTContext { 351 public ParameterSet tunnelParameters = null; 352 public Mode currentMode = null; 353 public Template currentTemplate = null; 354 public GroupIterator currentGroupIterator = null; 355 public RegexIterator currentRegexIterator = null; 356 357 362 363 public XSLTContext(XSLTContext original) { 364 if (original != null) { 365 this.tunnelParameters = original.tunnelParameters; 366 this.currentMode = original.currentMode; 367 this.currentTemplate = original.currentTemplate; 368 this.currentGroupIterator = original.currentGroupIterator; 369 this.currentRegexIterator = original.currentRegexIterator; 370 } 371 } 372 } 373 374 } 375 376 | Popular Tags |