Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.xmlcalabash.runtime;
  
 
Created by IntelliJ IDEA. User: ndw Date: Oct 8, 2008 Time: 5:26:50 AM To change this template use File | Settings | File Templates.
 
 public class XCompoundStep extends XAtomicStep {
     protected Hashtable<QNameRuntimeValuevariables = new Hashtable<QName,RuntimeValue> ();
     protected Vector<XStepsubpipeline = new Vector<XStep> ();
 
     public XCompoundStep(XProcRuntime runtimeStep stepXCompoundStep parent) {
         super(runtimestepparent);
     }
 
     /*
     public void addVariable(QName name, RuntimeValue value) {
         variables.put(name, value);
     }
     */
 
     public boolean hasInScopeVariableBinding(QName name) {
         if (.containsKey(name) || .containsKey(name)) {
             return true;
         }
 
         return getParent() == null ? false : getParent().hasInScopeVariableBinding(name);
     }
 
     public boolean hasInScopeVariableValue(QName name) {
         if (.containsKey(name) || .containsKey(name)) {
             RuntimeValue v = getVariable(name);
             return v != null &&  v.initialized();
         }
 
         return getParent() == null ? false : getParent().hasInScopeVariableValue(name);
     }
 
     public RuntimeValue getVariable(QName name) {
         if (.containsKey(name)) {
             return .get(name);
         } else {
             if (.containsKey(name)) {
                 return .get(name);
             } else {
                 return null;
             }
         }
     }
 
     public ReadablePipe getBinding(String stepNameString portName) {
         if (.equals(stepName)) {
             XInput input = getInput(portName);
             return input.getReader();
         }
 
         for (XStep step : ) {
             if (stepName.equals(step.getName())) {
                 XOutput output = step.getOutput(portName);
                 if (output == null) {
                     return new ReadableEmpty();
                 } else {
                     ReadablePipe rpipe = output.getReader();
                     return rpipe;
                 }
             }
         }
         return .getBinding(stepNameportName);
     }
 
     protected void addStep(XStep step) {
         .add(step);
     }
 
     public void instantiate(Step step) {
         finest(step.getNode(), "--> instantiate " + step);
         
         instantiateReaders(step);
         .addStep(this);
 
         DeclareStep decl = step.getDeclaration();
        for (Step substep : decl.subpipeline()) {
            if (..equals(substep.getType())) {
                XChoose newstep = new XChoose(substepthis);
                newstep.instantiate(substep);
            } else if (..equals(substep.getType())) {
                XGroup newstep = new XGroup(substepthis);
                newstep.instantiate(substep);
            } else if (..equals(substep.getType())) {
                XTry newstep = new XTry(substepthis);
                newstep.instantiate(substep);
            } else if (..equals(substep.getType())) {
                XCatch newstep = new XCatch(substepthis);
                newstep.instantiate(substep);
            } else if (..equals(substep.getType())) {
                XForEach newstep = new XForEach(substepthis);
                newstep.instantiate(substep);
            } else if (..equals(substep.getType())) {
                XViewport newstep = new XViewport(substepthis);
                newstep.instantiate(substep);
            } else if (..equals(substep.getType())) {
                XUntilUnchanged newstep = new XUntilUnchanged(,substep,this);
                newstep.instantiate(substep);
            } else if (substep.isPipelineCall()) {
                DeclareStep subdecl = substep.getDeclaration();
                XPipelineCall newstep = new XPipelineCall(substepthis);
                newstep.setDeclaration(subdecl);
                newstep.instantiate(substep);
                /*
                // Make sure the caller's inputs and outputs have the right sequence values
                for (Input input : subdecl.inputs()) {
                    String port = input.getPort();
                    for (ReadablePipe rpipe : inputs.get(port)) {
                        rpipe.canReadSequence(input.getSequence());
                    }
                }
                for (Output output : subdecl.outputs()) {
                    String port = output.getPort();
                    WritablePipe wpipe = outputs.get(port);
                    wpipe.canWriteSequence(output.getSequence());
                }
                */
            } else {
                XAtomicStep newstep = new XAtomicStep(substepthis);
                newstep.instantiate(substep);
            }
        }
        for (Input input : step.inputs()) {
            String port = input.getPort();
            if (port.startsWith("|")) {
                Vector<ReadablePipereaders = null;
                if (.containsKey(port)) {
                    readers = .get(port);
                } else {
                    readers = new Vector<ReadablePipe> ();
                    .put(portreaders);
                }
                for (Binding binding : input.getBinding()) {
                    ReadablePipe pipe = getPipeFromBinding(binding);
                    pipe.canReadSequence(input.getSequence());
                    pipe.setReader(step);
                    readers.add(pipe);
                    finest(step.getNode(), step.getName() + " reads from " + pipe + " for " + port);
                    
                    /* Attempted fix by ndw on 7 Dec...seems to work
                    if (binding.getBindingType() == Binding.PIPE_NAME_BINDING) {
                        PipeNameBinding pnbinding = (PipeNameBinding) binding;
                        ReadablePipe pipe = getBinding(pnbinding.getStep(), pnbinding.getPort());
                        pipe.canReadSequence(input.getSequence());
                        pipe.setReader(step);
                        readers.add(pipe);
                        finest(step.getNode(), step.getName() + " reads from " + pipe + " for " + port);
                    } else {
                        throw new XProcException("Don't know how to handle binding " + binding.getBindingType());
                    }
                    */
                }
                XInput xinput = new XInput(input);
                addInput(xinput);
            }
        }
        for (Output output : step.outputs()) {
            String port = output.getPort();
            if (port.endsWith("|")) {
                String rport = port.substring(0,port.length()-1);
                XInput xinput = getInput(rport);
                WritablePipe wpipe = xinput.getWriter();
                wpipe.setWriter(step);
                wpipe.canWriteSequence(true); // Let the other half work it out
                .put(portwpipe);
                finest(step.getNode(), step.getName() + " writes to " + wpipe + " for " + port);
            } else {
                XOutput xoutput = new XOutput(output);
                xoutput.setLogger(step.getLog(port));
                addOutput(xoutput);
                WritablePipe wpipe = xoutput.getWriter();
                wpipe.setWriter(step);
                wpipe.canWriteSequence(output.getSequence());
                .put(portwpipe);
                finest(step.getNode(), step.getName() + " writes to " + wpipe + " for " + port);
            }
        }
    }
    protected void copyInputs() throws SaxonApiException {
        for (String port : .keySet()) {
            if (!port.startsWith("|")) {
                String wport = port + "|";
                WritablePipe pipe = .get(wport);
                for (ReadablePipe reader : .get(port)) {
                    while (reader.moreDocuments()) {
                        XdmNode doc = reader.read();
                        pipe.write(doc);
                        finest(.getNode(), "Compound input copy from " + reader + " to " + pipe);
                    }
                }
            }
        }
    }
    public void reset() {
        super.reset();
        for (XStep step : ) {
            step.reset();
        }
    }
    public void run() throws SaxonApiException {
        XProcData data = .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
        for (QName name : .getOptions()) {
            Option option = .getOption(name);
            RuntimeValue value = computeValue(option);
            setOption(namevalue);
            .put(namevalue);
        }
        for (Variable var : .getVariables()) {
            RuntimeValue value = computeValue(var);
            .put(var.getName(), value);
        }
        .start(this);
        for (XStep step : ) {
            step.run();
        }
        .finish(this);
        for (String port : .keySet()) {
            if (port.startsWith("|")) {
                String wport = port.substring(1);
                WritablePipe pipe = .get(wport);
                for (ReadablePipe reader : .get(port)) {
                    while (reader.moreDocuments()) {
                        XdmNode doc = reader.read();
                        pipe.write(doc);
                        finest(.getNode(), "Compound output copy from " + reader + " to " + pipe);
                    }
                }
            }
        }
        data.closeFrame();
    }
New to GrepCode? Check out our FAQ X