Class FWProcessor

java.lang.Object
net.simplace.pipe.control.FWProcessor
Direct Known Subclasses:
AsciiToDatabaseTableProcessor, BrowseFolderProcessor, CopyFolderProcessor, CopyTableProcessor, CreateDBConnectionProcessor, CreateFileListProcessor, DeleteFilesProcessor, DownloadFileProcessor, EncodingConverterProcessor, FWLoopProcessor, JDOMParserProcessor, JDOMUnparseProcessor, MoveFileProcessor, ReadFileProcessor, ReleaseDBConnectionProcessor, RuleProcessor, RunAppProcessor, SaveProjectTemplateProcessor, SolutionToXMLProcessor, SQLStatementProcessor, UnzipFolderProcessor, WriteFileProcessor, WriteProjectXMLProcessor, XSLTTransformerProcessor

public abstract class FWProcessor extends Object
Abstract superclass for all standard and custom processors. A processor is one step of a FWPipeLine; it is declared as <processor class="..." progressid="..." if="..."> with <parameter key="...">value</parameter> children (initial parameters) and an optional <configuration> element. When piped, it works on a copy of the incoming parameters (plus its initial parameters) and writes its results to the outgoing observable.
Author:
Andreas Enders
  • Field Details

    • iContainer

      protected FWPipeLinesContainer iContainer
      The pipeline container this processor belongs to.
    • iProgressTasks

      protected ArrayList<FWProgressTask> iProgressTasks
      The progressTasks of this Processor.
    • iInObservable

      protected net.simplace.core.FWObservable iInObservable
      Map of parameters worked with in this processor.
    • iObservable

      protected net.simplace.core.FWObservable iObservable
      Map of parameters put to output for next processor.
    • iAllreadyLoopedCount

      protected int iAllreadyLoopedCount
      Number of loops this processor was run through (index of the current progress task).
  • Constructor Details

    • FWProcessor

      public FWProcessor()
  • Method Details

    • createProcessor

      public static FWProcessor createProcessor(org.jdom2.Element aProcessorElement, FWPipeLinesContainer aContainer) throws PipeLineCreationException
      Creates a processor by instantiating the class given in the attribute class of the element and initialises it (parameters, loop settings, progress task, configuration, if-expression).
      Parameters:
      aProcessorElement - the processor element
      aContainer - the pipeline container the processor belongs to
      Returns:
      the created processor
      Throws:
      PipeLineCreationException - if the class cannot be instantiated or a parameter has no key
    • createProcessor

      public static FWProcessor createProcessor(String aClassName) throws PipeLineCreationException
      Creates an uninitialised processor of the given class (no container, parameters or configuration).
      Parameters:
      aClassName - fully qualified name of the processor class
      Returns:
      the created processor
      Throws:
      PipeLineCreationException - if the class cannot be instantiated
    • clone

      public FWProcessor clone()
      Creates a new instance of the same class with the same container, configuration, if-expression and end-of-pipe flag. The list of progress tasks and the map of initial parameters are shared with the original on purpose: the progress view adds one task per clone to the shared list (getNewProgressTask()), and each clone uses its task by its loop count; access to the list is synchronized. The initial parameters are not changed after the pipeline is created.
      Overrides:
      clone in class Object
      Throws:
      RuntimeException - if the class cannot be instantiated
    • setInitialParameters

      protected void setInitialParameters(Map<String,Object> aInitialParameterMap)
      Parameters:
      aInitialParameterMap - the new initial parameters (the map is used, not copied)
    • getInitialParameters

      protected Map<String,Object> getInitialParameters()
      Returns:
      the initial parameters of this processor
    • process

      protected abstract boolean process() throws PipeLineException
      Must be overridden to implement the concrete processing step. Reads from the in parameters and writes results with setOutParameter(String, Object).
      Returns:
      true on success; false makes pipe(FWObservable, Integer) fail
      Throws:
      PipeLineException - if processing fails
    • checkInParameterMap

      protected boolean checkInParameterMap()
      Can be overridden to perform semantic checks on the input parameters before process().
      Returns:
      true if the input is valid; the default returns true
    • containsParameter

      protected boolean containsParameter(String aSourceKey)
      Parameters:
      aSourceKey - parameter key
      Returns:
      true if the parameter is set in the in parameters
    • setEndOfPipeFlag

      protected void setEndOfPipeFlag()
      Sets the end of pipe flag. Pipe line is aborted after this processor.
    • isEndOfPipe

      public boolean isEndOfPipe()
      Returns:
      true if the end of pipe flag is set, i.e. the pipeline is aborted after this processor
    • checkOutParameterMap

      protected boolean checkOutParameterMap()
      Can be overridden to perform semantic checks on the output after process().
      Returns:
      true if the output is valid; the default returns true
    • getInParameter

      protected Object getInParameter(String aKey)
      Parameters:
      aKey - parameter key
      Returns:
      the value from the in parameters, or null if not set
    • getInParameters

      protected net.simplace.core.FWObservable getInParameters()
      Returns:
      the in parameters (copy of the incoming parameters plus the initial parameters)
    • getInParameter

      protected Object getInParameter(String aKey, Object aDefault)
      Parameters:
      aKey - parameter key
      aDefault - value returned if the parameter is not set
      Returns:
      the value from the in parameters, or aDefault
    • getStringInParameter

      protected String getStringInParameter(String aKey, String aDefault)
      Returns the value of the parameter if it is a string (no token replacement).
      Parameters:
      aKey - parameter key
      aDefault - value returned if the parameter is not set or not a string
      Returns:
      the string value from the in parameters, or aDefault
    • getAllStringInParameters

      protected Map<String,String> getAllStringInParameters(String aKeyPrefix, boolean aElimKeyPrefix)
      Returns all string in parameters, whose keys start with a given prefix.
      Parameters:
      aKeyPrefix - prefix the "wanted" parameters must start with
      aElimKeyPrefix - if false the keys of the found parameters are used unchanged for the returned map. If true the prefix is eliminated for the use in the destination map.
      Returns:
      an empty map, when aKeyPrefix is null
    • getStringInParameter

      protected String getStringInParameter(String aKey)
      Returns the value of the parameter as string, with parameter tokens replaced (see FWObservable.getStringParameterValue(String)).
      Parameters:
      aKey - parameter key
      Returns:
      the in parameter as string, or null if not set
    • setOutParameter

      protected void setOutParameter(String aKey, Object aValue)
      Sets a parameter in the outgoing observable (created from the initial parameters if not yet set).
      Parameters:
      aKey - parameter key
      aValue - the value
    • setInParameterMap

      protected void setInParameterMap(net.simplace.core.FWObservable aObservable)
      Parameters:
      aObservable - the new in parameters
    • getOutParameter

      protected Object getOutParameter(String aKey)
      Parameters:
      aKey - parameter key
      Returns:
      the value from the outgoing observable, or null if not set
    • getOutParameterKeys

      protected Set<String> getOutParameterKeys()
      Returns:
      a copy of the keys of the outgoing observable
    • removeOutParameter

      protected void removeOutParameter(String aElement)
      Removes a parameter from the outgoing observable.
      Parameters:
      aElement - parameter key
    • pipe

      public net.simplace.core.FWObservable pipe(net.simplace.core.FWObservable aObservabe, Integer aAllreadyLoopedCount) throws PipeLineException
      Pipes the observable through this processor: builds the in parameters (copy of aObservabe plus initial parameters), evaluates the if-expression (if false, the observable is returned unchanged), performs the channel replacements, checks the input, runs process() and checks the output. Progress task states are updated along the way.
      Parameters:
      aObservabe - the incoming observable; also used as outgoing observable
      aAllreadyLoopedCount - number of loops already run; the processor's loop count is set to this value + 1
      Returns:
      the outgoing observable
      Throws:
      PipeLineException - if the input check, processing or output check fails
    • getConfiguration

      protected org.jdom2.Element getConfiguration()
      Returns the configuration of the processor. A configuration passed as in parameter CONFIGURATION_<class name> (or CONFIGURATION_<progress id>) replaces the one from the configuration element.
      Returns:
      the configuration element, or null
    • setConfiguration

      protected void setConfiguration(String aClassname, org.jdom2.Element aConfigurationElement)
      Passes a configuration to a following processor as out parameter CONFIGURATION_<class name>.
      Parameters:
      aClassname - class name (or progress id) of the target processor
      aConfigurationElement - the configuration element
    • hasConfiguration

      protected boolean hasConfiguration()
      Returns:
      true if the processor has a configuration element
    • fireTaskEvent

      protected void fireTaskEvent(JPanel aSourcePanel)
      Fires a task event for the current progress task to the listeners of the container (does nothing if the processor has no progress task).
      Parameters:
      aSourcePanel - panel to show in the progress view, or null
    • getNewProgressTask

      public FWProgressTask getNewProgressTask()
      Adds a clone of the first progress task (for a further loop). Synchronized on the task list, which is shared with the clones of this processor (see clone()).
      Returns:
      the new progress task, or null if the processor has no progress task
    • getProgressTask

      public FWProgressTask getProgressTask()
      Returns:
      the progress task for the current loop count, or null if there is none
    • getPipeLine

      protected FWPipeLine getPipeLine(String aPipeLineID)
      Parameters:
      aPipeLineID - id of the pipeline
      Returns:
      a clone of the pipeline from the container (see FWPipeLinesContainer.getPipeLine(String))
    • getSystemID

      protected String getSystemID()
      Returns:
      the system id of the pipeline container, or of the in parameters if there is no container
    • setStateProgressing

      protected void setStateProgressing(int aPercentDone, String aMessage)
      Sets the current progress task to progressing and fires a task event (does nothing without progress task).
      Parameters:
      aPercentDone - progress in percent (0-100)
      aMessage - message to show
    • setStateOfTask

      protected void setStateOfTask(String aStatusOfTask)
      Sets the state of the current progress task and fires a task event (does nothing without progress task).
      Parameters:
      aStatusOfTask - the new state, one of the constants in FWProgressTask.State
    • setLoopedCount

      protected void setLoopedCount(int aNumberOfAllreadyLooped)
      Sets the loop count; has to be set by the looping processor because of thread safety.
      Parameters:
      aNumberOfAllreadyLooped - number of loops already run
    • toXML

      public org.jdom2.Element toXML()
      Returns:
      an XML description of the processor; not implemented, always null