uk.org.ogsadai.activity
Class ActivityBase

java.lang.Object
  extended by uk.org.ogsadai.activity.ActivityBase
All Implemented Interfaces:
Activity
Direct Known Subclasses:
ActivityInputListenerActivity, ActivityUserErrorProducerActivity, BlockCountActivity, CloneableObjectProducerActivity, CreateResourceActivityBase, DeliverToNullActivity, DeliverToRequestStatusActivity, EndIfActivity, GetAvailableTablesActivity, GetAvailableTablesActivity, HeadActivity, IfEmptyListActivity, IterativeActivity, MatchedIterativeActivity, MatchedIterativeMultipleInputActivity, MatchedNestedIterativeActivity, ReadStringActivity, TimestampActivity, ToSingleListActivity, TupleUnionAllActivity

public abstract class ActivityBase
extends java.lang.Object
implements Activity

An abstract activity base class that provides access to input and output pipes, activity contracts and simple validation functionality. This functionality is common to most activity implementations, however a concrete activity will not normally extend this class directly. Instead a concrete class will typically extend one of the direct sub-classes of this class.

Author:
The OGSA-DAI Project Team.

Field Summary
protected  java.util.Set mContracts
          Set of contracts satisfied by the activity.
 
Constructor Summary
ActivityBase()
           
 
Method Summary
 void addInput(java.lang.String name, BlockReader input)
          Adds an input to the activity.
 void addOutput(java.lang.String name, BlockWriter output)
          Adds an output to the activity.
protected  void close()
          Closes all of the inputs and outputs of the activity.
protected  void closeDueToError()
          Closes all inputs and outputs of the activity due to an error.
 java.util.Set getActivityContracts()
          Gets the set of the contracts satisfied by the activity.
 ActivityDescriptor getActivityDescriptor()
          Gets a description of the activity instance.
protected  BlockReader getInput()
          Gets the input for an activity that has only one input.
protected  BlockReader getInput(java.lang.String name)
          Gets the first activity input with the specified name.
protected  java.util.List getInputs(java.lang.String name)
          Gets the activity inputs with the specified name.
protected  BlockWriter getOutput()
          Gets the output for an activity that has only one output.
protected  BlockWriter getOutput(java.lang.String name)
          Gets the first activity output with the specified name.
protected  java.util.List getOutputs(java.lang.String name)
          Gets the activity outputs with the specified name.
protected  boolean hasInput(java.lang.String name)
          Checks that an activity input exists with the specified input name.
protected  boolean hasOutput(java.lang.String name)
          Checks that an activity output exists with the specified output name.
protected  void removeInput(java.lang.String name, BlockReader reader)
          Removes the given block reader with the specified name from the activity's inputs.
 void setActivityDescriptor(ActivityDescriptor descriptor)
          Sets the activity descriptor for the activity instance.
 java.lang.String toString()
          Returns a string description of the activity.
protected  void validateInput(java.lang.String name)
          Validates the activity inputs by checking that an input exists with the specified input name.
protected  void validateInputs(java.lang.String name, int number)
          Validates the activity inputs by checking that a specified number of inputs exist with the specified input name.
protected  void validateOutput(java.lang.String name)
          Validates the activity outputs by checking that an output exists with the specified output name.
protected  void validateOutputs(java.lang.String name, int number)
          Validates the activity outputs by checking that a specified number of outputs exist with the specified output name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface uk.org.ogsadai.activity.Activity
process
 

Field Detail

mContracts

protected final java.util.Set mContracts
Set of contracts satisfied by the activity.

Constructor Detail

ActivityBase

public ActivityBase()
Method Detail

toString

public java.lang.String toString()
Returns a string description of the activity. This takes the form of: where NAME is the name of the activity, INSTANCE is the instance name for the activity, and TYPE is the activity class name.

Overrides:
toString in class java.lang.Object

getActivityContracts

public java.util.Set getActivityContracts()
Description copied from interface: Activity
Gets the set of the contracts satisfied by the activity. An activity contract associates an activity with some well-defined semantics. There are Client Toolkit activity classes that understand particular contracts, so these can be used to operate any activity satisfying the correct contract.

Specified by:
getActivityContracts in interface Activity
Returns:
set of contract name strings or an empty set if the activity does not satisfy any particular contracts.

setActivityDescriptor

public void setActivityDescriptor(ActivityDescriptor descriptor)
Description copied from interface: Activity
Sets the activity descriptor for the activity instance.

Specified by:
setActivityDescriptor in interface Activity
Parameters:
descriptor - Description of the activity instance.

getActivityDescriptor

public ActivityDescriptor getActivityDescriptor()
Description copied from interface: Activity
Gets a description of the activity instance.

Specified by:
getActivityDescriptor in interface Activity
Returns:
activity descriptor

addInput

public void addInput(java.lang.String name,
                     BlockReader input)
Description copied from interface: Activity
Adds an input to the activity.

Specified by:
addInput in interface Activity
Parameters:
name - Name of the activity input.
input - Block reader for reading the input data from.

removeInput

protected void removeInput(java.lang.String name,
                           BlockReader reader)
Removes the given block reader with the specified name from the activity's inputs.

Parameters:
name - name of the input
reader - the block reader to remove

addOutput

public void addOutput(java.lang.String name,
                      BlockWriter output)
Description copied from interface: Activity
Adds an output to the activity.

Specified by:
addOutput in interface Activity
Parameters:
name - Name of the activity output.
output - Block writer for writing the output data to.

getInput

protected BlockReader getInput()
Gets the input for an activity that has only one input. The behaviour of this method is unspecified for activities with more than one input.

Returns:
input block reader

getInput

protected BlockReader getInput(java.lang.String name)
Gets the first activity input with the specified name.

Parameters:
name - name of input
Returns:
activity input block reader or null if there is no input with the specified name

getInputs

protected java.util.List getInputs(java.lang.String name)
Gets the activity inputs with the specified name.

Parameters:
name - name of inputs
Returns:
a set of activity input block readers or an empty set (immutable) if there are no inputs

getOutput

protected BlockWriter getOutput()
Gets the output for an activity that has only one output. The behaviour of this method is unspecified for activities with more than one output.

Returns:
input block reader

getOutput

protected BlockWriter getOutput(java.lang.String name)
Gets the first activity output with the specified name.

Parameters:
name - name of output
Returns:
activity output block reader, or null if there is no output with the specified name.

getOutputs

protected java.util.List getOutputs(java.lang.String name)
Gets the activity outputs with the specified name.

Parameters:
name - name of outputs
Returns:
a set of activity output block writers or an empty set (immutable) if there are no outputs

validateInput

protected void validateInput(java.lang.String name)
                      throws InvalidActivityInputsException
Validates the activity inputs by checking that an input exists with the specified input name.

Parameters:
name - required input name
Throws:
InvalidActivityInputsException - if an input with the specified name does not exist

validateInputs

protected void validateInputs(java.lang.String name,
                              int number)
                       throws InvalidActivityInputsException
Validates the activity inputs by checking that a specified number of inputs exist with the specified input name.

Parameters:
name - required input name
number - number of inputs
Throws:
InvalidActivityInputsException - if the expected number of inputs with the specified name do not exist

validateOutput

protected void validateOutput(java.lang.String name)
                       throws InvalidActivityOutputsException
Validates the activity outputs by checking that an output exists with the specified output name.

Parameters:
name - required output name
Throws:
InvalidActivityOutputsException - if an output with the specified name does not exist

validateOutputs

protected void validateOutputs(java.lang.String name,
                               int number)
                        throws InvalidActivityOutputsException
Validates the activity outputs by checking that a specified number of outputs exist with the specified output name.

Parameters:
name - required output name
number - number of outputs
Throws:
InvalidActivityOutputsException - if the expected number of outputs with the specified name do not exist

hasInput

protected boolean hasInput(java.lang.String name)
Checks that an activity input exists with the specified input name.

Parameters:
name - input name
Returns:
true if so and false otherwise.

hasOutput

protected boolean hasOutput(java.lang.String name)
Checks that an activity output exists with the specified output name.

Parameters:
name - output name
Returns:
true if so and false otherwise.

close

protected void close()
Closes all of the inputs and outputs of the activity.


closeDueToError

protected void closeDueToError()
Closes all inputs and outputs of the activity due to an error.