/* * */ package org.orbeon.oxf.processor.pipeline; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.orbeon.oxf.cache.OutputCacheKey; import org.orbeon.oxf.debugger.api.Breakpoint; import org.orbeon.oxf.debugger.api.Debuggable; import org.orbeon.oxf.pipeline.api.PipelineContext; import org.orbeon.oxf.processor.ProcessorImpl; import org.orbeon.oxf.processor.*; import org.orbeon.oxf.util.LoggerFactory; import org.xml.sax.ContentHandler; /** * Proxy for PipelineProcessor - use instead of PipelineProcessor when XPL to run appears on pipeline input rather than config input * Creates a PipelineProcessor from the pipeline input, connects inputs and outputs to this processor's inputs and outputs */ public class PipelineProcessorProxy extends ProcessorImpl implements Debuggable { private static Logger logger = LoggerFactory.createLogger(PipelineProcessorProxy.class); private static final String INPUT_PIPELINE = "pipeline"; public PipelineProcessorProxy() { addInputInfo(new ProcessorInputOutputInfo(INPUT_PIPELINE)); } /** * create the PipelineProcessor, from the config input, or from state if already created */ protected PipelineProcessor Pipeline(PipelineContext context) { State state = (State) getState(context); if (state.pipeline == null ) { PipelineReader reader = new PipelineReader(); ProcessorInput pipelineReaderInput = reader.createInput("pipeline"); final ProcessorInput config = getInputByName(INPUT_PIPELINE); pipelineReaderInput.setOutput(new ProcessorImpl.ProcessorOutputImpl(getClass(), "dummy") { public void readImpl(PipelineContext context, ContentHandler contentHandler) { ProcessorImpl.readInputAsSAX(context, config, contentHandler); } public OutputCacheKey getKeyImpl(PipelineContext context) { return getInputKey(context, config); } public Object getValidityImpl(PipelineContext context) { return getInputValidity(context, config); } }); reader.start(context); state.pipeline = new PipelineProcessor(reader.getPipeline()); state.pipeline.reset(context); // connect inputs of this processor to the pipeline we've created Iterator it = getConnectedInputs().entrySet().iterator(); while (it.hasNext()) { String name = (String)((java.util.Map.Entry)it.next()).getKey(); // don't connect this pipeline's config (pipeline) input if (name != INPUT_PIPELINE) state.pipeline.addInput(name, getInputByName(name)); } } return state.pipeline; } /* * for pipelines with no outputs, call start on the pipeline */ public void start(PipelineContext pipelineContext) { State state = (State) getState(pipelineContext); if (!state.started) { Pipeline(pipelineContext).start(pipelineContext); state.started = true; } } public void reset(final PipelineContext context) { setState(context, new State()); } public ProcessorOutput createOutput(final String name) { ProcessorOutput output = new ProcessorImpl.ProcessorOutputImpl(getClass(), name) { public void readImpl(PipelineContext pipelineContext, ContentHandler contentHandler) { // read the pipeline's output Pipeline(pipelineContext).createOutput(name).read(pipelineContext, contentHandler); } }; addOutput(name, output); return output; } private static class State { public PipelineProcessor pipeline = null; public boolean started = false; } private List breakpoints; public void addBreakpoint(Breakpoint breakpoint) { if (breakpoints == null) breakpoints = new ArrayList(); breakpoints.add(breakpoint); } public List getBreakpoints() { return breakpoints; } }