Top Description Fields Constructors Methods
org.apache.tools.ant

public Class TaskConfigurationChecker

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List

Helper class for the check of the configuration of a given task. This class provides methods for making assumptions about the task configuration. After collecting all violations with assert* and fail methods the checkErrors will throw a BuildException with all collected messages or does nothing if there wasn't any error.

Example:

    public class MyTask extends Task {
        ...
        public void execute() {
            TaskConfigurationChecker checker = TaskConfigurationChecker(this);
            checker.assertConfig(
                srcdir != null,
                "Attribute 'srcdir' must be set.
            );
            checker.assertConfig(
                srcdir.exists(),
                "Srcdir (" + srcdir + ") must exist."
            );
            if (someComplexCondition()) {
                fail("Complex condition failed.");
            }
            checker.checkErrors();
        }
    }
See Also
Notification Pattern

Field Summary

Modifier and TypeField and Description
private List<String>
errors

List of all collected error messages.

private final Task
task

Task for which the configuration should be checked.

Constructor Summary

AccessConstructor and Description
public
TaskConfigurationChecker(Task
which task should be checked
task
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
assertConfig(boolean
which condition to check
condition
,
String
errormessage to throw if a condition failed
errormessage
)

Asserts that a condition is true.

public void
checkErrors()

Checks if there are any collected errors and throws a BuildException with all messages if there was one or more.

public void
fail(String
the message for the registered error
errormessage
)

Registers an error.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorsback to summary
private List<String> errors

List of all collected error messages.

taskback to summary
private final Task task

Task for which the configuration should be checked.

Constructor Detail

TaskConfigurationCheckerback to summary
public TaskConfigurationChecker(Task task)

Constructor.

Parameters
task:Task

which task should be checked

Method Detail

assertConfigback to summary
public void assertConfig(boolean condition, String errormessage)

Asserts that a condition is true.

Parameters
condition:boolean

which condition to check

errormessage:String

errormessage to throw if a condition failed

checkErrorsback to summary
public void checkErrors() throws BuildException

Checks if there are any collected errors and throws a BuildException with all messages if there was one or more.

Exceptions
BuildException:
if one or more errors were registered
failback to summary
public void fail(String errormessage)

Registers an error.

Parameters
errormessage:String

the message for the registered error