/** * Get a raw iterator over the results of the expression. This returns results without * any conversion of the returned items to "native" Java classes. This method is intended * for use by applications that need to process the results of the expression using * internal Saxon interfaces. * @param contextItem the context item for evaluating the expression * @return an iterator over the results of the expression, with no conversion of returned items * @since 9.0 */ public SequenceIterator rawIterator(Item contextItem) throws XPathException { XPathContextMajor context = new XPathContextMajor(contextItem, executable); context.openStackFrame(stackFrameMap); return rawIterator(context); }
/** * Create a dynamic context suitable for evaluating this expression, without supplying a context * item * * @return an XPathDynamicContext object representing a suitable dynamic context. This will * be initialized with a stack frame suitable for holding the variables used by the * expression. */ public XPathDynamicContext createDynamicContext() { XPathContextMajor context = new XPathContextMajor(null, executable); context.openStackFrame(stackFrameMap); return new XPathDynamicContext(env.getRequiredContextItemType(), context, stackFrameMap); }
/** * Create a dynamic context suitable for evaluating this expression * @param contextItem the initial context item, which may be null if no * context item is required, or if it is to be supplied later * @return an XPathDynamicContext object representing a suitable dynamic context. This will * be initialized with a stack frame suitable for holding the variables used by the * expression. */ public XPathDynamicContext createDynamicContext(Item contextItem) { XPathContextMajor context = new XPathContextMajor(contextItem, evaluator.getExecutable()); context.openStackFrame(stackFrameMap); return new XPathDynamicContext(context, stackFrameMap); }
/** * Create a dynamic context suitable for evaluating this expression, without supplying a context * item * * @return an XPathDynamicContext object representing a suitable dynamic context. This will * be initialized with a stack frame suitable for holding the variables used by the * expression. */ public XPathDynamicContext createDynamicContext() { XPathContextMajor context = new XPathContextMajor(null, executable); context.openStackFrame(stackFrameMap); return new XPathDynamicContext(env.getRequiredContextItemType(), context, stackFrameMap); }
/** * Create a dynamic context suitable for evaluating this expression * @param contextItem the initial context item, which may be null if no * context item is required, or if it is to be supplied later * @return an XPathDynamicContext object representing a suitable dynamic context. This will * be initialized with a stack frame suitable for holding the variables used by the * expression. */ public XPathDynamicContext createDynamicContext(Item contextItem) { XPathContextMajor context = new XPathContextMajor(contextItem, evaluator.getExecutable()); context.openStackFrame(stackFrameMap); return new XPathDynamicContext(context); }
/** * Create a dynamic context suitable for evaluating this expression * * @param contextItem the initial context item, which may be null if no * context item is required, or if it is to be supplied later * @return an XPathDynamicContext object representing a suitable dynamic context. This will * be initialized with a stack frame suitable for holding the variables used by the * expression. * @throws XPathException if the context item does not match the required context item type * set up in the static context */ public XPathDynamicContext createDynamicContext(Item contextItem) throws XPathException { checkContextItemType(contextItem); XPathContextMajor context = new XPathContextMajor(contextItem, executable); context.openStackFrame(stackFrameMap); return new XPathDynamicContext(env.getRequiredContextItemType(), context, stackFrameMap); }
/** * Create a dynamic context suitable for evaluating this expression * * @param contextItem the initial context item, which may be null if no * context item is required, or if it is to be supplied later * @return an XPathDynamicContext object representing a suitable dynamic context. This will * be initialized with a stack frame suitable for holding the variables used by the * expression. * @throws XPathException if the context item does not match the required context item type * set up in the static context */ public XPathDynamicContext createDynamicContext(Item contextItem) throws XPathException { checkContextItemType(contextItem); XPathContextMajor context = new XPathContextMajor(contextItem, executable); context.openStackFrame(stackFrameMap); return new XPathDynamicContext(env.getRequiredContextItemType(), context, stackFrameMap); }
/** * Execute a prepared XPath expression, returning the results as a List. The context * node must have been set previously using {@link #setContextNode(net.sf.saxon.om.NodeInfo)}. * @return The results of the expression, as a List. The List represents the sequence * of items returned by the expression. Each item in the list will either be an instance * of net.sf.saxon.om.NodeInfo, representing a node, or a Java object representing an atomic value. * For the types of Java object that may be returned, see {@link #evaluate(Object, javax.xml.namespace.QName)} * with the second argument set to NODESET. * @deprecated since 9.0. This method is not present in the JAXP interface. Either use * the JAXP methods such as {@link #evaluate(Object, QName)}, or use the Saxon XPath * API instead of JAXP. */ public List evaluate() throws XPathException { XPathContextMajor context = new XPathContextMajor(contextNode, executable); context.openStackFrame(stackFrameMap); SequenceIterator iter = expression.iterate(context); SequenceExtent extent = new SequenceExtent(iter); return (List)extent.convertToJava(Object.class, context); }
/** * Make a new XPath context for evaluating patterns if there is any possibility that the * pattern uses local variables * * @param context The existing XPath context * @return a new XPath context (or the existing context if no new context was created) */ private XPathContext perhapsMakeNewContext(XPathContext context) { int patternLocals = context.getController().getExecutable().getLargestPatternStackFrame(); if (patternLocals > 0) { context = context.newContext(); context.setOriginatingConstructType(Location.CONTROLLER); ((XPathContextMajor)context).openStackFrame(patternLocals); } return context; }
private String processShadowAttribute(String expression, String baseUri, AttributeLocation loc) throws XPathException { UseWhenStaticContext staticContext = new UseWhenStaticContext(compilation, startTag); staticContext.setBaseURI(baseUri); staticContext.setContainingLocation(loc); setNamespaceBindings(staticContext); Expression expr = AttributeValueTemplate.make(expression, staticContext); expr = typeCheck(expr, staticContext); SlotManager stackFrameMap = allocateSlots(expression, expr); XPathContext dynamicContext = makeDynamicContext(staticContext); ((XPathContextMajor) dynamicContext).openStackFrame(stackFrameMap); return expr.evaluateAsString(dynamicContext).toString(); }
private String processShadowAttribute(String expression, String baseUri, AttributeLocation loc) throws XPathException { UseWhenStaticContext staticContext = new UseWhenStaticContext(compilation, startTag); staticContext.setBaseURI(baseUri); staticContext.setContainingLocation(loc); setNamespaceBindings(staticContext); Expression expr = AttributeValueTemplate.make(expression, staticContext); expr = typeCheck(expr, staticContext); SlotManager stackFrameMap = allocateSlots(expression, expr); XPathContext dynamicContext = makeDynamicContext(staticContext); ((XPathContextMajor) dynamicContext).openStackFrame(stackFrameMap); return expr.evaluateAsString(dynamicContext).toString(); }
/** * Make a new XPath context for evaluating patterns if there is any possibility that the * pattern uses local variables * * @param context The existing XPath context * @return a new XPath context (or the existing context if no new context was created) */ private XPathContext perhapsMakeNewContext(XPathContext context) { int patternLocals = context.getController().getExecutable().getLargestPatternStackFrame(); if (patternLocals > 0) { context = context.newContext(); context.setOrigin(context.getController()); ((XPathContextMajor)context).openStackFrame(patternLocals); } return context; }
/** * Make a new XPath context for evaluating patterns if there is any possibility that the * pattern uses local variables * * @param context The existing XPath context * @return a new XPath context (or the existing context if no new context was created) */ private XPathContext perhapsMakeNewContext(XPathContext context) { int patternLocals = context.getController().getExecutable().getLargestPatternStackFrame(); if (patternLocals > 0) { context = context.newContext(); context.setOrigin(context.getController()); ((XPathContextMajor)context).openStackFrame(patternLocals); } return context; }
/** * Process the template call encapsulated by this package. * @return another TailCall. This will never be the original call, but it may be the next * recursive call. For example, if A calls B which calls C which calls D, then B may return * a TailCall to A representing the call from B to C; when this is processed, the result may be * a TailCall representing the call from C to D. * @throws XPathException if a dynamic error occurs */ public TailCall processLeavingTail() throws XPathException { Template nh = (Template)rule.getAction(); XPathContextMajor c2 = evaluationContext.newContext(); c2.setOrigin(NextMatch.this); c2.setLocalParameters(params); c2.setTunnelParameters(tunnelParams); c2.openStackFrame(nh.getStackFrameMap()); // System.err.println("Tail call on template"); return nh.applyLeavingTail(c2, rule); } }
/** * Make a new XPath context for evaluating patterns if there is any possibility that the * pattern uses local variables * * @param context The existing XPath context * @return a new XPath context */ public XPathContext makeNewContext(XPathContext context) { XPathContextMajor c2 = context.newContext(); c2.setOrigin(context.getController()); // WHY? c2.openStackFrame(getStackFrameSlotsNeeded()); if (!(context.getCurrentComponent().getActor() instanceof Accumulator)) { c2.setCurrentComponent(context.getCurrentMode()); // bug 3706 } return c2; }
/** * Make a new XPath context for evaluating patterns if there is any possibility that the * pattern uses local variables * * @param context The existing XPath context * @return a new XPath context */ public XPathContext makeNewContext(XPathContext context) { XPathContextMajor c2 = context.newContext(); c2.setOrigin(context.getController()); // WHY? c2.openStackFrame(getStackFrameSlotsNeeded()); if (!(context.getCurrentComponent().getActor() instanceof Accumulator)) { c2.setCurrentComponent(context.getCurrentMode()); // bug 3706 } return c2; }
/** * Run the query returning the results as an EventIterator * @param controller The Controller used to run the query * @param dynamicEnv the XQuery dynamic context for evaluating the query * @return an EventIterator representing the results of the query as a sequence of events */ public EventIterator iterateEvents(Controller controller, DynamicQueryContext dynamicEnv) throws XPathException { initializeController(dynamicEnv, controller); XPathContextMajor context = initialContext(dynamicEnv, controller); // In tracing/debugging mode, evaluate all the global variables first if (controller.getConfiguration().getTraceListener() != null) { controller.preEvaluateGlobals(context); } context.openStackFrame(stackFrameMap); final Configuration config = executable.getConfiguration(); EventIterator ei = expression.iterateEvents(context); //ei = new TracingEventIterator(EventStackIterator.flatten(ei)); return new ComplexContentProcessor(config, ei); }
/** * Evaluate an attribute set * @param context the dynamic context * @throws XPathException if any failure occurs */ public void expand(XPathContext context) throws XPathException { // apply the content of any attribute sets mentioned in use-attribute-sets if (useAttributeSets != null) { AttributeSet.expand(useAttributeSets, context); } if (getStackFrameMap() != null) { XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.openStackFrame(getStackFrameMap()); getBody().process(c2); } else { getBody().process(context); } }
/** * Evaluate a static expression (to initialize a static variable) * * @param expression the expression to be evaluated * @param locationId identifies the location of the expression in case error need to be reported * @param staticContext the static context for evaluation of the expression * @return the effective boolean value of the result of evaluating the expression * @throws XPathException if evaluation of the expression fails */ public Sequence<?> evaluateStatic(String expression, Location locationId, UseWhenStaticContext staticContext) throws XPathException { setNamespaceBindings(staticContext); Expression expr = ExpressionTool.make(expression, staticContext, 0, Token.EOF, null); expr = typeCheck(expr, staticContext); SlotManager stackFrameMap = getPipelineConfiguration().getConfiguration().makeSlotManager(); ExpressionTool.allocateSlots(expr, stackFrameMap.getNumberOfVariables(), stackFrameMap); XPathContext dynamicContext = makeDynamicContext(staticContext); ((XPathContextMajor) dynamicContext).openStackFrame(stackFrameMap); return expr.iterate(dynamicContext).materialize(); }
/** * Iterate over the results of the function */ public SequenceIterator iterate(XPathContext c) throws XPathException { PreparedExpression pexpr = prepareExpression(c); if (operation == EXPRESSION) { return SingletonIterator.makeIterator(new ObjectValue(pexpr)); } else { XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(details); c2.openStackFrame(pexpr.stackFrameMap); c2.setCurrentIterator(c.getCurrentIterator()); for (int i=1; i<argument.length; i++) { int slot = pexpr.variables[i-1].getLocalSlotNumber(); c2.setLocalVariable(slot, ExpressionTool.eagerEvaluate(argument[i],c)); } return Value.getIterator( ExpressionTool.lazyEvaluate(pexpr.expression, c2, 1)); } }