org.orbeon.oxf.processor
Class ProcessorImpl

java.lang.Object
  extended by org.orbeon.oxf.processor.ProcessorImpl
All Implemented Interfaces:
Processor
Direct Known Subclasses:
SimpleProcessor

public abstract class ProcessorImpl
extends Object
implements Processor

Helper class that implements default method of the Processor interface.


Nested Class Summary
static class ProcessorImpl.KeyValidity
           
 class ProcessorImpl.ProcessorKey
           
protected  class ProcessorImpl.ProcessorOutputImpl
           
 
Field Summary
static String INPUT_CONFIG
           
static String INPUT_DATA
           
static org.apache.log4j.Logger logger
           
static String OUTPUT_DATA
           
protected static String PARENT_PROCESSORS
          This is for internal pipeline engine use.
static String PROCESSOR_INPUT_SCHEME
           
static int PROCESSOR_SEQUENCE_NUMBER
           
static String PROCESSOR_VALIDATION_FLAG
           
static String SAX_INSPECTION_FLAG
           
static String USER_VALIDATION_FLAG
           
 
Constructor Summary
protected ProcessorImpl()
           
 
Method Summary
 void addInput(String inputName, ProcessorInput input)
           
protected  void addInputInfo(ProcessorInputOutputInfo inputInfo)
           
 void addOutput(String name, ProcessorOutput output)
           
protected  void addOutputInfo(ProcessorInputOutputInfo outputInfo)
           
 ProcessorInput createInput(String name)
          Creates a new input on this processor.
 ProcessorOutput createOutput(String outputName)
          Creates a new output on this processor.
 void deleteInput(ProcessorInput input)
          Deletes an input previously created with createInput(String name)
 void deleteOutput(ProcessorOutput output)
          Deletes an output previously created with createOutput(String name)
 long findInputLastModified(PipelineContext pipelineContext, ProcessorInput input, boolean inputMustBeInCache)
          Find the last modified timestamp of a particular input.
static long findLastModified(Object validity)
          Recursively find the last modified timestamp of a validity object.
 Map<String,List<ProcessorInput>> getConnectedInputs()
           
 Map<String,ProcessorOutput> getConnectedOutputs()
           
 String getId()
          A processor may have an "identifier".
 ProcessorInput getInputByName(String name)
           
 ProcessorInputOutputInfo getInputInfo(String name)
           
static OutputCacheKey getInputKey(PipelineContext context, ProcessorInput input)
           
 ProcessorImpl.KeyValidity getInputKeyValidity(PipelineContext context, ProcessorInput input)
          Subclasses can use this utility method to obtain the key and validity associated with an input when implementing the getKey and getValidity methods.
 Set<String> getInputNames()
           
 List<ProcessorInput> getInputsByName(String name)
           
 List<ProcessorInputOutputInfo> getInputsInfo()
           
static Object getInputValidity(PipelineContext context, ProcessorInput input)
           
 LocationData getLocationData()
          When this processor is created based on a declaration in an XML document, the LocationData provides information about the location of this declaration.
 org.dom4j.QName getName()
          Name of the processor, if it has been created by a factory and that factory has a name.
 ProcessorOutput getOutputByName(String outputName)
           
 int getOutputCount()
           
 List<ProcessorInputOutputInfo> getOutputsInfo()
           
static String getProcessorInputSchemeInputName(String uri)
          Return the input name if the URI is referring to a processor input, null otherwise.
 ProcessorImpl.ProcessorKey getProcessorKey(PipelineContext context)
          Returns a key that should be used to store the state of the processor in the context.
protected  PropertySet getPropertySet()
          Return a property set for this processor.
 int getSequenceNumber()
          TODO
 Object getState(PipelineContext pipelineContext)
          This method is used to retrieve the state information set with setState().
 boolean hasState(PipelineContext context)
           
 boolean isInputInCache(PipelineContext context, ProcessorInput input)
          Subclasses can use this utility method when implementing the getKey and getValidity methods to make sure that they don't read the whole config (if we don't already have it) just to return a key/validity.
static boolean isProcessorInputScheme(String uri)
          Check if the given URI is referring to a processor input.
 Document readCacheInputAsDOM(PipelineContext context, String inputName)
           
 org.dom4j.Document readCacheInputAsDOM4J(PipelineContext context, String inputName)
           
 Object readCacheInputAsObject(PipelineContext pipelineContext, ProcessorInput input, CacheableInputReader reader)
          To be used in the readImpl implementation of a processor when an object is created based on an input (an the object only depends on the input).
 Object readCacheInputAsObject(PipelineContext pipelineContext, ProcessorInput input, CacheableInputReader reader, boolean logCache)
           
 org.orbeon.saxon.om.DocumentInfo readCacheInputAsTinyTree(PipelineContext pipelineContext, org.orbeon.saxon.Configuration configuration, String inputName)
           
 Document readInputAsDOM(PipelineContext context, ProcessorInput input)
           
 org.dom4j.Document readInputAsDOM4J(PipelineContext context, ProcessorInput input)
           
static void readInputAsSAX(PipelineContext context, ProcessorInput input, XMLReceiver xmlReceiver)
          The fundamental read method based on SAX.
 org.orbeon.saxon.om.DocumentInfo readInputAsTinyTree(PipelineContext pipelineContext, org.orbeon.saxon.Configuration configuration, ProcessorInput input)
           
 void reset(PipelineContext pipelineContext)
          Resets the processor.
 void setId(String id)
           
 void setLocationData(LocationData loc)
           
 void setName(org.dom4j.QName name)
           
 void setState(PipelineContext context, Object state)
          This method is used by processor implementations to store state information tied to the current execution of the current processor, across processor initialization as well as reads of all the processor's outputs.
 void start(PipelineContext pipelineContext)
          This method is called to trigger the execution of this processor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static org.apache.log4j.Logger logger

INPUT_DATA

public static final String INPUT_DATA
See Also:
Constant Field Values

INPUT_CONFIG

public static final String INPUT_CONFIG
See Also:
Constant Field Values

OUTPUT_DATA

public static final String OUTPUT_DATA
See Also:
Constant Field Values

PROCESSOR_VALIDATION_FLAG

public static final String PROCESSOR_VALIDATION_FLAG
See Also:
Constant Field Values

USER_VALIDATION_FLAG

public static final String USER_VALIDATION_FLAG
See Also:
Constant Field Values

SAX_INSPECTION_FLAG

public static final String SAX_INSPECTION_FLAG
See Also:
Constant Field Values

PROCESSOR_SEQUENCE_NUMBER

public static int PROCESSOR_SEQUENCE_NUMBER

PROCESSOR_INPUT_SCHEME

public static final String PROCESSOR_INPUT_SCHEME
See Also:
Constant Field Values

PARENT_PROCESSORS

protected static final String PARENT_PROCESSORS
This is for internal pipeline engine use.

See Also:
Constant Field Values
Constructor Detail

ProcessorImpl

protected ProcessorImpl()
Method Detail

getSequenceNumber

public int getSequenceNumber()
Description copied from interface: Processor
TODO

Specified by:
getSequenceNumber in interface Processor

getPropertySet

protected PropertySet getPropertySet()
Return a property set for this processor.


getLocationData

public LocationData getLocationData()
Description copied from interface: Processor
When this processor is created based on a declaration in an XML document, the LocationData provides information about the location of this declaration. Typically, if this processor corresponds to a a PDL file, the LocationData holds information regarding the position of the element in the PDL file.

Specified by:
getLocationData in interface Processor
Returns:
the LocationData for this processor

setLocationData

public void setLocationData(LocationData loc)
Specified by:
setLocationData in interface Processor
Parameters:
loc - the new LocationData of this processor
See Also:
Processor.getLocationData()

setId

public void setId(String id)
Specified by:
setId in interface Processor
Parameters:
id - the new id of this processor
See Also:
Processor.getId()

getId

public String getId()
Description copied from interface: Processor
A processor may have an "identifier". The identifier has no implication on the behaviour of the processor. It is there for information only (for instance, it will be displayed by the Inspector). In the pipeline language, the id is specified with the "id" attribute of the element.

Specified by:
getId in interface Processor
Returns:
the identifier of this processor

getName

public org.dom4j.QName getName()
Description copied from interface: Processor
Name of the processor, if it has been created by a factory and that factory has a name. The name has no implication on the behaviour of the processor. It is there for information only.

Specified by:
getName in interface Processor
Returns:
The name of this processor

setName

public void setName(org.dom4j.QName name)
Specified by:
setName in interface Processor
Parameters:
name - The new name of this processor
See Also:
Processor.getName()

getInputByName

public ProcessorInput getInputByName(String name)
Specified by:
getInputByName in interface Processor
Parameters:
name - Name of the input
Returns:
The inputs that have been previously created with createInput(String name). Returns null if there is no existing input with this name.
See Also:
Processor.createInput(java.lang.String)

getInputsByName

public List<ProcessorInput> getInputsByName(String name)

createInput

public ProcessorInput createInput(String name)
Description copied from interface: Processor
Creates a new input on this processor. The new input can then be connected to the output of an other processor. This method cannot be called twice with the same name on the same processor.

Specified by:
createInput in interface Processor
Parameters:
name - Name of the input to create
Returns:
The newly created input

addInput

public void addInput(String inputName,
                     ProcessorInput input)

deleteInput

public void deleteInput(ProcessorInput input)
Description copied from interface: Processor
Deletes an input previously created with createInput(String name)

Specified by:
deleteInput in interface Processor
Parameters:
input - Name of the input to delete
See Also:
Processor.createInput(java.lang.String)

getOutputByName

public ProcessorOutput getOutputByName(String outputName)
Specified by:
getOutputByName in interface Processor
Parameters:
outputName - Name of the output
Returns:
The outputs that have been previously created with createOutput(String name). Returns null if there is no existing output with this name.
See Also:
Processor.createOutput(java.lang.String)

createOutput

public ProcessorOutput createOutput(String outputName)
Description copied from interface: Processor
Creates a new output on this processor. The output can then be connected to the input of an other processor. This method cannnot be called twice on the same processor with the same name.

Specified by:
createOutput in interface Processor
Parameters:
outputName - Name of the output to create. null is allowed.
Returns:
The newly created output

addOutput

public void addOutput(String name,
                      ProcessorOutput output)

getOutputCount

public int getOutputCount()

deleteOutput

public void deleteOutput(ProcessorOutput output)
Description copied from interface: Processor
Deletes an output previously created with createOutput(String name)

Specified by:
deleteOutput in interface Processor
Parameters:
output - Name of the output to delete
See Also:
Processor.createOutput(java.lang.String)

addInputInfo

protected void addInputInfo(ProcessorInputOutputInfo inputInfo)

addOutputInfo

protected void addOutputInfo(ProcessorInputOutputInfo outputInfo)

getInputNames

public Set<String> getInputNames()
Specified by:
getInputNames in interface Processor
Returns:
Names of all the inputs connected to this processor.

getInputsInfo

public List<ProcessorInputOutputInfo> getInputsInfo()
Specified by:
getInputsInfo in interface Processor
Returns:
A list of ProcessorInputOutputInfo objects corresponding to the inputs that can be created on this processor. This exposes the "input API" of this processor.

getConnectedInputs

public Map<String,List<ProcessorInput>> getConnectedInputs()
Specified by:
getConnectedInputs in interface Processor
Returns:
A read-only Map containing all the inputs currently connected to this processor. Each key in the Map is a String specifying an input name. The List associated to the key contains one or more ProcessorInput objects. This is particularly useful to detect whether optional inputs are connected.

getInputInfo

public ProcessorInputOutputInfo getInputInfo(String name)

getOutputsInfo

public List<ProcessorInputOutputInfo> getOutputsInfo()
Specified by:
getOutputsInfo in interface Processor
Returns:
A list of ProcessorInputOutputInfo objects corresponding to the outputs that can be created on this processor. This exposes the "outputs API" of this processor.

getConnectedOutputs

public Map<String,ProcessorOutput> getConnectedOutputs()
Specified by:
getConnectedOutputs in interface Processor
Returns:
A read-only Map containing all the outputs currently connected to this processor. Each key in the Map is a String specifying an output name. The List associated to the key contains one or more ProcessorOutput objects. This is particularly useful to detect whether optional outputs are connected.

readInputAsSAX

public static void readInputAsSAX(PipelineContext context,
                                  ProcessorInput input,
                                  XMLReceiver xmlReceiver)
The fundamental read method based on SAX.


readInputAsDOM

public Document readInputAsDOM(PipelineContext context,
                               ProcessorInput input)

readInputAsDOM4J

public org.dom4j.Document readInputAsDOM4J(PipelineContext context,
                                           ProcessorInput input)

readInputAsTinyTree

public org.orbeon.saxon.om.DocumentInfo readInputAsTinyTree(PipelineContext pipelineContext,
                                                            org.orbeon.saxon.Configuration configuration,
                                                            ProcessorInput input)

readCacheInputAsDOM

public Document readCacheInputAsDOM(PipelineContext context,
                                    String inputName)

readCacheInputAsDOM4J

public org.dom4j.Document readCacheInputAsDOM4J(PipelineContext context,
                                                String inputName)

readCacheInputAsTinyTree

public org.orbeon.saxon.om.DocumentInfo readCacheInputAsTinyTree(PipelineContext pipelineContext,
                                                                 org.orbeon.saxon.Configuration configuration,
                                                                 String inputName)

readCacheInputAsObject

public Object readCacheInputAsObject(PipelineContext pipelineContext,
                                     ProcessorInput input,
                                     CacheableInputReader reader)
To be used in the readImpl implementation of a processor when an object is created based on an input (an the object only depends on the input).

Parameters:
input - The input the object depends on
reader - The code constructing the object based on the input
Returns:
The object returned by the reader (either directly returned, or from the cache)

readCacheInputAsObject

public Object readCacheInputAsObject(PipelineContext pipelineContext,
                                     ProcessorInput input,
                                     CacheableInputReader reader,
                                     boolean logCache)

getState

public Object getState(PipelineContext pipelineContext)
This method is used to retrieve the state information set with setState(). This method may be called from start() and ProcessorOutput.readImpl().

Specified by:
getState in interface Processor
Parameters:
pipelineContext - current context
Returns:
state object set by the caller of setState()

setState

public void setState(PipelineContext context,
                     Object state)
This method is used by processor implementations to store state information tied to the current execution of the current processor, across processor initialization as well as reads of all the processor's outputs. This method should be called from the reset() method.

Parameters:
context - current PipelineContext object
state - user-defined object containing state information

hasState

public boolean hasState(PipelineContext context)

getProcessorKey

public ProcessorImpl.ProcessorKey getProcessorKey(PipelineContext context)
Returns a key that should be used to store the state of the processor in the context. This method must be called in ProcessorOutput.readImpl() or start() of the processors before read/start is called on other processors. (The key returned by getProcessorKey can be used after read/start is called.)


start

public void start(PipelineContext pipelineContext)
Description copied from interface: Processor
This method is called to trigger the execution of this processor. This method can only be called on processor with no outputs (so-called serializers). If this processor has outputs, the method read should be called on the outputs instead.

Specified by:
start in interface Processor
Parameters:
pipelineContext - Context in which the processor is executed

reset

public void reset(PipelineContext pipelineContext)
Description copied from interface: Processor
Resets the processor. This method is called before the processor is executed (either by calling read its outputs, or by calling start on the processor.

Specified by:
reset in interface Processor
Parameters:
pipelineContext - Context in which the processor is executed

isProcessorInputScheme

public static boolean isProcessorInputScheme(String uri)
Check if the given URI is referring to a processor input.


getProcessorInputSchemeInputName

public static String getProcessorInputSchemeInputName(String uri)
Return the input name if the URI is referring to a processor input, null otherwise.


getInputKey

public static OutputCacheKey getInputKey(PipelineContext context,
                                         ProcessorInput input)

getInputValidity

public static Object getInputValidity(PipelineContext context,
                                      ProcessorInput input)

isInputInCache

public boolean isInputInCache(PipelineContext context,
                              ProcessorInput input)
Subclasses can use this utility method when implementing the getKey and getValidity methods to make sure that they don't read the whole config (if we don't already have it) just to return a key/validity.

Specified by:
isInputInCache in interface Processor
Returns:

getInputKeyValidity

public ProcessorImpl.KeyValidity getInputKeyValidity(PipelineContext context,
                                                     ProcessorInput input)
Subclasses can use this utility method to obtain the key and validity associated with an input when implementing the getKey and getValidity methods.

Returns:
a KeyValidity object containing non-null key and validity, or null

findInputLastModified

public long findInputLastModified(PipelineContext pipelineContext,
                                  ProcessorInput input,
                                  boolean inputMustBeInCache)
Find the last modified timestamp of a particular input.

Parameters:
pipelineContext - pipeline context
input - input to check
inputMustBeInCache - if true, also return 0 if the input is not currently in cache
Returns:
timestamp, <= 0 if unknown

findLastModified

public static long findLastModified(Object validity)
Recursively find the last modified timestamp of a validity object. Supported types are Long and List. The latest timestamp is returned.

Parameters:
validity - validity object
Returns:
timestamp, <= 0 if unknown