Package net.sf.saxon.expr

Examples of net.sf.saxon.expr.XPathContext


                out.append(it, 0, NodeInfo.ALL_NAMESPACES);
            }
        } else {
            state = BUSY;
            Controller controller = context.getController();
            XPathContext c2 = savedXPathContext.newMinorContext();
            //c2.setOrigin(this);
            // Fork the output: one copy goes to a SequenceOutputter which remembers the contents for
            // use next time the variable is referenced; another copy goes to the current output destination.
            SequenceOutputter seq = controller.allocateSequenceOutputter(20);
            seq.setPipelineConfiguration(controller.makePipelineConfiguration());
            seq.open();
            TeeOutputter tee = new TeeOutputter(context.getReceiver(), seq);
            tee.setPipelineConfiguration(controller.makePipelineConfiguration());
            c2.setTemporaryReceiver(tee);

            expression.process(c2);

            seq.close();
            List list = seq.getList();
View Full Code Here


     * of {@link ContextStackFrame}
     * @throws java.util.NoSuchElementException
     *          iteration has no more elements.
     */
    public Object next() {
        XPathContext context = next;
        if (context == null) {
            return null;
        }
        int construct = context.getOriginatingConstructType();
        Object origin = context.getOrigin();

        if (first) {
            // these constructs are only considered if they appear at the top of the stack
            if (construct == Location.FILTER_EXPRESSION ||
                    construct == Location.PATH_EXPRESSION ||
                    construct == Location.SORT_KEY ||
                    construct == Location.GROUPING_KEY) {

            } else {

            }
        }

        if (construct == Location.CONTROLLER) {
            next = context.getCaller();
            return new ContextStackFrame.CallingApplication();
        } else if (construct == Location.BUILT_IN_TEMPLATE) {
            next = context.getCaller();
            return new ContextStackFrame.BuiltInTemplateRule();
        }
//        InstructionInfo info;
//        if (origin instanceof Instruction) {
//            info = ((Instruction)origin);
//        } else {
//            next = context.getCaller();
//            return next();
//        }
        //System.err.println("Construct: " + construct);
        if (construct == Location.FUNCTION_CALL) {
            ContextStackFrame.FunctionCall sf = new ContextStackFrame.FunctionCall();
            UserFunctionCall ufc = (UserFunctionCall)origin;
            sf.setSystemId(ufc.getSystemId());
            sf.setLineNumber(ufc.getLineNumber());
            sf.setContainer(ufc.getContainer());
            sf.setFunctionName(ufc.getFunctionName());
            sf.setContextItem(context.getContextItem());
            next = context.getCaller();
            return sf;
        } else if (construct == StandardNames.XSL_APPLY_TEMPLATES) {
            ContextStackFrame.ApplyTemplates sf = new ContextStackFrame.ApplyTemplates();
            ApplyTemplates loc = (ApplyTemplates)origin;
            sf.setSystemId(loc.getSystemId());
            sf.setLineNumber(loc.getLineNumber());
            sf.setContainer(loc.getContainer());
            sf.setContextItem(context.getContextItem());
            next = context.getCaller();
            return sf;
        } else if (construct == StandardNames.XSL_CALL_TEMPLATE) {
            ContextStackFrame.CallTemplate sf = new ContextStackFrame.CallTemplate();
            CallTemplate loc = (CallTemplate)origin;
            sf.setSystemId(loc.getSystemId());
            sf.setLineNumber(loc.getLineNumber());
            sf.setContainer(loc.getContainer());
            sf.setTemplateName(loc.getObjectName());
            sf.setContextItem(context.getContextItem());
            next = context.getCaller();
            return sf;
        } else if (construct == StandardNames.XSL_VARIABLE) {
            ContextStackFrame.VariableEvaluation sf = new ContextStackFrame.VariableEvaluation();
            GeneralVariable var = ((GeneralVariable)origin);
            sf.setSystemId(var.getSystemId());
            sf.setLineNumber(var.getLineNumber());
            sf.setContainer(var.getContainer());
            sf.setContextItem(context.getContextItem());
            sf.setVariableName(var.getVariableQName());
            next = context.getCaller();
            return sf;
        } else if (construct == StandardNames.XSL_FOR_EACH) {
            ContextStackFrame.ForEach sf = new ContextStackFrame.ForEach();
            ForEach var = ((ForEach)origin);
            sf.setSystemId(var.getSystemId());
            sf.setLineNumber(var.getLineNumber());
            sf.setContainer(var.getContainer());
            sf.setContextItem(context.getContextItem());
            next = context.getCaller();
            return sf;
//        } else if (construct == Location.FILTER_EXPRESSION) {
//            out.println("    In predicate of filter expression");
//        } else if (construct == Location.PATH_EXPRESSION) {
//            out.println("    In step of path expression");
//        } else if (construct == Location.SORT_KEY) {
//            out.println("    In evaluation of sort key");
//        } else if (construct == Location.GROUPING_KEY) {
//            out.println("    In evaluation of grouping key");
        } else {
            //other context changes are not considered significant enough to report
            //out.println("    In unidentified location " + construct);
            next = context.getCaller();
            return next();
        }

    }
View Full Code Here

     * @param contextStack
     * @param state   a stack on which the instruction can save state information during the call on processLeft()
     */

    public void processLeft(Stack<XPathContext> contextStack, Stack state) throws XPathException {
        XPathContext context = contextStack.peek();
        SequenceReceiver out = context.getReceiver();
        state.push(out);
        SequenceOutputter out2 = new SequenceOutputter();
        out2.setPipelineConfiguration(out.getPipelineConfiguration());
        context.setReceiver(out2);
    }
View Full Code Here

     * @param contextStack
     * @param state   a stack on which the instruction can save state information during the call on processLeft()
     */

    public void processRight(Stack<XPathContext> contextStack, Stack state) throws XPathException {
        XPathContext context = contextStack.peek();
        CharSequence value = ((SequenceOutputter)context.getReceiver()).getFirstItem().getStringValueCS();
        SequenceReceiver out = (SequenceReceiver)state.pop();
        context.setReceiver(out);
        out.append(new StringValue(value), 0, 0);
    }
View Full Code Here

      * or more groups, one for each value of the grouping key.
     */

    private void buildIndexedGroups() throws XPathException {
        HashMap index = new HashMap(40);
        XPathContext c2 = keyContext.newMinorContext();
        c2.setCurrentIterator(population);
        c2.setOriginatingConstructType(Location.GROUPING_KEY);
        while (true) {
            Item item = population.next();
            if (item==null) {
                break;
            }
View Full Code Here

    public void close() {
    }

    public SequenceIterator getAnother() throws XPathException {
        XPathContext c2 = keyContext.newMinorContext();
        c2.setOriginatingConstructType(Location.GROUPING_KEY);
        return new GroupByIterator(population.getAnother(), keyExpression, c2, collator);
    }
View Full Code Here

            // probably redundant. It's the caller's job to set this flag, because there might be
            // a non-standard error listener in use.
        }

        if (exception instanceof XPathException) {
            XPathContext context = ((XPathException)exception).getXPathContext();
            if (context != null && doStackTrace && getRecoveryPolicy() != Configuration.RECOVER_SILENTLY) {
                printStackTrace(errorOutput, context);
            }
        }
    }
View Full Code Here

     * pre-evaluation, or that need access to context information, can override this method.
     * @param visitor an expression visitor
     */

    public Expression preEvaluate(ExpressionVisitor visitor) throws XPathException {
        final XPathContext context = visitor.getStaticContext().makeEarlyEvaluationContext();
        return new StringLiteral(
            unicodeToString(argument[0].iterate(context), context));
    }
View Full Code Here

        }
    }

    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        XPathContext c2 = context.newMinorContext();
        c2.setOrigin(this);
        SequenceReceiver out = c2.getReceiver();
        Item item = context.getContextItem();
        if (!(item instanceof NodeInfo)) {
            out.append(item, locationId);
            return null;
        }
        NodeInfo source = (NodeInfo)item;

        // Processing depends on the node kind.

        switch(source.getNodeKind()) {

        case Type.ELEMENT:
            // use the generic code for creating new elements
            return super.processLeavingTail(c2);

        case Type.ATTRIBUTE:
            try {
                CopyOf.copyAttribute(source, schemaType, validation, locationId, c2);
            } catch (NoOpenStartTagException err) {
                DynamicError e = new DynamicError(err.getMessage());
                e.setXPathContext(context);
                e.setErrorCode(err.getErrorCode());
                context.getController().recoverableError(e);
            }
            break;

        case Type.TEXT:
            out.characters(source.getStringValue(), locationId, 0);
            break;

        case Type.PROCESSING_INSTRUCTION:
            out.processingInstruction(source.getDisplayName(), source.getStringValue(), locationId, 0);
            break;

        case Type.COMMENT:
            out.comment(source.getStringValue(), locationId, 0);
            break;

        case Type.NAMESPACE:
            try {
                source.copy(out, NodeInfo.NO_NAMESPACES, false, locationId);
            } catch (NoOpenStartTagException err) {
                DynamicError e = new DynamicError(err.getMessage());
                e.setXPathContext(context);
                e.setErrorCode(err.getErrorCode());
                context.getController().recoverableError(e);
            }
            break;

        case Type.DOCUMENT:
            Receiver val = controller.getConfiguration().
                    getDocumentValidator(out,
                                         source.getBaseURI(),
                                         controller.getNamePool(),
                                         validation);
            if (val != out) {
                SequenceReceiver sr = new TreeReceiver(val);
                sr.setConfiguration(controller.getConfiguration());
                c2.setReceiver(sr);
                val = sr;
            }
            val.setConfiguration(controller.getConfiguration());
            val.startDocument(0);
            processChildren(c2);
View Full Code Here

                }
            }
            root = new TextFragmentValue(textValue, baseURI);
            root.setConfiguration(controller.getConfiguration());
        } else {
            XPathContext c2 = context.newMinorContext();
            c2.setOrigin(this);

            // TODO: delayed evaluation of temporary trees, in the same way as
            // node-sets. This requires saving the controller, including values of local variables
            // and any assignable global variables (ouch).

            // TODO: use an Outputter that delayes the decision whether to build a
            // TextFragment or a TinyTree until the first element is encountered, to
            // avoid the overhead of using a TinyTree for text-only trees. This would
            // make the static analysis superfluous.

            TinyBuilder builder = new TinyBuilder();
            //System.err.println("Build doc " + builder);
            builder.setSizeParameters(treeSizeParameters);
            builder.setLineNumbering(controller.getConfiguration().isLineNumbering());

            Receiver receiver = builder;
            receiver.setSystemId(baseURI);
            receiver.setConfiguration(controller.getConfiguration());
            receiver.open();
            receiver.startDocument(0);
            c2.changeOutputDestination(null,
                    receiver,
                    false,
                    validationAction,
                    schemaType);
            processChildren(c2);
View Full Code Here

TOP

Related Classes of net.sf.saxon.expr.XPathContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.