Examples of XProcData


Examples of com.xmlcalabash.core.XProcData

        logger.trace("Running " + infoName + " " + step.getName());
        if (runtime.getAllowGeneralExpressions()) {
            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Running with the 'general-values' extension enabled."));
        }

        XProcData data = runtime.getXProcData();
        data.openFrame(this);

        runtime.start(this);
        try {
            doRun();
        } catch (XProcException ex) {
            runtime.error(ex);
            throw ex;
        } catch (SaxonApiException ex) {
            runtime.error(ex);
            throw ex;
        } finally {
            runtime.finish(this);
            data.closeFrame();
        }
    }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

                binding.setPort(portName);

                input.addBinding(binding);
            }
        } else if (input.getParameterInput()) {
            XProcData data = runtime.getXProcData();
            // If depth==0 then we're on a declare step and you aren't allowed to
            // provide default bindings for parameter input ports.
            if (data.getDepth() == 0 && input.getBinding().size() > 0) {
                throw XProcException.staticError(35, input.getNode(), "You must not specify bindings in this context.");
            }
        }

        for (Binding binding : input.getBinding()) {
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

    }
   
    public void run() throws SaxonApiException {
        logger.trace("Running p:for-each " + step.getName());

        XProcData data = runtime.getXProcData();
        data.openFrame(this);

        if (current == null) {
            current = new Pipe(runtime);
        }

        String iport = "#iteration-source";

        sequencePosition = 0;
        sequenceLength = 0;

        inScopeOptions = parent.getInScopeOptions();

        // FIXME: Do I really have to do this? At the very least, only do it if we have to!
        Vector<XdmNode> nodes = new Vector<XdmNode> ();
        for (ReadablePipe is_reader : inputs.get(iport)) {
            while (is_reader.moreDocuments()) {
                XdmNode is_doc = is_reader.read();
                logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Input copy from " + is_reader));
                logger.trace(MessageFormatter.nodeMessage(step.getNode(), is_doc.toString()));
                nodes.add(is_doc);
                sequenceLength++;
            }
        }

        runtime.getXProcData().setIterationSize(sequenceLength);

        runtime.start(this);

        try {
            for (XdmNode is_doc : nodes) {
                // Setup the current port before we compute variables!
                current.resetWriter();
                current.write(is_doc);
                logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Copy to current"));

                sequencePosition++;
                runtime.getXProcData().setIterationPosition(sequencePosition);

                for (Variable var : step.getVariables()) {
                    RuntimeValue value = computeValue(var);
                    inScopeOptions.put(var.getName(), value);
                }

                // N.B. At this time, there are no compound steps that accept parameters or options,
                // so the order in which we calculate them doesn't matter. That will change if/when
                // there are such compound steps.

                // Calculate all the variables
                inScopeOptions = parent.getInScopeOptions();
                for (Variable var : step.getVariables()) {
                    RuntimeValue value = computeValue(var);
                    inScopeOptions.put(var.getName(), value);
                }

                for (XStep step : subpipeline) {
                    step.run();
                }

                for (String port : inputs.keySet()) {
                    if (port.startsWith("|")) {
                        String wport = port.substring(1);

                        boolean seqOk = step.getOutput(wport).getSequence();
                        int docsCopied = 0;

                        WritablePipe pipe = outputs.get(wport);
                        // The output of a for-each is a sequence, irrespective of what the output says
                        pipe.canWriteSequence(true);

                        for (ReadablePipe reader : inputs.get(port)) {
                            reader.canReadSequence(true); // Hack again!
                            while (reader.moreDocuments()) {
                                XdmNode doc = reader.read();
                                pipe.write(doc);
                                docsCopied++;
                                logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Output copy from " + reader + " to " + pipe));
                            }
                            reader.resetReader();
                        }

                        if (docsCopied != 1 && !seqOk) {
                            throw XProcException.dynamicError(6);
                        }
                    }
                }

                for (XStep step : subpipeline) {
                    step.reset();
                }
            }

        } finally {
            for (String port : inputs.keySet()) {
                if (port.startsWith("|")) {
                    String wport = port.substring(1);
                    WritablePipe pipe = outputs.get(wport);
                    pipe.close(); // Indicate that we're done
                }
            }
            runtime.finish(this);
            data.closeFrame();
        }
    }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

    }

    public void run() throws SaxonApiException {
        logger.trace("Running cx:until-unchanged " + step.getName());

        XProcData data = runtime.getXProcData();
        data.openFrame(this);

        if (current == null) {
            current = new Pipe(runtime);
        }

        String iport = "#iteration-source";

        sequencePosition = 0;
        sequenceLength = 1;

        inScopeOptions = parent.getInScopeOptions();

        runtime.getXProcData().setIterationSize(sequenceLength);

        String iPortName = null;
        String oPortName = null;
        for (String port : inputs.keySet()) {
            if (port.startsWith("|")) {
                iPortName = port;
                oPortName = port.substring(1);
            }
        }

        runtime.start(this);

        try {
            for (ReadablePipe is_reader : inputs.get(iport)) {
                XdmNode os_doc = null;

                while (is_reader.moreDocuments()) {
                    XdmNode is_doc = is_reader.read();
                    boolean changed = true;

                    while (changed) {
                        // Setup the current port before we compute variables!
                        current.resetWriter();
                        current.write(is_doc);
                        logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Copy to current"));

                        sequencePosition++;
                        runtime.getXProcData().setIterationPosition(sequencePosition);

                        for (Variable var : step.getVariables()) {
                            RuntimeValue value = computeValue(var);
                            inScopeOptions.put(var.getName(), value);
                        }

                        // N.B. At this time, there are no compound steps that accept parameters or options,
                        // so the order in which we calculate them doesn't matter. That will change if/when
                        // there are such compound steps.

                        // Calculate all the variables
                        inScopeOptions = parent.getInScopeOptions();
                        for (Variable var : step.getVariables()) {
                            RuntimeValue value = computeValue(var);
                            inScopeOptions.put(var.getName(), value);
                        }

                        for (XStep step : subpipeline) {
                            step.run();
                        }

                        int docsCopied = 0;

                        for (ReadablePipe reader : inputs.get(iPortName)) {
                            while (reader.moreDocuments()) {
                                os_doc = reader.read();
                                docsCopied++;
                            }
                            reader.resetReader();
                        }

                        if (docsCopied != 1) {
                            throw XProcException.dynamicError(6);
                        }

                        for (XStep step : subpipeline) {
                            step.reset();
                        }

                        XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler();
                        xcomp.declareVariable(doca);
                        xcomp.declareVariable(docb);

                        XPathExecutable xexec = xcomp.compile("deep-equal($doca,$docb)");
                        XPathSelector selector = xexec.load();

                        selector.setVariable(doca, is_doc);
                        selector.setVariable(docb, os_doc);

                        Iterator<XdmItem> values = selector.iterator();
                        XdmAtomicValue item = (XdmAtomicValue) values.next();
                        changed = !item.getBooleanValue();

                        is_doc = os_doc;
                    }

                    WritablePipe pipe = outputs.get(oPortName);
                    pipe.write(os_doc);
                }
            }

        } finally {
            for (String port : inputs.keySet()) {
                if (port.startsWith("|")) {
                    String wport = port.substring(1);
                    WritablePipe pipe = outputs.get(wport);
                    pipe.close(); // Indicate that we're done
                }
            }
            runtime.finish(this);
            data.closeFrame();
        }
    }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

                xstep.setParameter(name, inScopeOptions.get(name));
            }
        }
       
        // Make sure we do this *after* calculating any option/parameter values...
        XProcData data = runtime.getXProcData();
        data.openFrame(this);

        runtime.start(this);
        try {
            xstep.run();

            // FIXME: Is it sufficient to only do this for atomic steps?
            String cache = getInheritedExtensionAttribute(XProcConstants.cx_cache);
            if ("true".equals(cache)) {
                for (String port : outputs.keySet()) {
                    WritablePipe wpipe = outputs.get(port);
                    // FIXME: Hack. There should be a better way...
                    if (wpipe instanceof Pipe) {
                        ReadablePipe rpipe = new Pipe(runtime, ((Pipe) wpipe).documents());
                        rpipe.canReadSequence(true);
                        rpipe.setReader(step);
                        while (rpipe.moreDocuments()) {
                            XdmNode doc = rpipe.read();
                            runtime.cache(doc, step.getNode().getBaseURI());
                        }
                    }
                }
            } else if (!"false".equals(cache) && cache != null) {
                throw XProcException.dynamicError(19);
            }

           
        } finally {
            for (String port : outputs.keySet()) {
                WritablePipe wpipe = outputs.get(port);
                wpipe.close(); // Indicate we're done
            }
           
            runtime.finish(this);
            data.closeFrame();
        }
    }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

            xdef = def;
        }

        public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
            XProcRuntime runtime = registry.getRuntime(xdef);
            XProcData data = runtime.getXProcData();
            XStep step = data.getStep();
            // FIXME: this can't be the best way to do this...
            // step == null in use-when
            if (step != null && !(step instanceof XCompoundStep)) {
                throw XProcException.dynamicError(23);
            }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

            step.reset();
        }
    }

    public void run() throws SaxonApiException {
        XProcData data = runtime.getXProcData();
        data.openFrame(this);
       
        copyInputs();

        // N.B. At this time, there are no compound steps that accept parameters or options,
        // so the order in which we calculate them doesn't matter. That will change if/when
        // there are such compound steps.

        // Calculate all the options
        inScopeOptions = parent.getInScopeOptions();
        for (QName name : step.getOptions()) {
            Option option = step.getOption(name);
            RuntimeValue value = computeValue(option);
            setOption(name, value);
            inScopeOptions.put(name, value);
        }

        for (Variable var : step.getVariables()) {
            RuntimeValue value = computeValue(var);
            inScopeOptions.put(var.getName(), value);
        }

        runtime.start(this);

        try {
            for (XStep step : subpipeline) {
                step.run();
            }

            for (String port : inputs.keySet()) {
                if (port.startsWith("|")) {
                    String wport = port.substring(1);
                    WritablePipe pipe = outputs.get(wport);
                    for (ReadablePipe reader : inputs.get(port)) {
                        while (reader.moreDocuments()) {
                            XdmNode doc = reader.read();
                            pipe.write(doc);
                            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Compound output copy from " + reader + " to " + pipe));
                        }
                    }
                }
            }
        } finally {
            runtime.finish(this);
            data.closeFrame();
        }
    }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

    }

    public void run() throws SaxonApiException {
        logger.trace("Running p:viewport " + step.getName());

        XProcData data = runtime.getXProcData();
        data.openFrame(this);

        if (current == null) {
            current = new Pipe(runtime);
        }
View Full Code Here

Examples of com.xmlcalabash.core.XProcData

        // N.B. At this time, there are no compound steps that accept parameters or options,
        // so the order in which we calculate them doesn't matter. That will change if/when
        // there are such compound steps.
       
        // Don't reset iteration-position and iteration-size
        XProcData data = runtime.getXProcData();
        int ipos = data.getIterationPosition();
        int isize = data.getIterationSize();
        data.openFrame(this);
        data.setIterationPosition(ipos);
        data.setIterationSize(isize);

        inScopeOptions = parent.getInScopeOptions();
        for (Variable var : step.getVariables()) {
            RuntimeValue value = computeValue(var);
            inScopeOptions.put(var.getName(), value);
        }

        runtime.start(this);

        XCompoundStep xstep = null;
        for (XStep step : subpipeline) {
            if (step instanceof XWhen) {
                XWhen when = (XWhen) step;
                if (when.shouldRun()) {
                    xstep = when;
                    break;
                }
            } else {
                // Must be an otherwise
                xstep = (XOtherwise) step;
                break;
            }
        }

        if (xstep == null) {
            throw XProcException.dynamicError(4);
        }

        for (String port : inputs.keySet()) {
            if (!port.startsWith("|") && !"#xpath-context".equals(port)) {
                xstep.inputs.put(port, inputs.get(port));
            }
        }

        for (String port : outputs.keySet()) {
            if (!port.endsWith("|")) {
                xstep.outputs.put(port, outputs.get(port));
            }
        }

        try {
            xstep.run();
        } finally {
            runtime.finish(this);
            data.closeFrame();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.