org.orbeon.oxf.processor
Class ProcessorImpl

java.lang.Object
  extended byorg.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
 class ProcessorImpl.CacheableTransformerOutputImpl
          Implementation of a caching transformer output that assumes that an output simply depends on all the inputs plus optional local information.
protected static class ProcessorImpl.DigestState
           
 class ProcessorImpl.DigestTransformerOutputImpl
          Implementation of a caching transformer output that assumes that an output simply depends on all the inputs plus optional local information that can be digested.
static class ProcessorImpl.KeyValidity
           
static class ProcessorImpl.ProcessorInputImpl
          Basic implementation of ProcessorInput.
 class ProcessorImpl.ProcessorKey
           
static class ProcessorImpl.ProcessorOutputImpl
          Basic implementation of ProcessorOutput.
 
Field Summary
static org.orbeon.oxf.util.IndentedLogger indentedLogger
           
static String INPUT_CONFIG
           
static String INPUT_DATA
           
static char KEY_SEPARATOR
           
static org.apache.log4j.Logger logger
           
static String OUTPUT_DATA
           
static String PROCESSOR_INPUT_SCHEME
           
static String PROCESSOR_INPUT_SCHEME_OLD
           
static String PROCESSOR_VALIDATION_FLAG
           
static String SAX_INSPECTION_FLAG
           
static String USER_VALIDATION_FLAG
           
 
Constructor Summary
ProcessorImpl()
           
 
Method Summary
 void addInput(String name, org.orbeon.oxf.processor.ProcessorInput input)
           
protected  void addInputInfo(ProcessorInputOutputInfo inputInfo)
           
 void addOutput(String name, org.orbeon.oxf.processor.ProcessorOutput output)
           
protected  void addOutputInfo(ProcessorInputOutputInfo outputInfo)
           
 void checkSockets()
           
 org.orbeon.oxf.processor.ProcessorInput createInput(String name)
          Creates a new input on this processor.
 org.orbeon.oxf.processor.ProcessorOutput createOutput(String name)
          Creates a new output on this processor.
 void deleteInput(org.orbeon.oxf.processor.ProcessorInput input)
          Deletes an input previously created with createInput(String name)
 void deleteOutput(org.orbeon.oxf.processor.ProcessorOutput output)
          Deletes an output previously created with createOutput(String name)
protected  void executeChildren(PipelineContext context, Runnable runnable)
          For use in processor that contain other processors.
protected static void executeParents(PipelineContext context, Runnable runnable)
          For use in processor that contain other processors.
protected  long findInputLastModified(PipelineContext pipelineContext, org.orbeon.oxf.processor.ProcessorInput input, boolean inputMustBeInCache)
          Find the last modified timestamp of a particular input.
protected static long findLastModified(Object validity)
          Recursively find the last modified timestamp of a validity object.
protected  Object getCachedInputAsObject(PipelineContext pipelineContext, org.orbeon.oxf.processor.ProcessorInput processorInput)
           
protected  Object getCacheOutputObject(PipelineContext pipelineContext, ProcessorImpl.ProcessorOutputImpl processorOutput, String keyName, org.orbeon.oxf.processor.OutputObjectCreator creator)
          Cache an object associated with a given processor output.
 Map getConnectedInputs()
           
 Map getConnectedOutputs()
           
 String getId()
          A processor may have an "identifier".
 org.orbeon.oxf.processor.ProcessorInput getInputByName(String name)
           
 ProcessorInputOutputInfo getInputInfo(String name)
           
protected static org.orbeon.oxf.cache.OutputCacheKey getInputKey(PipelineContext context, org.orbeon.oxf.processor.ProcessorInput input)
           
protected  ProcessorImpl.KeyValidity getInputKeyValidity(PipelineContext context, org.orbeon.oxf.processor.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.
protected  ProcessorImpl.KeyValidity getInputKeyValidity(PipelineContext context, String inputName)
           
 List getInputsByName(String name)
           
 List getInputsInfo()
           
protected static Object getInputValidity(PipelineContext context, org.orbeon.oxf.processor.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.
 QName getName()
          Name of the processor, if it has been created by a factory and that factory has a name.
 org.orbeon.oxf.processor.ProcessorOutput getOutputByName(String name)
           
 ProcessorInputOutputInfo getOutputInfo(String name)
           
protected  Object getOutputObject(PipelineContext pipelineContext, ProcessorImpl.ProcessorOutputImpl processorOutput, String keyName)
          Get a cached object associated with a given processor output.
protected  Object getOutputObject(PipelineContext pipelineContext, ProcessorImpl.ProcessorOutputImpl processorOutput, String keyName, ProcessorImpl.KeyValidity outputKeyValidityImpl)
           
 List getOutputsInfo()
           
protected static Object getParentState(PipelineContext context)
           
static String getProcessorInputSchemeInputName(String uri)
          Return the input name if the URI is referring to a processor input, null otherwise.
protected  ProcessorImpl.ProcessorKey getProcessorKey(PipelineContext context)
          Returns a key that should be used to store the state of the processor in the context.
protected  org.orbeon.oxf.properties.PropertySet getPropertySet()
          Return a property set for this processor.
 Object getState(PipelineContext context)
          This method is used to retrieve the state information set with setState().
protected  boolean hasState(PipelineContext context)
           
protected  boolean isInputInCache(PipelineContext context, ProcessorImpl.KeyValidity keyValidity)
           
protected  boolean isInputInCache(PipelineContext context, org.orbeon.oxf.processor.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.
protected  boolean isInputInCache(PipelineContext context, String inputName)
           
static boolean isProcessorInputScheme(String uri)
          Check if the given URI is referring to a processor input.
protected  Document readCacheInputAsDOM(PipelineContext context, String inputName)
           
protected  Document readCacheInputAsDOM4J(PipelineContext context, String inputName)
           
protected  Object readCacheInputAsObject(PipelineContext context, org.orbeon.oxf.processor.ProcessorInput input, org.orbeon.oxf.processor.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).
protected  org.orbeon.saxon.om.DocumentInfo readCacheInputAsTinyTree(PipelineContext context, String inputName)
           
protected  Document readInputAsDOM(PipelineContext context, org.orbeon.oxf.processor.ProcessorInput input)
           
protected  Document readInputAsDOM(PipelineContext context, String inputName)
           
protected  Document readInputAsDOM4J(PipelineContext context, org.orbeon.oxf.processor.ProcessorInput input)
           
protected  Document readInputAsDOM4J(PipelineContext context, String inputName)
           
protected static void readInputAsSAX(PipelineContext context, org.orbeon.oxf.processor.ProcessorInput input, ContentHandler contentHandler)
          The fundamental read method based on SAX.
protected  void readInputAsSAX(PipelineContext context, String inputName, ContentHandler contentHandler)
           
protected  org.orbeon.saxon.om.DocumentInfo readInputAsTinyTree(PipelineContext context, org.orbeon.oxf.processor.ProcessorInput input)
           
protected  void removeInputInfo(ProcessorInputOutputInfo inputInfo)
           
protected  void removeOutputInfo(ProcessorInputOutputInfo outputInfo)
           
 void reset(PipelineContext pipelineContext)
          Resets the processor.
 void setId(String id)
           
 void setLocationData(LocationData loc)
           
 void setName(QName name)
           
protected  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

indentedLogger

public static org.orbeon.oxf.util.IndentedLogger indentedLogger

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

KEY_SEPARATOR

public static final char KEY_SEPARATOR
See Also:
Constant Field Values

PROCESSOR_INPUT_SCHEME_OLD

public static final String PROCESSOR_INPUT_SCHEME_OLD
See Also:
Constant Field Values

PROCESSOR_INPUT_SCHEME

public static final String PROCESSOR_INPUT_SCHEME
See Also:
Constant Field Values
Constructor Detail

ProcessorImpl

public ProcessorImpl()
Method Detail

getPropertySet

protected org.orbeon.oxf.properties.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 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(QName name)
Specified by:
setName in interface Processor
Parameters:
name - The new name of this processor
See Also:
Processor.getName()

getInputByName

public org.orbeon.oxf.processor.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 getInputsByName(String name)

createInput

public org.orbeon.oxf.processor.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 name,
                     org.orbeon.oxf.processor.ProcessorInput input)

deleteInput

public void deleteInput(org.orbeon.oxf.processor.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 org.orbeon.oxf.processor.ProcessorOutput getOutputByName(String name)
Specified by:
getOutputByName in interface Processor
Parameters:
name - 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 org.orbeon.oxf.processor.ProcessorOutput createOutput(String name)
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:
name - Name of the output to create. null is allowed.
Returns:
The newly created output

addOutput

public void addOutput(String name,
                      org.orbeon.oxf.processor.ProcessorOutput output)

deleteOutput

public void deleteOutput(org.orbeon.oxf.processor.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)

removeInputInfo

protected void removeInputInfo(ProcessorInputOutputInfo inputInfo)

addOutputInfo

protected void addOutputInfo(ProcessorInputOutputInfo outputInfo)

removeOutputInfo

protected void removeOutputInfo(ProcessorInputOutputInfo outputInfo)

getInputsInfo

public List 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 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 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 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.

getOutputInfo

public ProcessorInputOutputInfo getOutputInfo(String name)

checkSockets

public void checkSockets()

readInputAsSAX

protected static void readInputAsSAX(PipelineContext context,
                                     org.orbeon.oxf.processor.ProcessorInput input,
                                     ContentHandler contentHandler)
The fundamental read method based on SAX.


readInputAsSAX

protected void readInputAsSAX(PipelineContext context,
                              String inputName,
                              ContentHandler contentHandler)

readInputAsDOM

protected Document readInputAsDOM(PipelineContext context,
                                  org.orbeon.oxf.processor.ProcessorInput input)

readInputAsDOM4J

protected Document readInputAsDOM4J(PipelineContext context,
                                    org.orbeon.oxf.processor.ProcessorInput input)

readInputAsTinyTree

protected org.orbeon.saxon.om.DocumentInfo readInputAsTinyTree(PipelineContext context,
                                                               org.orbeon.oxf.processor.ProcessorInput input)

readInputAsDOM

protected Document readInputAsDOM(PipelineContext context,
                                  String inputName)

readInputAsDOM4J

protected Document readInputAsDOM4J(PipelineContext context,
                                    String inputName)

readCacheInputAsDOM

protected Document readCacheInputAsDOM(PipelineContext context,
                                       String inputName)

readCacheInputAsDOM4J

protected Document readCacheInputAsDOM4J(PipelineContext context,
                                         String inputName)

readCacheInputAsTinyTree

protected org.orbeon.saxon.om.DocumentInfo readCacheInputAsTinyTree(PipelineContext context,
                                                                    String inputName)

readCacheInputAsObject

protected Object readCacheInputAsObject(PipelineContext context,
                                        org.orbeon.oxf.processor.ProcessorInput input,
                                        org.orbeon.oxf.processor.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)

getCachedInputAsObject

protected Object getCachedInputAsObject(PipelineContext pipelineContext,
                                        org.orbeon.oxf.processor.ProcessorInput processorInput)

executeChildren

protected void executeChildren(PipelineContext context,
                               Runnable runnable)
For use in processor that contain other processors. Consider the current processor as the parent of the processors on which we call read/start.


executeParents

protected static void executeParents(PipelineContext context,
                                     Runnable runnable)
For use in processor that contain other processors. Consider the current processor as a child or at the same level of the processors on which we call read/start.


getParentState

protected static Object getParentState(PipelineContext context)

getState

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

Parameters:
context - current PipelineContext object
Returns:
state object set by the caller of setState()

setState

protected 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

protected boolean hasState(PipelineContext context)

getProcessorKey

protected 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

protected static org.orbeon.oxf.cache.OutputCacheKey getInputKey(PipelineContext context,
                                                                 org.orbeon.oxf.processor.ProcessorInput input)

getInputValidity

protected static Object getInputValidity(PipelineContext context,
                                         org.orbeon.oxf.processor.ProcessorInput input)

isInputInCache

protected boolean isInputInCache(PipelineContext context,
                                 org.orbeon.oxf.processor.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.


isInputInCache

protected boolean isInputInCache(PipelineContext context,
                                 String inputName)

isInputInCache

protected boolean isInputInCache(PipelineContext context,
                                 ProcessorImpl.KeyValidity keyValidity)

getInputKeyValidity

protected ProcessorImpl.KeyValidity getInputKeyValidity(PipelineContext context,
                                                        org.orbeon.oxf.processor.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

getInputKeyValidity

protected ProcessorImpl.KeyValidity getInputKeyValidity(PipelineContext context,
                                                        String inputName)

getCacheOutputObject

protected Object getCacheOutputObject(PipelineContext pipelineContext,
                                      ProcessorImpl.ProcessorOutputImpl processorOutput,
                                      String keyName,
                                      org.orbeon.oxf.processor.OutputObjectCreator creator)
Cache an object associated with a given processor output.

Parameters:
pipelineContext - current PipelineContext
processorOutput - output to associate with
keyName - key for the object to cache
creator - creator for the object
Returns:
created object if caching was possible, null otherwise

getOutputObject

protected Object getOutputObject(PipelineContext pipelineContext,
                                 ProcessorImpl.ProcessorOutputImpl processorOutput,
                                 String keyName)
Get a cached object associated with a given processor output.

Parameters:
pipelineContext - current PipelineContext
processorOutput - output to associate with
keyName - key for the object to cache
Returns:
cached object if object found, null otherwise

getOutputObject

protected Object getOutputObject(PipelineContext pipelineContext,
                                 ProcessorImpl.ProcessorOutputImpl processorOutput,
                                 String keyName,
                                 ProcessorImpl.KeyValidity outputKeyValidityImpl)

findInputLastModified

protected long findInputLastModified(PipelineContext pipelineContext,
                                     org.orbeon.oxf.processor.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

protected 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