Working with command results in embedded mode
The EmbeddedScript method getResult() returns
the result of the last command that was executed.
There are five types of Result supported by EmbeddedScript.
In order to cast a result to its specific type, check the result
object to determine which class it is, or call getType().
While the documentation indicates the type of result returned for
each command, it is recommended to confirm that the type is the correct
instance before using it.
Using instanceof to check the type:
script.execute(list subscriptions
);
Result result = script.getResult();
if (result instanceof ResultStringTable)
{
...
}
Using getType() to check the type:
script.execute(list subscriptions
);
Result result = script.getResult();
switch (result.getType())
{
case Result.TABLE:
...
break;
}
The key methods for each of the result types are as follows:
ResultNullfor commands with no output.- String
toString()Returns an empty string
ResultStringKeyValuesfor commands that return a collection of string-based key-value pairs.- String[]
getKeys()- String[]
getNames()- int
getRowCount()- String
getValue(String key)- String
toString()
ResultStringListfor commands that return a list of strings.- int
getRowCount()- String
getValueAt(int row) throws IndexOutOfBoundsException- String
toString()
ResultStringTablefor commands that return a table of records.- int
getColumnCount()- String
getColumnAt(int column) throws IndexOutOfBoundsException- int
getRowCount()- String
getValueAt(int row, int column) throws ArrayIndexOutOfBoundsException- String
getValueAt(int row, String columnName) throws ArrayIndexOutOfBoundsException- int
lookupRow(String lookupColumnName, String lookupValue)- String
lookupValue(String lookupColumnName, String keyColumnName, String keyValue)- String
toString()
ResultValuefor commands that return a string value.- String
getValue()- String
toString()
The results for a command may contain elements that are translated. For example, an application run in Japanese will display column names, keys, and possibly values in Japanese. Applications written using EmbeddedScript must account for language differences, if those applications are run in multiple languages.