At each stage in a task's life cycle, this class displays information
* to show the internal state of the task and its position with in the project.
* It takes a name
attribute.
name
attribute of this task. */
private String name;
/** The body text of this task. */
private String text;
/**
* The constructor displays the state of the task * as it is instantiated.
*/ public LifeCycleTask() { System.out.println("---------------"); System.out.println("Constructor called"); System.out.println("Value of name attribute: " + name); System.out.println("Value of the body text: " + text); System.out.println("Project: " + getProject()); System.out.println("Location: " + getLocation()); System.out.println("Target: " + getOwningTarget()); System.out.println("---------------"); } /** *Displays the state of the task at initialization.
* @see #logAll(String method) */ public final void init() { logAll("init()"); } /** *Displays the state of the task when Ant runs it. * This method also runs some usage checks * to ensure the task is being used properly.
*/ public final void execute() { if (name == null) { throw new BuildException("You must specify a name attribute in " + getTaskName() + "."); } logAll("execute()"); // Write the name to output log(name, Project.MSG_INFO); } /** *Sets the name to display * and shows the state of the task afterwards.
* @param aName The name to display */ public final void setName(final String aName) { // The value of the name attribute this.name = aName; logAll("setName()"); } /** *Sets the body text of the task * and shows the state of the task afterwards.
* @param bodyText The body text */ public final void addText(final String bodyText) { // If the body text is just whitespace, it might as well be null if (bodyText.trim().equals("")) { this.text = null; } else { this.text = bodyText.trim(); } logAll("addText()"); } /**Checks for task references.
* @return String * A string that tells us details of the reference check */ private String referenceCheck() { // The default setting String setString = "Reference not found."; // We need the references that have been set in this project Hashtable refs = getProject().getReferences(); Enumeration e = refs.elements(); // Let's iterate over them while (e.hasMoreElements()) { // We want to work with each object, so we'll instantiate an object Object obj = e.nextElement(); // Check to see whether this object is a task // If it is, we'll build a string that contains its name and type if (obj.getClass().getName(). equals("org.apache.tools.ant.UnknownElement") || obj.getClass().getName(). equals(this.getClass().getName())) { Task aTask = (Task) obj; setString = "Reference to " + aTask.getTaskName() + " found, of type " + aTask.getClass().getName() + ". "; setString = setString + "Its id is " + aTask.getRuntimeConfigurableWrapper(). getAttributeMap().get("id") + "."; } } return setString; } /** *A central logging method that all the life-cycle methods call
* to display the state of the task.
* It displays the value of the name
attribute
* and other information about the task,
* including the name of its project and its location in the build file.