Class Switch

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
net.sf.antcontrib.logic.Switch
All Implemented Interfaces:
Cloneable

public class Switch extends org.apache.tools.ant.Task
Task definition for the ANT task to switch on a particular value.

 Usage:

   Task declaration in the project:
   
     <taskdef name="switch" classname="net.sf.antcontrib.logic.Switch" />
   

   Task calling syntax:
    
     <switch value="value" [caseinsensitive="true|false"] >
       <case value="val">
         <property name="propname" value="propvalue" /> |
         <antcall target="targetname" /> |
         any other tasks
       </case>
      [
       <default>
         <property name="propname" value="propvalue" /> |
         <antcall target="targetname" /> |
         any other tasks
       </default> 
      ]
     </switch>
    


   Attributes:
       value           -> The value to switch on
       caseinsensitive -> Should we do case insensitive comparisons?
                          (default is false)

   Subitems:
       case     --> An individual case to consider, if the value that
                    is being switched on matches to value attribute of
                    the case, then the nested tasks will be executed.
       default  --> The default case for when no match is found.

 
 Crude Example:

     
     <switch value="${foo}">
       <case value="bar">
         <echo message="The value of property foo is bar" />
       </case>
       <case value="baz">
         <echo message="The value of property foo is baz" />
       </case>
       <default>
         <echo message="The value of property foo is not sensible" />
       </default>
     </switch>
     

 
Author:
Matthew Inger, Stefan Bodewig
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    final class 
     
  • Field Summary

    Fields inherited from class org.apache.tools.ant.Task

    target, taskName, taskType, wrapper

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addDefault(org.apache.tools.ant.taskdefs.Sequential res)
    Creates the <default> tag
    Creates the <case> tag
    void
     
    void
    setCaseInsensitive(boolean c)
     
    void
    Sets the value being switched on

    Methods inherited from class org.apache.tools.ant.Task

    bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Switch

      public Switch()
      Default Constructor
  • Method Details

    • execute

      public void execute() throws org.apache.tools.ant.BuildException
      Overrides:
      execute in class org.apache.tools.ant.Task
      Throws:
      org.apache.tools.ant.BuildException
    • setValue

      public void setValue(String value)
      Sets the value being switched on
    • setCaseInsensitive

      public void setCaseInsensitive(boolean c)
    • createCase

      public Switch.Case createCase() throws org.apache.tools.ant.BuildException
      Creates the <case> tag
      Throws:
      org.apache.tools.ant.BuildException
    • addDefault

      public void addDefault(org.apache.tools.ant.taskdefs.Sequential res) throws org.apache.tools.ant.BuildException
      Creates the <default> tag
      Throws:
      org.apache.tools.ant.BuildException