Package net.sf.saxon

Examples of net.sf.saxon.Controller


    protected void promoteInst(PromotionOffer offer) throws XPathException {
    }


    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        XPathContext c2 = context.newMinorContext();
        c2.setOrigin(this);
        SequenceReceiver out = c2.getReceiver();
        TinyBuilder builder = new TinyBuilder();
        Receiver receiver = builder;
        receiver.setConfiguration(controller.getConfiguration());
        receiver.open();

        c2.changeOutputDestination(null, receiver, false, Validation.PRESERVE, null);
        processChildren(c2);
        receiver.close();
View Full Code Here


    public Value call(Value[] actualArgs, XPathContextMajor context, boolean evaluateTailCalls)
            throws XPathException {

        // If this is a memo function, see if the result is already known
        Controller controller = context.getController();
        if (memoFunction) {
            Value value = getCachedValue(controller, actualArgs);
            if (value != null) return value;
        }
View Full Code Here

    * Enumerate the results of the expression
    */

    public SequenceIterator iterate(XPathContext context) throws XPathException {

        Controller controller = context.getController();

        Item arg2 = argument[2].evaluateItem(context);
        if (!(arg2 instanceof NodeInfo)) {
            dynamicError("When calling the key() function, the context item must be a node", "XT1270", context);
            return null;
        }
        NodeInfo root= ((NodeInfo)arg2).getRoot();
        if (!(root instanceof DocumentInfo)) {
            dynamicError("In the key() function," +
                            " the node supplied in the third argument (or the context node if absent)" +
                            " must be in a tree whose root is a document node", "XT1270", context);
            return null;
        }
        DocumentInfo doc = (DocumentInfo)root;

        int fprint = keyFingerprint;
        if (fprint == -1) {
            String givenkeyname = argument[0].evaluateItem(context).getStringValue();
            try {
                fprint = nsContext.getFingerprint(givenkeyname, false, context.getController().getNamePool());
            } catch (XPathException err) {
                dynamicError("Invalid key name: " + err.getMessage(), "XT1260", context);
            }
            if (fprint==-1) {
                dynamicError("Key '" + givenkeyname + "' has not been defined", "XT1260", context);
                return null;
            }
        }

        // If the second argument is a singleton, we evaluate the function
        // directly; otherwise we recurse to evaluate it once for each Item
        // in the sequence.

        Expression expression = argument[1];
        if (Cardinality.allowsMany(expression.getCardinality())) {
            KeyContextInfo info = new KeyContextInfo();
            info.document = doc;
            info.context = context;
            info.keyFingerprint = fprint;

            SequenceIterator keys = argument[1].iterate(context);
            SequenceIterator allValues = new MappingIterator(keys, this, null, info);
            return new DocumentOrderIterator(allValues, LocalOrderComparer.getInstance());
        } else {
            AtomicValue keyValue = (AtomicValue)argument[1].evaluateItem(context);
            if (keyValue == null) {
                return EmptyIterator.getInstance();
            }
            KeyManager keyManager = controller.getKeyManager();
            return keyManager.selectByKey(fprint, doc, keyValue, context);

        }
    }
View Full Code Here

                                Mode mode,
                                ParameterSet parameters,
                                ParameterSet tunnelParameters,
                                XPathContextMajor context)
                                throws XPathException {
        Controller controller = context.getController();
        TailCall tc = null;

        XPathContextMajor c2 = context;

        // Iterate over this sequence

        if (controller.isTracing()) {

            c2.setCurrentIterator(iterator);
            c2.setCurrentMode(mode);
            while(true) {
                // process any tail calls returned from previous nodes
                while (tc != null) {
                    tc = tc.processLeavingTail(c2);
                }

                NodeInfo node = (NodeInfo)iterator.next();
                        // We can assume it's a node - we did static type checking
                if (node == null) break;

                // find the node handler [i.e., the template rule] for this node
                Template eh = controller.getRuleManager().getTemplateRule(node, mode, c2);

                if (eh==null) {             // Use the default action for the node
                                            // No need to open a new stack frame!
                    defaultAction(node, parameters, tunnelParameters, c2);

                } else {
                    if (tunnelParameters != null || eh.needsStackFrame()) {
                        TraceListener traceListener = controller.getTraceListener();
                        c2.setLocalParameters(parameters);
                        c2.setTunnelParameters(tunnelParameters);
                        c2.openStackFrame(eh.getStackFrameMap());
                        traceListener.startCurrentItem(node);
                        tc = eh.processLeavingTail(c2);
                        traceListener.endCurrentItem(node);
                    } else {
                        TraceListener traceListener = controller.getTraceListener();
                        traceListener.startCurrentItem(node);
                        tc = eh.processLeavingTail(c2);
                        traceListener.endCurrentItem(node);
                    }
                }
            }

        } else {    // not tracing

            c2.setCurrentIterator(iterator);
            c2.setCurrentMode(mode);
            while(true) {

                // process any tail calls returned from previous nodes
                while (tc != null) {
                    tc = tc.processLeavingTail(c2);
                }

                NodeInfo node = (NodeInfo)iterator.next();
                        // We can assume it's a node - we did static type checking
                if (node == null) break;

                // find the template rule for this node

                Template eh = controller.getRuleManager().getTemplateRule(node, mode, c2);

                if (eh==null) {             // Use the default action for the node
                                            // No need to open a new stack frame!
                    defaultAction(node, parameters, tunnelParameters, c2);
View Full Code Here

        }
        return list.iterator();
    }

    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        XPathContext c2 = context.newMinorContext();
        c2.setOrigin(this);

        Result result;
        OutputURIResolver resolver = null;

        if (href == null) {
            result = controller.getPrincipalResult();
        } else {
            try {
                resolver = controller.getOutputURIResolver();

                String hrefValue = href.evaluateAsString(context);
                result = resolver.resolve(hrefValue, controller.getPrincipalResultURI());
                if (result == null) {
                    resolver = StandardOutputResolver.getInstance();
                    result = resolver.resolve(hrefValue, controller.getPrincipalResultURI());
                }
            } catch (TransformerException e) {
                throw XPathException.wrap(e);
            }
        }

        boolean timing = controller.getConfiguration().isTiming();
        if (timing) {
            String dest = result.getSystemId();
            if (dest == null) {
                if (result instanceof StreamResult) {
                    dest = "anonymous output stream";
                } else if (result instanceof SAXResult) {
                    dest = "SAX2 ContentHandler";
                } else if (result instanceof DOMResult) {
                    dest = "DOM tree";
                } else {
                    dest = result.getClass().getName();
                }
            }
            System.err.println("Writing to " + dest);
        }

        Properties props = outputProperties;
        if (serializationAttributes.size() > 0) {
            props = new Properties(outputProperties);
            final NamePool namePool = context.getController().getNamePool();
            for (Iterator it = serializationAttributes.keySet().iterator(); it.hasNext();) {
                Integer key = (Integer) it.next();
                Expression exp = (Expression) serializationAttributes.get(key);
                String value = exp.evaluateAsString(context);
                try {
                    setSerializationProperty(props, key.intValue(), value, namePool, nsResolver);
                } catch (DynamicError e) {
                    e.setXPathContext(context);
                    e.setLocator(getSourceLocator());
                    throw e;
                }
            }
        }
        String nextInChain = outputProperties.getProperty(SaxonOutputKeys.NEXT_IN_CHAIN);
        if (nextInChain != null) {
            try {
                result = controller.prepareNextStylesheet(nextInChain, baseURI, result);
            } catch (TransformerException e) {
                throw XPathException.wrap(e);
            }
        }
View Full Code Here

     * @param context the dynamic execution context
     * @return either null, or a tail call that the caller must invoke on return
     * @throws net.sf.saxon.xpath.XPathException
     */
    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        TraceListener listener = controller.getTraceListener();
      if (controller.isTracing()) {
             listener.enter(getInstructionInfo(), context);
        }
        // Don't attempt tail call optimization when tracing, the results are too confusing
        child.process(context);
         if (controller.isTracing()) {
             listener.leave(getInstructionInfo());
        }
        return null;
    }
View Full Code Here

     *     expression; or null to indicate that the result is an empty
     *     sequence
     */

    public Item evaluateItem(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        if (controller.isTracing()) {
            controller.getTraceListener().enter(getInstructionInfo(), context);
        }
        Item result = child.evaluateItem(context);
        if (controller.isTracing()) {
            controller.getTraceListener().leave(getInstructionInfo());
        }
        return result;
    }
View Full Code Here

     * @return a SequenceIterator that can be used to iterate over the result
     *     of the expression
     */

    public SequenceIterator iterate(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        if (controller.isTracing()) {
            controller.getTraceListener().enter(getInstructionInfo(), context);
        }
        SequenceIterator result = child.iterate(context);
        if (controller.isTracing()) {
            controller.getTraceListener().leave(getInstructionInfo());
        }
        return result;
    }
View Full Code Here

    * Must be used with care, since functions dependent on a Controller
    * will not be available.
    */

    public XPathContextMajor(Item item, Configuration config) {
        controller = new Controller(config);
        controller.setExecutable(new Executable());
        AxisIterator iter = SingletonIterator.makeIterator(item);
        iter.next();
        currentIterator = iter;
        origin = controller;
View Full Code Here

            case Expression.EVALUATE_METHOD: {
                Item item = exp.evaluateItem(context);
                return Value.asValue(item);
            }
            case Expression.PROCESS_METHOD: {
                Controller controller = context.getController();
                XPathContext c2 = context.newMinorContext();
                c2.setOrigin((InstructionInfoProvider)exp);
                SequenceOutputter seq = new SequenceOutputter();
                seq.setConfiguration(controller.getConfiguration());
                seq.setDocumentLocator(((Instruction)exp).getExecutable().getLocationMap());
                c2.setTemporaryReceiver(seq);
                seq.open();
                exp.process(c2);
                seq.close();
View Full Code Here

TOP

Related Classes of net.sf.saxon.Controller

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.