com.exoftware.exactor
Class Command

java.lang.Object
  extended byjunit.framework.Assert
      extended bycom.exoftware.exactor.Command
Direct Known Subclasses:
AbstractSwtCommand, WebCommand

public class Command
extends junit.framework.Assert

Base class for all commands executed by the framework. The class provides access to the parameters of the command and the script which contains the command. The class extends junit.framework.Assert so all the assert methods are available for use.

Subclasses must implement the execute method. If the command is responsible for performing a check then the execute method should throw an AssertionFailedError in the event that the check was unsuccessful, e.g.

 
     public void execute() throws Exception
     {
         if( !"hello".equals( "goodbye" ) )
             throw new AssertionFailedError( "Values not equal" );
     }
 
 
or using the convenience method,
 
     public void execute() throws Exception
     {
         assertEquals( "hello", "goodbye" );
     }
 
 

Author:
Brian Swan

Constructor Summary
Command()
           
 
Method Summary
 void addParameter(Parameter p)
          Add a parameter to the command.
 int countParameters()
          Returns the number of parameters added to the command.
 void execute()
          Subclasses should implement this method to perform the actions of their command.
 int getLineNumber()
          Returns the number of the line in the script where this command is defined.
 java.lang.String getName()
          Returns the command name for this command.
 Parameter getParameter(int index)
          Returns the parameter at the specified index.
 Parameter getParameter(int index, java.lang.String defaultValue)
          Returns the parameter at the specified index.
 Parameter[] getParameters()
          Returns all the parameters in this command.
 Script getScript()
          Returns the script that owns this command.
 boolean hasParameters()
          Check whether the command has any parameters.
 java.lang.String parametersAsString()
          Return all parameters as single string for display purposes.
 java.lang.String resolveFileRelativeToScriptFile(java.lang.String fileName)
          Resolves a filename relative to actual file used to create the script file.
 void setLineNumber(int lineNumber)
          set the line number of the command in the script.
 void setName(java.lang.String name)
          Set the name of the command.
 void setScript(Script s)
          Set the owning script for this command.
 void substituteParameters(Parameter[] substitutions)
          Substitute the supplied parameters for any placeholder parameters in the command.
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

public Command()
Method Detail

addParameter

public void addParameter(Parameter p)
                  throws java.lang.NullPointerException
Add a parameter to the command.

Parameters:
p - the parameter to add.
Throws:
java.lang.NullPointerException - if the supplied parameter is null.

hasParameters

public boolean hasParameters()
Check whether the command has any parameters.

Returns:
true if the command has parameters, otherwise false.

countParameters

public int countParameters()
Returns the number of parameters added to the command.

Returns:
the number of parameters added to the command.

getParameter

public Parameter getParameter(int index)
                       throws java.lang.IndexOutOfBoundsException
Returns the parameter at the specified index.

Parameters:
index - the index of the parameter to return.
Returns:
the parameter at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if the command has no parameters, or if the index is out of range (index < 0 || index >= countParameters()).

getParameter

public Parameter getParameter(int index,
                              java.lang.String defaultValue)
Returns the parameter at the specified index.

Parameters:
index - the index of the parameter to return.
Returns:
the parameter at the specified index. If not present returns new Parameter(defaultValue);

getParameters

public Parameter[] getParameters()
Returns all the parameters in this command.

Returns:
all the parameters in this command.

getScript

public Script getScript()
Returns the script that owns this command.

Returns:
the script that owns this command.

setScript

public void setScript(Script s)
               throws java.lang.NullPointerException
Set the owning script for this command.

Parameters:
s - the script that owns this command.
Throws:
java.lang.NullPointerException - if the supplied script is null.

execute

public void execute()
             throws java.lang.Exception
Subclasses should implement this method to perform the actions of their command. If the command is responsible for performing a check then a AssertionFailedError should be thrown in the event that the check fails. By default this method fails with a "Not implemented" message.

Throws:
java.lang.Exception - if an error occurs.
See Also:
AssertionFailedError

getLineNumber

public int getLineNumber()
Returns the number of the line in the script where this command is defined.

Returns:
the line number of the command in the script.

setLineNumber

public void setLineNumber(int lineNumber)
set the line number of the command in the script.

Parameters:
lineNumber - the line number of this command.

getName

public java.lang.String getName()
Returns the command name for this command.

Returns:
the command name for this command.

setName

public void setName(java.lang.String name)
Set the name of the command.

Parameters:
name - the name of the command.

substituteParameters

public void substituteParameters(Parameter[] substitutions)
                          throws java.lang.RuntimeException
Substitute the supplied parameters for any placeholder parameters in the command. A placeholder parameter is a parameter with a value of the format $n, where n is the index into the supplied substitutions array. If n is not a valid index into the substitutions array then the parameter is left unchanged.

Parameters:
substitutions - the array of parameters to use for substitutions.
Throws:
java.lang.RuntimeException

parametersAsString

public java.lang.String parametersAsString()
Return all parameters as single string for display purposes. Also does any required substitution.

Returns:
all parametes as a string

resolveFileRelativeToScriptFile

public java.lang.String resolveFileRelativeToScriptFile(java.lang.String fileName)
Resolves a filename relative to actual file used to create the script file. Recognizes a files as been relative if it begins with a '.'.

Parameters:
fileName - to be resolved
Returns:
resolved file name