org.schmant.task.stub
Class AbstractActionTask<T extends ActionTaskSpec<T>>

java.lang.Object
  extended by org.schmant.support.AbstractArgumentChecker
      extended by org.schmant.task.stub.AbstractTask<T>
          extended by org.schmant.task.stub.AbstractActionTask<T>
All Implemented Interfaces:
TaskDependency, ActionTaskConfigurable<T>, ActionTaskSpec<T>, LoggingConfigurable<T>, SourceConfigurable<T>, SourceConfigured, Task, TaskRunnable, TaskSpecification<T>
Direct Known Subclasses:
AbstractCallbackRecursiveActionTask, AbstractJavadocTask, AbstractParseXmlTask, AbstractProcessTask, AbstractXmlCatalogActionTask, ChmodTask, DeleteTask, ForEachSourceTask, HtmlLinkValidationTask, ReplaceSourceFileTask, TemplateCompilerTask, TreeDeleteTask

public abstract class AbstractActionTask<T extends ActionTaskSpec<T>>
extends AbstractTask<T>
implements ActionTaskSpec<T>

This class may be used as a starting point for action task implementations.

Since:
0.5
Author:
Karl Gustafsson

Constructor Summary
AbstractActionTask()
           
 
Method Summary
 T addSource(Object o)
          Add one or several sources.
 T addSources(Object o)
          This method does the same as SourceConfigurable.addSource(Object)
 T clearSources()
          Clear the collection of sources.
 void copyProperties(T spec)
          Override the implementation from AbstractTask to copy the source properties.
protected  RelativeLocation getRelativeToBase()
           
 Object getSource()
          Get the source object when there is only one source set.
 List<Object> getSources()
          Get the sources set on this action task.
protected  boolean isMoreThanOneSourceAllowed()
          Is more than one source object allowed? This method returns false .
protected  boolean isSourcesMandatory()
          Must the sources property be set? This method returns true.
 T setRelativeToBase(RelativeLocation rel)
          This property is set with the task's source's location relative to a base location if the task is run within a recursive task.
 T setSource(Object o)
          Set one or several sources, discarding previously set sources.
 T setSources(Object o)
          This method does the same as SourceConfigurable.setSource(Object)
 String toString()
          Default implementation for tasks.
protected  Collection<String> validate(Report r)
          Override the method inherited from AbstractTask to give a validation error if no source is set (and isSourcesMandatory() is true).
 
Methods inherited from class org.schmant.task.stub.AbstractTask
cancel, createTask, getDefaultLogFooter, getDefaultLogHeader, getDependencyForTasksScheduledByThisTask, getDependencyObservable, getFailureCause, getLogFooter, getLogHeader, getSatisfiedStateLock, getThis, isCancelled, isDone, isInterrupted, isRunning, isSatisfied, isSuccessful, run, runInternal, setLogFooter, setLogHeader, setReportLevel, setTraceLogging
 
Methods inherited from class org.schmant.support.AbstractArgumentChecker
check, check, check, check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.schmant.task.TaskSpecification
createTask
 
Methods inherited from interface org.schmant.task.confable.LoggingConfigurable
setLogFooter, setLogHeader, setReportLevel, setTraceLogging
 

Constructor Detail

AbstractActionTask

public AbstractActionTask()
Method Detail

setSource

public final T setSource(Object o)
Description copied from interface: SourceConfigurable
Set one or several sources, discarding previously set sources.

Specified by:
setSource in interface SourceConfigurable<T extends ActionTaskSpec<T>>
Parameters:
o - The source. If this is a Collection or an array, it is flattened (see FlatteningList), and all objects in the collection or array are set.
Returns:
this

setSources

public final T setSources(Object o)
Description copied from interface: SourceConfigurable
This method does the same as SourceConfigurable.setSource(Object)

Specified by:
setSources in interface SourceConfigurable<T extends ActionTaskSpec<T>>
Parameters:
o - The source or sources.
Returns:
this

addSource

public final T addSource(Object o)
Description copied from interface: SourceConfigurable
Add one or several sources.

Specified by:
addSource in interface SourceConfigurable<T extends ActionTaskSpec<T>>
Parameters:
o - The source. If this is a Collection or an array, it is flattened (see FlatteningList), and all sources in the collection or array are added.
Returns:
this

addSources

public final T addSources(Object o)
Description copied from interface: SourceConfigurable
This method does the same as SourceConfigurable.addSource(Object)

Specified by:
addSources in interface SourceConfigurable<T extends ActionTaskSpec<T>>
Parameters:
o - The source or sources.
Returns:
this

clearSources

public final T clearSources()
Description copied from interface: SourceConfigurable
Clear the collection of sources.

Specified by:
clearSources in interface SourceConfigurable<T extends ActionTaskSpec<T>>
Returns:
this.

getSources

public List<Object> getSources()
Get the sources set on this action task.

Subclasses may override this method to add sources that are set via other properties.

Specified by:
getSources in interface SourceConfigured
Returns:
The sources.

getSource

public Object getSource()
Get the source object when there is only one source set. This method should only be used for tasks whose isMoreThanOneSourceAllowed() method returns false.

Specified by:
getSource in interface SourceConfigured
Returns:
The single source object, or null if no source is set.

setRelativeToBase

public final T setRelativeToBase(RelativeLocation rel)
Description copied from interface: SourceConfigurable
This property is set with the task's source's location relative to a base location if the task is run within a recursive task. The base location is the location of the source of the recursive task.

If the SourceConfigurable (this object) is an action task factory that is used in a recursive action task, the recursive action task sets this property for each created task.

Specified by:
setRelativeToBase in interface SourceConfigurable<T extends ActionTaskSpec<T>>
Parameters:
rel - The source's location relative to the base location.
Returns:
this

getRelativeToBase

protected final RelativeLocation getRelativeToBase()

isSourcesMandatory

protected boolean isSourcesMandatory()
Must the sources property be set? This method returns true. Subclasses may override this method to return false if the sources property is not mandatory.

Returns:
true, always.

isMoreThanOneSourceAllowed

protected boolean isMoreThanOneSourceAllowed()
Is more than one source object allowed? This method returns false . Subclasses override this method to return true if they allow several sources.

This method will only be called if isSourcesMandatory() returns true.

Returns:
false, always

validate

protected Collection<String> validate(Report r)
Override the method inherited from AbstractTask to give a validation error if no source is set (and isSourcesMandatory() is true).

Subclasses may override this to add their own validations.

Overrides:
validate in class AbstractTask<T extends ActionTaskSpec<T>>
Parameters:
r - A report to log warning and debug messages to. Validation errors should not be logged, though. They are logged later.
Returns:
A collection of error messages.

toString

public String toString()
Description copied from class: AbstractTask
Default implementation for tasks. Task implementations may override this. It is used in the default log header that is written (level INFO) before a task is run.

This implementation just returns the class name.

Overrides:
toString in class AbstractTask<T extends ActionTaskSpec<T>>

copyProperties

public void copyProperties(T spec)
Override the implementation from AbstractTask to copy the source properties. Subclasses must override this to copy their own properties.

Specified by:
copyProperties in interface TaskSpecification<T extends ActionTaskSpec<T>>
Overrides:
copyProperties in class AbstractTask<T extends ActionTaskSpec<T>>
Parameters:
spec - The specification to copy properties to.