edu.ucsb.cs.jicos.services.external.services.matlab
Class TaskMatlab

java.lang.Object
  extended by edu.ucsb.cs.jicos.services.Task
      extended by edu.ucsb.cs.jicos.services.external.services.TaskExternal
          extended by edu.ucsb.cs.jicos.services.external.services.matlab.TaskMatlab
All Implemented Interfaces:
edu.ucsb.cs.jicos.services.external.XmlConverter, java.io.Serializable

public class TaskMatlab
extends TaskExternal

See Also:
Serialized Form

Field Summary
static int DATATYPE_Double
          double (floating point) data type.
static int DATATYPE_Float
          floating point data type.
static int DATATYPE_Int08
          8-bit (signed) integer data type.
static int DATATYPE_Int16
          16-bit (signed) integer data type.
static int DATATYPE_Int32
          32-bit (signed) integer data type.
static int DATATYPE_Int64
          64-bit (signed) integer data type.
static int DATATYPE_unknown
          Unknown data type.
 
Fields inherited from class edu.ucsb.cs.jicos.services.external.services.TaskExternal
serviceClass
 
Fields inherited from class edu.ucsb.cs.jicos.services.Task
ALL_INPUTS
 
Fields inherited from interface edu.ucsb.cs.jicos.services.external.XmlConverter
NAMESPACE, STYLESHEET_Html, STYLESHEET_Unknown, STYLESHEET_Xml
 
Constructor Summary
TaskMatlab()
          Default, no argument, constructor.
TaskMatlab(java.lang.String command)
          Create a Matlab task with the specified command.
TaskMatlab(java.lang.String command, java.util.Map dataMap, java.lang.String resultName)
          Create a complete Matlab task.
 
Method Summary
 void addData(java.util.Map dataMap)
          Add the contents of a map to the contents of the data map.
 void addData(java.lang.String name, java.lang.Object value)
          Add an object to the data map of this task.
 java.lang.Object createInput(ExternalData externalData)
          Create the input variable with data from the external data (should be overridden).
 XmlDocument createResult(java.lang.Object result)
          Create an XML document from the result (should be overridden).
 Shared createShared(ExternalData externalData)
          Create the shared object with data from the external data (should be overridden).
 java.lang.Object execute(Environment environment)
          Get the Matlab engine and invoke a command on it.
 boolean fromXml(ExternalData externalData)
          Populate the variables with data from the external data (should be overridden).
 java.lang.String getCommand()
          Return the name of the command.
 java.lang.Object[][] getData()
          Return the data in a n x2 array of data.
 java.lang.Object getData(java.lang.String name)
          Get a particular data item by name.
 java.util.Map getDataMap()
          Return the map of data (name/value pairs).
static int getDataType(java.lang.String typeName)
          Return the data type enumerator for the given name.
 java.lang.Object getMatlabResult()
          Return the result of the matlab computation.
 java.lang.String getResultName()
          Return the name of the variable containing the result.
static java.lang.String getTypeName(int typeId)
          Get the name of the typeId enumerator.
 void setCommand(java.lang.String command)
          Set the command to be perfoirmed by matlab.
 void setData(java.util.Map dataMap)
          Set the contents of the data map to the contents of the given map.
 void setMatlabResult(java.lang.Object matlabResult)
          Save the result of the computation.
 void setResultName(java.lang.String resultName)
          Set the name of the variable containing the result at the end of the computation.
 java.lang.String toHtmlString(XmlDocument xmlResult, java.lang.String hostPort)
          Create an HTML document from the result (should be overridden).
protected  java.lang.String toString_Matrix(java.lang.Number[][] matrix, boolean isInteger)
          Convert a matrix of java.lang.Number to a string.
protected  java.lang.String toString_MatrixFloat(java.lang.Object matrix)
          Convert a vector of floating point numbers (float, or double) to a string.
protected  java.lang.String toString_MatrixInt(java.lang.Object matrix)
          Convert a matrix of integers (short, int, or long) to a string.
protected  java.lang.String toString_Scalar(java.lang.Number scalar, boolean isInteger)
          Convert a java.lang.Number to a string using a number formatter.
protected  java.lang.String toString_Vector(java.lang.Number[] vector, boolean isInteger)
          Convert an array of java.lang.Numbers to a string.
protected  java.lang.String toString_VectorFloat(java.lang.Object vector)
          Convert a vector of floating points (float, or double) to a string.
protected  java.lang.String toString_VectorInt(java.lang.Object vector)
          Convert a vector of integers (short, int, or long) to a string.
 java.lang.String toString()
          Override the default method to create a Java string (class[member,[...]]).
 java.lang.String toString(java.lang.Object object)
          Convert an object to a string (depending on it's type).
protected  java.lang.String toXml_Matrix(java.lang.Object matrix, java.lang.String name, java.lang.String prefix)
          Convert a matrix to an XML element.
protected  java.lang.String toXml_Scalar(java.lang.Number scalar, java.lang.String name, boolean isInteger, java.lang.String prefix)
          Convert a java.lang.Number to an XML element.
protected  java.lang.String toXml_String(java.lang.String string, java.lang.String name, java.lang.String prefix)
          Convert a String to an XML element.
protected  java.lang.String toXml_Vector(java.lang.Object vector, java.lang.String name, java.lang.String prefix)
          Convert a vector (1-dimensional array) to an XML element.
 java.lang.String toXml(java.lang.Object object, java.lang.String name, java.lang.String prefix)
          Convert the given object to an XML string with the element name given and precede each line of text with the given prefix.
 java.lang.String toXml(java.lang.String prefix)
          Create XML out of this object.
 
Methods inherited from class edu.ucsb.cs.jicos.services.external.services.TaskExternal
getStyleSheet, serviceClass
 
Methods inherited from class edu.ucsb.cs.jicos.services.Task
compute, execute, executeIncrementally, executeOnServer, getInput, getTaskId, isAtomic, numInputs, numUnsetInputs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATATYPE_unknown

public static final int DATATYPE_unknown
Unknown data type.

See Also:
Constant Field Values

DATATYPE_Int08

public static final int DATATYPE_Int08
8-bit (signed) integer data type.

See Also:
Constant Field Values

DATATYPE_Int16

public static final int DATATYPE_Int16
16-bit (signed) integer data type.

See Also:
Constant Field Values

DATATYPE_Int32

public static final int DATATYPE_Int32
32-bit (signed) integer data type.

See Also:
Constant Field Values

DATATYPE_Int64

public static final int DATATYPE_Int64
64-bit (signed) integer data type.

See Also:
Constant Field Values

DATATYPE_Float

public static final int DATATYPE_Float
floating point data type.

See Also:
Constant Field Values

DATATYPE_Double

public static final int DATATYPE_Double
double (floating point) data type.

See Also:
Constant Field Values
Constructor Detail

TaskMatlab

public TaskMatlab()
Default, no argument, constructor.


TaskMatlab

public TaskMatlab(java.lang.String command)
Create a Matlab task with the specified command.

Parameters:
command - Matlab command.

TaskMatlab

public TaskMatlab(java.lang.String command,
                  java.util.Map dataMap,
                  java.lang.String resultName)
Create a complete Matlab task.

Parameters:
command - The matlab command to evaluate.
dataMap - The supporting data for the command.
resultName - The name of the variable containing the result.
Method Detail

getCommand

public java.lang.String getCommand()
Return the name of the command.


getDataMap

public java.util.Map getDataMap()
Return the map of data (name/value pairs).


getDataType

public static int getDataType(java.lang.String typeName)
Return the data type enumerator for the given name.

Parameters:
typeName - The name of the type.

getResultName

public java.lang.String getResultName()
Return the name of the variable containing the result.


getTypeName

public static java.lang.String getTypeName(int typeId)
Get the name of the typeId enumerator.

Parameters:
typeId - The data type enumerator.

getData

public java.lang.Object[][] getData()
Return the data in a n x2 array of data. The first element of each row is the name and the second element is the obect.


getData

public java.lang.Object getData(java.lang.String name)
Get a particular data item by name.

Parameters:
name - The name of the data item, null for the whole thing.
Returns:
The specified data item, or null if not found.

getMatlabResult

public java.lang.Object getMatlabResult()
Return the result of the matlab computation.


toString

public java.lang.String toString()
Override the default method to create a Java string (class[member,[...]]).

Overrides:
toString in class Task
Returns:
a String representation of the Task:

toString

public java.lang.String toString(java.lang.Object object)
Convert an object to a string (depending on it's type). Possible objects:
  1. java.lang.Number
  2. int[]
  3. double[]
  4. java.lang.Number[]
  5. int[][]
  6. double[][]
  7. java.lang.Number[][]

Parameters:
object - Some object.

toXml

public java.lang.String toXml(java.lang.Object object,
                              java.lang.String name,
                              java.lang.String prefix)
Convert the given object to an XML string with the element name given and precede each line of text with the given prefix.

Parameters:
object - The object to convert.
name - The name of the element.
prefix - Precede each line of text with this string.

setCommand

public void setCommand(java.lang.String command)
Set the command to be perfoirmed by matlab.

Parameters:
command - Matlab command to invoke.

setResultName

public void setResultName(java.lang.String resultName)
Set the name of the variable containing the result at the end of the computation.

Parameters:
resultName - The name of the variable.

setData

public void setData(java.util.Map dataMap)
Set the contents of the data map to the contents of the given map.

Parameters:
dataMap - A map of variable name/value pairs.

addData

public void addData(java.lang.String name,
                    java.lang.Object value)
Add an object to the data map of this task.

Parameters:
name - The name of this variable.
value - The value of this variable.

addData

public void addData(java.util.Map dataMap)
Add the contents of a map to the contents of the data map.

Parameters:
dataMap - Additional contents.

setMatlabResult

public void setMatlabResult(java.lang.Object matlabResult)
Save the result of the computation.

Parameters:
matlabResult - The result of the matlab result.

execute

public java.lang.Object execute(Environment environment)
Get the Matlab engine and invoke a command on it.

Overrides:
execute in class TaskExternal
Parameters:
environment - The Jicos environment of this task.
Returns:
The returned Object is either the execute method's computed value xor a (compose) Task. In the latter case, the compose task takes the output from this task's subtasks, and composes it to create this task's output. This, at least, is the intent of this method's returned value.

toXml

public java.lang.String toXml(java.lang.String prefix)
Create XML out of this object.

Specified by:
toXml in interface edu.ucsb.cs.jicos.services.external.XmlConverter
Overrides:
toXml in class TaskExternal
Parameters:
prefix - Precede each line of output with this.

fromXml

public boolean fromXml(ExternalData externalData)
Populate the variables with data from the external data (should be overridden).

Specified by:
fromXml in interface edu.ucsb.cs.jicos.services.external.XmlConverter
Overrides:
fromXml in class TaskExternal
Returns:
false

createInput

public java.lang.Object createInput(ExternalData externalData)
Create the input variable with data from the external data (should be overridden).

Specified by:
createInput in interface edu.ucsb.cs.jicos.services.external.XmlConverter
Overrides:
createInput in class TaskExternal
Returns:
null

createShared

public Shared createShared(ExternalData externalData)
Create the shared object with data from the external data (should be overridden).

Specified by:
createShared in interface edu.ucsb.cs.jicos.services.external.XmlConverter
Overrides:
createShared in class TaskExternal
Returns:
false

createResult

public XmlDocument createResult(java.lang.Object result)
                         throws java.lang.Exception
Create an XML document from the result (should be overridden).

Specified by:
createResult in interface edu.ucsb.cs.jicos.services.external.XmlConverter
Overrides:
createResult in class TaskExternal
Returns:
>?xml version="1.0"?<
Throws:
java.lang.Exception

toHtmlString

public java.lang.String toHtmlString(XmlDocument xmlResult,
                                     java.lang.String hostPort)
Create an HTML document from the result (should be overridden).

Specified by:
toHtmlString in interface edu.ucsb.cs.jicos.services.external.XmlConverter
Overrides:
toHtmlString in class TaskExternal

toString_Scalar

protected java.lang.String toString_Scalar(java.lang.Number scalar,
                                           boolean isInteger)
Convert a java.lang.Number to a string using a number formatter.

Parameters:
scalar - The number to format.
isInteger - Are the numbers integers?
See Also:
toString()

toString_Vector

protected java.lang.String toString_Vector(java.lang.Number[] vector,
                                           boolean isInteger)
Convert an array of java.lang.Numbers to a string.

Parameters:
vector - The array of numbers.
isInteger - Are the numbers integers?
See Also:
toString()

toString_VectorInt

protected java.lang.String toString_VectorInt(java.lang.Object vector)
Convert a vector of integers (short, int, or long) to a string.

Parameters:
vector - The array of numbers.
See Also:
toString()

toString_VectorFloat

protected java.lang.String toString_VectorFloat(java.lang.Object vector)
Convert a vector of floating points (float, or double) to a string.

Parameters:
vector - The array of floating point numbers.
See Also:
toString()

toString_Matrix

protected java.lang.String toString_Matrix(java.lang.Number[][] matrix,
                                           boolean isInteger)
Convert a matrix of java.lang.Number to a string.

Parameters:
matrix - The array of array of numbers.
isInteger - Are the numbers integers?
See Also:
toString()

toString_MatrixInt

protected java.lang.String toString_MatrixInt(java.lang.Object matrix)
Convert a matrix of integers (short, int, or long) to a string.

Parameters:
matrix - The array of array of numbers.
See Also:
toString()

toString_MatrixFloat

protected java.lang.String toString_MatrixFloat(java.lang.Object matrix)
Convert a vector of floating point numbers (float, or double) to a string.

Parameters:
matrix - The array of array of numbers.
See Also:
toString()

toXml_String

protected java.lang.String toXml_String(java.lang.String string,
                                        java.lang.String name,
                                        java.lang.String prefix)
Convert a String to an XML element.

Parameters:
string - The string to convert.
name - The name of the string element.
prefix - Preced each line with this text.
See Also:
toXml(Object,String,String)

toXml_Scalar

protected java.lang.String toXml_Scalar(java.lang.Number scalar,
                                        java.lang.String name,
                                        boolean isInteger,
                                        java.lang.String prefix)
Convert a java.lang.Number to an XML element.

Parameters:
scalar - The number to convert.
name - The name of the string element.
isInteger - Is the number an integer or floating point?
prefix - Preced each line with this text.
See Also:
toXml(Object,String,String)

toXml_Vector

protected java.lang.String toXml_Vector(java.lang.Object vector,
                                        java.lang.String name,
                                        java.lang.String prefix)
Convert a vector (1-dimensional array) to an XML element.

Parameters:
vector - The vector to convert.
name - The name of the string element.
prefix - Preced each line with this text.
See Also:
toXml(Object,String,String)

toXml_Matrix

protected java.lang.String toXml_Matrix(java.lang.Object matrix,
                                        java.lang.String name,
                                        java.lang.String prefix)
Convert a matrix to an XML element.

Parameters:
matrix - The matrix to convert.
name - The name of the string element.
prefix - Preced each line with this text.
See Also:
toXml(Object,String,String)


Jicos: http://cs.ucsb.edu/projects/jicos