com.sun.slamd.scripting.general
Class StringVariable

java.lang.Object
  extended bycom.sun.slamd.scripting.engine.Variable
      extended bycom.sun.slamd.scripting.general.StringVariable
All Implemented Interfaces:
Argument

public class StringVariable
extends Variable

This class defines a string variable that has an string value. It also defines a set of methods for dealing with string variables:


Field Summary
static java.lang.String APPEND_METHOD_NAME
          The name of the method that will be used to append strings together.
static int APPEND_METHOD_NUMBER
          The method number for the "append" method.
static int ASSIGN_1_METHOD_NUMBER
          The method number for the first "assign" method.
static int ASSIGN_2_METHOD_NUMBER
          The method number for the second "assign" method.
static java.lang.String ASSIGN_METHOD_NAME
          The name of the method that will be used to assign a value to the variable.
static java.lang.String COMPARE_TO_METHOD_NAME
          The name of the method that will perform lexicographical comparisons of strings.
static int COMPARE_TO_METHOD_NUMBER
          The method number for the "compareTo" method.
static java.lang.String CONTAINS_METHOD_NAME
          The name of the method that will determine whether this string contains a specified substring.
static int CONTAINS_METHOD_NUMBER
          The method number for the "contains" method.
static java.lang.String ENDS_WITH_METHOD_NAME
          The name of the method that will determine whether this string ends with a specified substring.
static int ENDS_WITH_METHOD_NUMBER
          The method number for the "endsWith" method.
static java.lang.String EQUALS_METHOD_NAME
          The name of the method that will determine whether two strings are equal.
static int EQUALS_METHOD_NUMBER
          The method number for the "equals" method.
static int INDEX_OF_1_METHOD_NUMBER
          The method number for the first "indexOf" method.
static int INDEX_OF_2_METHOD_NUMBER
          The method number for the second "indexOf" method.
static java.lang.String INDEX_OF_METHOD_NAME
          The name of the method that may be used to determine the position of a specified substring.
static java.lang.String IS_NULL_METHOD_NAME
          The name of the method that will determine whether this string has not been assigned a value.
static int IS_NULL_METHOD_NUMBER
          The method number for the isNull method.
static int LAST_INDEX_OF_1_METHOD_NUMBER
          The method number for the first "lastIndexOf" method.
static int LAST_INDEX_OF_2_METHOD_NUMBER
          The method number for the second "lastIndexOf" method.
static java.lang.String LAST_INDEX_OF_METHOD_NAME
          The name of the method that may be used to determine the position of the last occurrence of a specified substring.
static java.lang.String LENGTH_METHOD_NAME
          The name of the method that will determine the length of this string.
static int LENGTH_METHOD_NUMBER
          The method number for the "length" method.
static java.lang.String NOT_NULL_METHOD_NAME
          The name of the method that will determine whether this string has been assigned a value.
static int NOT_NULL_METHOD_NUMBER
          The method number for the "notNull" method.
static java.lang.String SPLIT_AT_METHOD_NAME
          The name of the method that will be used to split this string at a specified delimiter.
static int SPLIT_AT_METHOD_NUMBER
          The method number for the "splitAt" method.
static java.lang.String SPLIT_AT_TABS_METHOD_NAME
          The name of the method that will be used to split this string at tab characters.
static int SPLIT_AT_TABS_METHOD_NUMBER
          The method number for the "splitAtTabs" method.
static java.lang.String STARTS_WITH_METHOD_NAME
          The name of the method that will determine whether this string starts with a specified substring.
static int STARTS_WITH_METHOD_NUMBER
          The method number for the "startsWith" method.
static Method[] STRING_VARIABLE_METHODS
          The set of methods associated with string variables.
static java.lang.String STRING_VARIABLE_TYPE
          The name that will be used for the data type of string variables.
static int SUBSTRING_1_METHOD_NUMBER
          The method number for the first "substring" method.
static int SUBSTRING_2_METHOD_NUMBER
          The method number for the first "second" method.
static java.lang.String SUBSTRING_METHOD_NAME
          The name of the method that will retrieve a substring of the overall string value.
static java.lang.String TO_LOWERCASE_METHOD_NAME
          The name of the method that will convert the string to all lowercase.
static int TO_LOWERCASE_METHOD_NUMBER
          The method number for the "toLowerCase" method.
static java.lang.String TO_UPPERCASE_METHOD_NAME
          The name of the method that will convert the string to all uppercase.
static int TO_UPPERCASE_METHOD_NUMBER
          The method number for the "toUpperCase" method.
 
Constructor Summary
StringVariable()
          Creates a new variable with no name, to be used only when creating a variable with Class.newInstance(), and only when setName() is called after that to set the name.
StringVariable(java.lang.String stringValue)
          Creates a new string variable with the provided value.
 
Method Summary
 void assign(Argument argument)
          Assigns the value of the provided argument to this variable.
 Variable executeMethod(int lineNumber, int methodNumber, Argument[] arguments)
          Executes the specified method, using the provided variables as arguments to the method, and makes the return value available to the caller.
 int getMethodNumber(java.lang.String methodName, java.lang.String[] argumentTypes)
          Retrieves the method number for the method that has the specified name and argument types, or -1 if there is no such method.
 Method[] getMethods()
          Retrieves a list of all methods defined for this variable.
 java.lang.String getReturnTypeForMethod(java.lang.String methodName, java.lang.String[] argumentTypes)
          Retrieves the return type for the method with the specified name and argument types.
 java.lang.String getStringValue()
          Retrieves the string value associated with this variable.
 java.lang.String getValueAsString()
          Retrieves a string representation of the value of this argument.
 java.lang.String getVariableTypeName()
          Retrieves the name of the variable type for this variable.
 boolean hasMethod(java.lang.String methodName)
          Indicates whether this variable type has a method with the specified name.
 void setStringValue(java.lang.String stringValue)
          Specifies the string value for this variable.
 java.lang.String toLowerCase()
          Retrieves the string value associated with this variable, converted to lowercase.
 
Methods inherited from class com.sun.slamd.scripting.engine.Variable
getArgumentAsString, getArgumentType, getArgumentValue, getName, getStatTrackers, isValidIdentifier, setName, startStatTrackers, stopStatTrackers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRING_VARIABLE_TYPE

public static final java.lang.String STRING_VARIABLE_TYPE
The name that will be used for the data type of string variables.

See Also:
Constant Field Values

APPEND_METHOD_NAME

public static final java.lang.String APPEND_METHOD_NAME
The name of the method that will be used to append strings together.

See Also:
Constant Field Values

APPEND_METHOD_NUMBER

public static final int APPEND_METHOD_NUMBER
The method number for the "append" method.

See Also:
Constant Field Values

ASSIGN_METHOD_NAME

public static final java.lang.String ASSIGN_METHOD_NAME
The name of the method that will be used to assign a value to the variable.

See Also:
Constant Field Values

ASSIGN_1_METHOD_NUMBER

public static final int ASSIGN_1_METHOD_NUMBER
The method number for the first "assign" method.

See Also:
Constant Field Values

ASSIGN_2_METHOD_NUMBER

public static final int ASSIGN_2_METHOD_NUMBER
The method number for the second "assign" method.

See Also:
Constant Field Values

COMPARE_TO_METHOD_NAME

public static final java.lang.String COMPARE_TO_METHOD_NAME
The name of the method that will perform lexicographical comparisons of strings.

See Also:
Constant Field Values

COMPARE_TO_METHOD_NUMBER

public static final int COMPARE_TO_METHOD_NUMBER
The method number for the "compareTo" method.

See Also:
Constant Field Values

CONTAINS_METHOD_NAME

public static final java.lang.String CONTAINS_METHOD_NAME
The name of the method that will determine whether this string contains a specified substring.

See Also:
Constant Field Values

CONTAINS_METHOD_NUMBER

public static final int CONTAINS_METHOD_NUMBER
The method number for the "contains" method.

See Also:
Constant Field Values

ENDS_WITH_METHOD_NAME

public static final java.lang.String ENDS_WITH_METHOD_NAME
The name of the method that will determine whether this string ends with a specified substring.

See Also:
Constant Field Values

ENDS_WITH_METHOD_NUMBER

public static final int ENDS_WITH_METHOD_NUMBER
The method number for the "endsWith" method.

See Also:
Constant Field Values

EQUALS_METHOD_NAME

public static final java.lang.String EQUALS_METHOD_NAME
The name of the method that will determine whether two strings are equal. specified substring.

See Also:
Constant Field Values

EQUALS_METHOD_NUMBER

public static final int EQUALS_METHOD_NUMBER
The method number for the "equals" method.

See Also:
Constant Field Values

INDEX_OF_METHOD_NAME

public static final java.lang.String INDEX_OF_METHOD_NAME
The name of the method that may be used to determine the position of a specified substring.

See Also:
Constant Field Values

INDEX_OF_1_METHOD_NUMBER

public static final int INDEX_OF_1_METHOD_NUMBER
The method number for the first "indexOf" method.

See Also:
Constant Field Values

INDEX_OF_2_METHOD_NUMBER

public static final int INDEX_OF_2_METHOD_NUMBER
The method number for the second "indexOf" method.

See Also:
Constant Field Values

IS_NULL_METHOD_NAME

public static final java.lang.String IS_NULL_METHOD_NAME
The name of the method that will determine whether this string has not been assigned a value.

See Also:
Constant Field Values

IS_NULL_METHOD_NUMBER

public static final int IS_NULL_METHOD_NUMBER
The method number for the isNull method.

See Also:
Constant Field Values

LAST_INDEX_OF_METHOD_NAME

public static final java.lang.String LAST_INDEX_OF_METHOD_NAME
The name of the method that may be used to determine the position of the last occurrence of a specified substring.

See Also:
Constant Field Values

LAST_INDEX_OF_1_METHOD_NUMBER

public static final int LAST_INDEX_OF_1_METHOD_NUMBER
The method number for the first "lastIndexOf" method.

See Also:
Constant Field Values

LAST_INDEX_OF_2_METHOD_NUMBER

public static final int LAST_INDEX_OF_2_METHOD_NUMBER
The method number for the second "lastIndexOf" method.

See Also:
Constant Field Values

LENGTH_METHOD_NAME

public static final java.lang.String LENGTH_METHOD_NAME
The name of the method that will determine the length of this string.

See Also:
Constant Field Values

LENGTH_METHOD_NUMBER

public static final int LENGTH_METHOD_NUMBER
The method number for the "length" method.

See Also:
Constant Field Values

NOT_NULL_METHOD_NAME

public static final java.lang.String NOT_NULL_METHOD_NAME
The name of the method that will determine whether this string has been assigned a value.

See Also:
Constant Field Values

NOT_NULL_METHOD_NUMBER

public static final int NOT_NULL_METHOD_NUMBER
The method number for the "notNull" method.

See Also:
Constant Field Values

SPLIT_AT_METHOD_NAME

public static final java.lang.String SPLIT_AT_METHOD_NAME
The name of the method that will be used to split this string at a specified delimiter.

See Also:
Constant Field Values

SPLIT_AT_METHOD_NUMBER

public static final int SPLIT_AT_METHOD_NUMBER
The method number for the "splitAt" method.

See Also:
Constant Field Values

SPLIT_AT_TABS_METHOD_NAME

public static final java.lang.String SPLIT_AT_TABS_METHOD_NAME
The name of the method that will be used to split this string at tab characters.

See Also:
Constant Field Values

SPLIT_AT_TABS_METHOD_NUMBER

public static final int SPLIT_AT_TABS_METHOD_NUMBER
The method number for the "splitAtTabs" method.

See Also:
Constant Field Values

STARTS_WITH_METHOD_NAME

public static final java.lang.String STARTS_WITH_METHOD_NAME
The name of the method that will determine whether this string starts with a specified substring.

See Also:
Constant Field Values

STARTS_WITH_METHOD_NUMBER

public static final int STARTS_WITH_METHOD_NUMBER
The method number for the "startsWith" method.

See Also:
Constant Field Values

SUBSTRING_METHOD_NAME

public static final java.lang.String SUBSTRING_METHOD_NAME
The name of the method that will retrieve a substring of the overall string value.

See Also:
Constant Field Values

SUBSTRING_1_METHOD_NUMBER

public static final int SUBSTRING_1_METHOD_NUMBER
The method number for the first "substring" method.

See Also:
Constant Field Values

SUBSTRING_2_METHOD_NUMBER

public static final int SUBSTRING_2_METHOD_NUMBER
The method number for the first "second" method.

See Also:
Constant Field Values

TO_LOWERCASE_METHOD_NAME

public static final java.lang.String TO_LOWERCASE_METHOD_NAME
The name of the method that will convert the string to all lowercase.

See Also:
Constant Field Values

TO_LOWERCASE_METHOD_NUMBER

public static final int TO_LOWERCASE_METHOD_NUMBER
The method number for the "toLowerCase" method.

See Also:
Constant Field Values

TO_UPPERCASE_METHOD_NAME

public static final java.lang.String TO_UPPERCASE_METHOD_NAME
The name of the method that will convert the string to all uppercase.

See Also:
Constant Field Values

TO_UPPERCASE_METHOD_NUMBER

public static final int TO_UPPERCASE_METHOD_NUMBER
The method number for the "toUpperCase" method.

See Also:
Constant Field Values

STRING_VARIABLE_METHODS

public static final Method[] STRING_VARIABLE_METHODS
The set of methods associated with string variables.

Constructor Detail

StringVariable

public StringVariable()
               throws ScriptException
Creates a new variable with no name, to be used only when creating a variable with Class.newInstance(), and only when setName() is called after that to set the name.

Throws:
ScriptException - If a problem occurs while initializing the new variable.

StringVariable

public StringVariable(java.lang.String stringValue)
Creates a new string variable with the provided value.

Parameters:
stringValue - The value to use for this String variable.
Method Detail

getStringValue

public java.lang.String getStringValue()
Retrieves the string value associated with this variable.

Returns:
The string value associated with this variable.

toLowerCase

public java.lang.String toLowerCase()
Retrieves the string value associated with this variable, converted to lowercase.

Returns:
The string value associated with this variable in lowercase form.

setStringValue

public void setStringValue(java.lang.String stringValue)
Specifies the string value for this variable.

Parameters:
stringValue - The string value for this variable.

getVariableTypeName

public java.lang.String getVariableTypeName()
Retrieves the name of the variable type for this variable.

Specified by:
getVariableTypeName in class Variable
Returns:
The name of the variable type for this variable.

getMethods

public Method[] getMethods()
Retrieves a list of all methods defined for this variable.

Specified by:
getMethods in class Variable
Returns:
A list of all methods defined for this variable.

hasMethod

public boolean hasMethod(java.lang.String methodName)
Indicates whether this variable type has a method with the specified name.

Specified by:
hasMethod in class Variable
Parameters:
methodName - The name of the method.
Returns:
true if this variable has a method with the specified name, or false if it does not.

getMethodNumber

public int getMethodNumber(java.lang.String methodName,
                           java.lang.String[] argumentTypes)
Retrieves the method number for the method that has the specified name and argument types, or -1 if there is no such method.

Specified by:
getMethodNumber in class Variable
Parameters:
methodName - The name of the method.
argumentTypes - The list of argument types for the method.
Returns:
The method number for the method that has the specified name and argument types.

getReturnTypeForMethod

public java.lang.String getReturnTypeForMethod(java.lang.String methodName,
                                               java.lang.String[] argumentTypes)
Retrieves the return type for the method with the specified name and argument types.

Specified by:
getReturnTypeForMethod in class Variable
Parameters:
methodName - The name of the method.
argumentTypes - The set of argument types for the method.
Returns:
The return type for the method, or null if there is no such method defined.

executeMethod

public Variable executeMethod(int lineNumber,
                              int methodNumber,
                              Argument[] arguments)
                       throws ScriptException
Executes the specified method, using the provided variables as arguments to the method, and makes the return value available to the caller.

Specified by:
executeMethod in class Variable
Parameters:
lineNumber - The line number of the script in which the method call occurs.
methodNumber - The method number of the method to execute.
arguments - The set of arguments to use for the method.
Returns:
The value returned from the method, or null if it does not return a value.
Throws:
ScriptException - If the specified method does not exist, or if a problem occurs while attempting to execute it.

assign

public void assign(Argument argument)
            throws ScriptException
Assigns the value of the provided argument to this variable. The value of the provided argument must be of the same type as this variable.

Specified by:
assign in class Variable
Parameters:
argument - The argument whose value should be assigned to this variable.
Throws:
ScriptException - If a problem occurs while performing the assignment.

getValueAsString

public java.lang.String getValueAsString()
Retrieves a string representation of the value of this argument.

Returns:
A string representation of the value of this argument.