context.arch.interpreter
Class Interpreter

java.lang.Object
  extended bycontext.arch.BaseObject
      extended bycontext.arch.interpreter.Interpreter
All Implemented Interfaces:
CommunicationsHandler, MessageHandler

public abstract class Interpreter
extends BaseObject

This class is the basic interpreter.

See Also:
BaseObject

Field Summary
static boolean DEBUG
          Debug flag
static int DEFAULT_PORT
          Default port to use for interpreters
protected  Attributes inAttributes
           
protected  java.util.Hashtable inAttributeTypes
           
static java.lang.String INTERPRET
          Tag for interpreter
static java.lang.String INTERPRET_REPLY
          Tag for interpreterReply
static java.lang.String INTERPRETER_TYPE
          The tag for the type of this object
protected  Attributes outAttributes
           
protected  java.util.Hashtable outAttributeTypes
           
 
Fields inherited from class context.arch.BaseObject
BASEOBJECT_TYPE, communications, DISABLE_PORT, discoverer, EXIT_OK, gFrame, handlers, ID, parser, PING, PING_REPLY, QUERY_DESCRIPTION, QUERY_DESCRIPTION_REPLY, serviceHandlers
 
Constructor Summary
Interpreter(int port)
          Constructor that creates a BaseObject with the given port and sets the incoming and outgoing attributes.
 
Method Summary
 DataObject callInterpreter(DataObject data, java.lang.String error)
          This method ensures that the incoming attributes are correct and calls interpretData().
protected  java.lang.String getInAttributeType(java.lang.String name)
          Returns the attribute type with the given name for incoming attributes
 DataObject getInterpreterDescription()
          Returns the interpreter description that should be overloaded
protected  java.lang.String getOutAttributeType(java.lang.String name)
          Returns the attribute type with the given name for outgoing attributes
 java.lang.String getType()
          Returns the type of the object This method should be overridden
 DataObject getUserDescription()
          Overloads the BaseObject method
protected abstract  Attributes interpretData(Attributes data)
          This abstract method interprets the given data and returns it.
protected  boolean isInAttribute(java.lang.String name)
          Checks if the given incoming attribute is an attribute of this interpreter
protected  boolean isOutAttribute(java.lang.String name)
          Checks if the given outgoing attribute is an attribute of this interpreter
protected  DataObject runInterpreterMethod(DataObject data, java.lang.String error)
          This is an empty method that should be overridden by objects that subclass from this class.
 DataObject runUserMethod(DataObject data)
          This method is meant to handle any internal methods that the baseObject doesn't handle.
protected  void setInAttribute(java.lang.String name, java.lang.String type)
          Adds an incoming attribute
protected abstract  Attributes setInAttributes()
          Sets the incoming attributes for the interpreter
protected  void setOutAttribute(java.lang.String name, java.lang.String type)
          Adds an outgoing attribute
protected abstract  Attributes setOutAttributes()
          Sets the outgoing attributes for the interpreter
 
Methods inherited from class context.arch.BaseObject
activateDisplay, askInterpreter, deactivateDisplay, debugprintln, decodeData, discovererQuery, discovererQuery, discovererRegistration, discovererRegistration, discovererSendSubscription, discovererSubscribe, discovererSubscriptionNotification, discovererUnregistration, discovererUpdate, encodeData, executeAsynchronousWidgetService, executeSynchronousWidgetService, findDiscoverer, findDiscoverer, findDiscoverer, getComponentDescription, getDescription, getHostAddress, getHostName, getId, getId, getLease, getListOfHandlers, getLocationAddress, getPort, getVersion, getVersion, getWidgetAttributes, getWidgetCallbacks, getWidgetConstantAttributes, getWidgetServices, handleIndependentReply, independentUserRequest, leaseEndNotified, pingComponent, pingComponent, pollWidget, println, putDataInWidget, queryVersion, quit, retrieveDataFrom, retrieveDataFrom, returnPing, runComponentMethod, runMethod, serviceResult, setAllDebug, setDiscoverer, setDisplay, setDisplay, setDisplayName, setDisplayTitle, setId, setLease, setLocationAddress, setVersion, subscribeTo, unsubscribeFrom, updateAndPollWidget, userCallback, userRequest, userRequest, userRequest, userRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Debug flag


INTERPRET

public static final java.lang.String INTERPRET
Tag for interpreter

See Also:
Constant Field Values

INTERPRETER_TYPE

public static final java.lang.String INTERPRETER_TYPE
The tag for the type of this object

See Also:
Constant Field Values

INTERPRET_REPLY

public static final java.lang.String INTERPRET_REPLY
Tag for interpreterReply

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
Default port to use for interpreters

See Also:
Constant Field Values

inAttributes

protected Attributes inAttributes

outAttributes

protected Attributes outAttributes

inAttributeTypes

protected java.util.Hashtable inAttributeTypes

outAttributeTypes

protected java.util.Hashtable outAttributeTypes
Constructor Detail

Interpreter

public Interpreter(int port)
Constructor that creates a BaseObject with the given port and sets the incoming and outgoing attributes.

Parameters:
port - Port number to create the BaseObject on
See Also:
BaseObject
Method Detail

getType

public java.lang.String getType()
Returns the type of the object This method should be overridden

Overrides:
getType in class BaseObject
Returns:
String

runUserMethod

public DataObject runUserMethod(DataObject data)
This method is meant to handle any internal methods that the baseObject doesn't handle. In particular, this method handles interpret requests. It ensures that the ID of the incoming request matches this interpreter. If the method is an INTERPRET method, it sends it to the interpreter. Otherwise runInterpreterMethod() is called.

Overrides:
runUserMethod in class BaseObject
Parameters:
data - DataObject containing the method to run and parameters
Returns:
DataObject containing the results of running the method
See Also:
runInterpreterMethod(DataObject,String)

callInterpreter

public DataObject callInterpreter(DataObject data,
                                  java.lang.String error)
This method ensures that the incoming attributes are correct and calls interpretData(). It returns the interpreted results.

Parameters:
data - Incoming interpret request
error - Incoming error, if any
Returns:
interpreted results
See Also:
#interpretData(AttributeNameValues)

interpretData

protected abstract Attributes interpretData(Attributes data)
This abstract method interprets the given data and returns it.

Parameters:
data - AttributeNameValues containing data to be interpreted
Returns:
AttributeNameValues object containing the interpreted data

runInterpreterMethod

protected DataObject runInterpreterMethod(DataObject data,
                                          java.lang.String error)
This is an empty method that should be overridden by objects that subclass from this class. It is called when another component tries to run a method on the interpreter, but it's not an interpret request.

Parameters:
data - DataObject containing the data for the method
error - String containing the incoming error value
Returns:
DataObject containing the method results

getInAttributeType

protected java.lang.String getInAttributeType(java.lang.String name)
Returns the attribute type with the given name for incoming attributes

Parameters:
name - Name of the attribute to get

setInAttribute

protected void setInAttribute(java.lang.String name,
                              java.lang.String type)
Adds an incoming attribute

Parameters:
name - Name of the attribute to set
type - Type of the attribute

isInAttribute

protected boolean isInAttribute(java.lang.String name)
Checks if the given incoming attribute is an attribute of this interpreter

Parameters:
name - Name of the attribute to check

getOutAttributeType

protected java.lang.String getOutAttributeType(java.lang.String name)
Returns the attribute type with the given name for outgoing attributes

Parameters:
name - Name of the attribute to get

setOutAttribute

protected void setOutAttribute(java.lang.String name,
                               java.lang.String type)
Adds an outgoing attribute

Parameters:
name - Name of the attribute to set
type - Type of the attribute

isOutAttribute

protected boolean isOutAttribute(java.lang.String name)
Checks if the given outgoing attribute is an attribute of this interpreter

Parameters:
name - Name of the attribute to check

setInAttributes

protected abstract Attributes setInAttributes()
Sets the incoming attributes for the interpreter


setOutAttributes

protected abstract Attributes setOutAttributes()
Sets the outgoing attributes for the interpreter


getUserDescription

public DataObject getUserDescription()
Overloads the BaseObject method

Overrides:
getUserDescription in class BaseObject
Returns:
DataObject The description
See Also:
Discoverer

getInterpreterDescription

public DataObject getInterpreterDescription()
Returns the interpreter description that should be overloaded