gov.nasa.arc.brahms.vm.data
Class VMOperand

java.lang.Object
  extended by gov.nasa.arc.brahms.common.data.BrahmsObject
      extended by gov.nasa.arc.brahms.common.data.Operand
          extended by gov.nasa.arc.brahms.vm.data.VMOperand
All Implemented Interfaces:
IAssignmentLhs, gov.nasa.arc.brahms.common.IConstants, IVMAssignmentLhs, java.io.Serializable

public class VMOperand
extends Operand
implements IVMAssignmentLhs

A VMOperand is an Operand with extensions for use in the virtual machine. An operand represents a terminal element in an expression and specifies either an object, object and attribute, value, or represents a nested expression. An object can be one of a Concept, Current, Variable referencing a Concept, or a Parameter referencing a Concept or Variable. A value can be an Integer, Double, Boolean, String, Symbol, a Variable referencing a value or a Parameter referencing a value.

Version:
$Revision: 1.11 $ $Date: 2009/11/23 22:24:32 $ $Author: rnado $
Author:
Ron van Hoof
See Also:
Operand, Serialized Form

Field Summary
 
Fields inherited from interface gov.nasa.arc.brahms.common.IConstants
ABORT, ACTIVECLASS, ACTIVECONCEPT, ACTIVEINSTANCE, AGENT, ANONYMOUS, ANYAGENT, AREA, AREADEF, ASSIGNED, ATTRIBUTE, BASEAREADEF, BASECLASS, BASECONCEPTUALCLASS, BASEGROUP, BASELIBRARY, BOOLEAN, BROADCAST, BUILDING, BYTE, CCLOCK, CDATE, CHAR, CITY, CLASS, CLOCK, COLLECTALL, COMMUNICATE, COMPLETE, COMPOSITE, COMPUTER, CONCEPT, CONCEPTUALCLASS, CONCEPTUALCONCEPT, CONCEPTUALOBJECT, CONTINUE, COPY, CREATEAGENT, CREATEAREA, CREATEOBJECT, current, CURRENT, DATAFRAME, DATE, DB, DETECTABLE, DIV, DOUBLE, EMAIL, EMPTY_STRING, END, ENDACTIVITY, ENTAGENT, EQ, EXCEPTION, EXPR, FACE2FACE, FACTFRAME, FALSE, FAX, FLOAT, FOREACH, FORONE, G2, GE, GEOGRAPHYCONCEPT, GESTURE, GET, GROUP, GT, IMPASSE, INT, INVALID, JAVA, JAVA_TYPE, KNOWN_MODIFIER, KNOWNVAL_MODIFIER, LE, LOCAL, LONG, LT, MAP, MINUS, MOD, MOVE, MULT, NE, NEW, NONE, NOT_MODIFIER, NOWORK, O, OA, OBJECT, ONTOLOGY, PAGER, PARAMETER, PATH, PHONE, PLUS, PRIMITIVE, PRIVATE, PROAGENT, PROTECTED, PRSAGENT, PUBLIC, PUT, RECEIVE, RELATION, sACTIVECLASS, sACTIVECONCEPT, sACTIVEINSTANCE, sAGENT, sARCHIVE, sAREA, sAREADEF, sBOOLEAN, sBYTE, sBYTECODEEXT, sCHAR, sCLASS, sCOMPUTER, sCONCEPT, sCONCEPTUALCLASS, sCONCEPTUALCONCEPT, sCONCEPTUALOBJECT, sCOPY, sCURRENT, sDETECTABLE, sDOUBLE, sEMAIL, sEND, SEND, sFACE2FACE, sFAX, sFILEEXT, sFLOAT, sGEOGRAPHYCONCEPT, sGROUP, SHORT, SIMAGENT, sINT, sJAVA_TYPE, sLONG, sMAP, sNEW, sNONE, sNOWORK, sOBJECT, SOURCECODE, sPAGER, sPARAMETER, sPATH, sPHONE, sPRIVATE, sPROJECTEXT, sPROTECTED, sPUBLIC, sSHORT, sSTART, sSTRING, sSYMBOL, START, STRING, sUNKNOWN, sVOID, SYMBOL, TRUE, UDT, UML, UNASSIGNED, UNDEFINED, unknown, UNKNOWN, UNKNOWN_MODIFIER, V, VARIABLE, VOID, WHENEVER, WORKFRAME, WORLD, XML
 
Constructor Summary
VMOperand()
          Constructor, creates a new empty operand.
VMOperand(java.lang.Boolean b)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Byte bt)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Character c)
          Constructor, creates a new operand referencing the specified value
VMOperand(Concept concept)
          Constructor, creates a new operand for the specified concept.
VMOperand(Concept concept, Attribute attribute)
          Constructor, creates a new operand for the specified concept and attribute
VMOperand(Current current)
          Constructor, creates a new operand for the current indicator.
VMOperand(Current current, Attribute attribute)
          Constructor, creates a new operand for the current indicator and attribute.
VMOperand(java.lang.Double d)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Float f)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Integer i)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Long l)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Object value)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.Object object, Attribute property)
          Constructor, creates a new operand referencing the specified Java object and property.
VMOperand(Parameter parm)
          Constructor, creates a new operand for the specified parameter.
VMOperand(Parameter parm, Attribute attribute)
          Constructor, creates a new operand for the specified parameter and attribute.
VMOperand(java.lang.Short st)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.String s)
          Constructor, creates a new operand referencing the specified value
VMOperand(java.lang.String s, boolean symbol)
          Constructor, creates a new operand referencing the specified value
VMOperand(Variable var)
          Constructor, creates a new operand for the specified variable.
VMOperand(Variable var, Attribute attribute)
          Constructor, creates a new operand for the specified variable and attribute.
VMOperand(VMExpression expr)
          Constructor, creates a new operand representing a nested expression
 
Method Summary
 void assign(java.util.List<java.lang.Object> values, VMActiveInstanceCtx agent, VMFrameCtx frame, Type collectType)
          Assigns a list of values to the element resulting from evaluating the left-hand side expression.
 void buildRSN(gov.nasa.arc.brahms.vm.engine.rsn.ReasoningStateNetwork rsn, gov.nasa.arc.brahms.vm.engine.rsn.IRSNFrameNode frame, gov.nasa.arc.brahms.vm.engine.rsn.RSNActivityRefNode actref, int modifier)
          Adds this operand to the reasoning state network to build up a reasoning state network that maintains a state of what statements matched with the operand.
 java.lang.Object coerceValue(java.lang.Object value, Type brahmsType)
          Attempts to coerce a value to a form that can be assigned to a variable of a given Brahms type.
 boolean evaluate(gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame, int modifier, int relop, gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameEvaluationRecord evalRcd, java.util.LinkedList values)
          Evaluates the operand as part of a precondition determining whether or not the operand has a successfull match with a statement.
 java.lang.String getConditionElementID(gov.nasa.arc.brahms.vm.engine.rsn.IRSNFrameNode frame)
          Returns the condition element id for this operand for the specified frame node.
 java.util.LinkedList resolveAsLhs(VMActiveInstanceCtx agent, VMFrameCtx frame, int strategy)
          Resolves this operand considering it to be part of an expression located on the left hand side in a comparison.
 java.util.LinkedList resolveAsRhs(VMActiveInstanceCtx agent, VMFrameCtx frame, int strategy)
          Resolves this operand considering it to be part of an expression located on the right hand side in a comparison.
 java.util.LinkedList resolveCollectionIndex(VMActiveInstanceCtx agent, VMFrameCtx frame)
          Resolves the collection index of this operand, this method resolves the index value specified in this operand.
 java.util.LinkedList resolveObject(VMActiveInstanceCtx agent, VMFrameCtx frame)
          Resolves the object for this operand to one or more concepts provided this operand represents an object.
 java.util.LinkedList resolveValue(VMActiveInstanceCtx agent, VMFrameCtx frame)
          Resolves the value of this operand, this method only resolves the object to the appropriate set of concepts or returns the value represented by this operand.
 
Methods inherited from class gov.nasa.arc.brahms.common.data.Operand
getAttribute, getCollectionIndex, getCollectionIndexType, getExpression, getObject, getObjectType, getOperandType, getParameters, getValue, getValueType, getValueTypeIndicator, getVariables, isAnonymous, isUnknown, setAttribute, setCollectionIndex, setCollectionIndex, setCollectionIndex, setCollectionIndex, setExpression, setID, setObject, setObject, setObject, setObject, setObjectType, setOperandType, setUnknown, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueType, toString
 
Methods inherited from class gov.nasa.arc.brahms.common.data.BrahmsObject
delete, export, getFile, getID, getLine, getSerialNumber, isBCC, isDynamic, isLoaded, isResolved, setBCC, setDynamic, setFile, setID, setLine, setLoaded, setResolved, setSerialNumber
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.nasa.arc.brahms.common.data.IAssignmentLhs
export
 

Constructor Detail

VMOperand

public VMOperand()
Constructor, creates a new empty operand.


VMOperand

public VMOperand(Concept concept)
Constructor, creates a new operand for the specified concept.

Parameters:
concept - the Concept this operand references

VMOperand

public VMOperand(Current current)
Constructor, creates a new operand for the current indicator.

Parameters:
current - the Current object

VMOperand

public VMOperand(Variable var)
Constructor, creates a new operand for the specified variable.

Parameters:
var - the Variable this operand references

VMOperand

public VMOperand(Parameter parm)
Constructor, creates a new operand for the specified parameter.

Parameters:
parm - the Parameter this operand references

VMOperand

public VMOperand(Concept concept,
                 Attribute attribute)
Constructor, creates a new operand for the specified concept and attribute

Parameters:
concept - the Concept this operand references
attribute - the Attribute of the Concept referenced by the operand

VMOperand

public VMOperand(Current current,
                 Attribute attribute)
Constructor, creates a new operand for the current indicator and attribute.

Parameters:
current - the Current object
attribute - the Attribute of the Current concept referenced by the operand

VMOperand

public VMOperand(Variable var,
                 Attribute attribute)
Constructor, creates a new operand for the specified variable and attribute.

Parameters:
var - the Variable this operand references
attribute - the Attribute of the concept referenced by the variable as referenced by the operand

VMOperand

public VMOperand(Parameter parm,
                 Attribute attribute)
Constructor, creates a new operand for the specified parameter and attribute.

Parameters:
parm - the Parameter this operand references
attribute - the Attribute of the concept referenced by the parameter as referenced by the operand

VMOperand

public VMOperand(java.lang.Integer i)
Constructor, creates a new operand referencing the specified value

Parameters:
i - the Integer value referenced by the operand

VMOperand

public VMOperand(java.lang.Character c)
Constructor, creates a new operand referencing the specified value

Parameters:
c - the Character value referenced by the operand

VMOperand

public VMOperand(java.lang.Byte bt)
Constructor, creates a new operand referencing the specified value

Parameters:
bt - the Byte value referenced by the operand

VMOperand

public VMOperand(java.lang.Short st)
Constructor, creates a new operand referencing the specified value

Parameters:
st - the Short value referenced by the operand

VMOperand

public VMOperand(java.lang.Long l)
Constructor, creates a new operand referencing the specified value

Parameters:
l - the Long value referenced by the operand

VMOperand

public VMOperand(java.lang.Float f)
Constructor, creates a new operand referencing the specified value

Parameters:
f - the Float value referenced by the operand

VMOperand

public VMOperand(java.lang.Double d)
Constructor, creates a new operand referencing the specified value

Parameters:
d - the Double value referenced by the operand

VMOperand

public VMOperand(java.lang.Boolean b)
Constructor, creates a new operand referencing the specified value

Parameters:
b - the Boolean value referenced by the operand

VMOperand

public VMOperand(java.lang.String s)
Constructor, creates a new operand referencing the specified value

Parameters:
s - the String value referenced by the operand

VMOperand

public VMOperand(java.lang.String s,
                 boolean symbol)
Constructor, creates a new operand referencing the specified value

Parameters:
s - the String or Symbol value referenced by the operand
symbol - true if s is a symbol, false if s is a string

VMOperand

public VMOperand(java.lang.Object value)
Constructor, creates a new operand referencing the specified value

Parameters:
value - the Java object referenced by the operand

VMOperand

public VMOperand(java.lang.Object object,
                 Attribute property)
Constructor, creates a new operand referencing the specified Java object and property. This is only used for transfer definitions in a request for beliefs from a remote agent

Parameters:
object - the Java object referenced by the operand
property - an Attribute representing a property of the Java object

VMOperand

public VMOperand(VMExpression expr)
Constructor, creates a new operand representing a nested expression

Parameters:
expr - the nested Expression
Method Detail

resolveAsLhs

public java.util.LinkedList resolveAsLhs(VMActiveInstanceCtx agent,
                                         VMFrameCtx frame,
                                         int strategy)
                                  throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves this operand considering it to be part of an expression located on the left hand side in a comparison. As an operand in a left hand side expression in a comparison the operand cannot contain a nested expression or a value. The operand resolves itself by checking the object. If the object is current, a variable, or a parameter they are resolved to concepts. This method returns one or more operands that can directly be used in expressions. If multiple concepts result from the resolution, then multiple operands are returned. If an attribute is specified, then all operands returned will also reference the attribute.

Note:This method is only usable with consequences, detectables, and transfer definitions, not with preconditions. Left hand side of preconditions can contain expressions which are not handled by this method.

Parameters:
agent - the agent from which the belief set is to be used to resolve this operand
frame - the frame in which this operand is used, used to resolve variables. The frame is also used to resolve current. Current is replaced with the agent performing the frame. The agent passed can be another agent then the current agent (in case of transfers from another agent).
strategy - the strategy to use to resolve this operand as a left hand side. NONE if an OA is not to be resolved, FACTS if facts are to be used to resolve an OA, BELIEFS if beliefs are to be used to resolve an OA
Returns:
LinkedList a list of operands that can be used in expressions located on the left hand side of a comparison.
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the method was unable to get access to dynamic or static model elements
VMError - if an invalid element is encountered in the operand when considering this as part of a left hand side expression in a comparison.
See Also:
resolveAsRhs(gov.nasa.arc.brahms.vm.rt.VMActiveInstanceCtx, gov.nasa.arc.brahms.vm.rt.VMFrameCtx, int), IVMComparison.NONE, IVMComparison.FACTS, IVMComparison.BELIEFS

resolveObject

public java.util.LinkedList resolveObject(VMActiveInstanceCtx agent,
                                          VMFrameCtx frame)
                                   throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves the object for this operand to one or more concepts provided this operand represents an object.

Parameters:
agent - the agent from which the belief set is to be used to resolve this operand
frame - the frame in which this operand is used, used to resolve variables. The frame is also used to resolve current. Current is replaced with the agent performing the frame. The agent passed can be another agent then the current agent (in case of transfers from another agent).
Returns:
LinkedList a list of resolved concepts.
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the operand does not reference an object
VMError - if an invalid element is encountered in the operand when considering this as part of a left hand side expression in a comparison.

resolveAsRhs

public java.util.LinkedList resolveAsRhs(VMActiveInstanceCtx agent,
                                         VMFrameCtx frame,
                                         int strategy)
                                  throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves this operand considering it to be part of an expression located on the right hand side in a comparison. As an operand in a right hand side expression in a comparison the operand can contain a nested expression or a value. The operand resolves itself by checking the object or if it is an expression resolving the expression. If it is an object and it is current, a variable, or a parameter they are resolved to concepts. This method returns one or more operands that can directly be used in expressions. If multiple concepts result from the resolution, then multiple operands are returned. If an attribute is specified, then all operands returned will be resolved to a value using the resolved object by looking up the value in the belief set of the agent and optionally by looking up the value in the fact set of the world.

Parameters:
agent - the agent from which the belief set is to be used to resolve this operand
frame - the frame in which this operand is used, used to resolve variables. The frame is also used to resolve current. Current is replaced with the agent performing the frame. The agent passed can be another agent then the current agent (in case of transfers from another agent).
strategy - the strategy to use to resolve this operand as a right hand side. FACTS if facts are to be used to resolve an OA, BELIEFS if beliefs are to be used to resolve an OA
Returns:
LinkedList a list of RhsOperandValue's that can be used in expressions located on the right hand side of a comparison.
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the method was unable to get access to dynamic or static model elements
VMError - if an invalid element is encountered in the operand when considering this as part of a left hand side expression in a comparison.
See Also:
resolveAsLhs(gov.nasa.arc.brahms.vm.rt.VMActiveInstanceCtx, gov.nasa.arc.brahms.vm.rt.VMFrameCtx, int), IVMComparison.FACTS, IVMComparison.BELIEFS

resolveValue

public java.util.LinkedList resolveValue(VMActiveInstanceCtx agent,
                                         VMFrameCtx frame)
                                  throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves the value of this operand, this method only resolves the object to the appropriate set of concepts or returns the value represented by this operand. This method does not yet resolve the values by matching with beliefs or facts taking into account the attribute defined for the operand.

Parameters:
agent - the agent from which the belief set is to be used to resolve this operand
frame - the frame in which this operand is used, used to resolve variables. The frame is also used to resolve current. Current is replaced with the agent performing the frame. The agent passed can be another agent then the current agent (in case of transfers from another agent).
Returns:
LinkedList a list of objectified values.
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the method was unable to get access to dynamic or static model elements
VMError - if an invalid element is encountered in the operand when considering this as part of a left hand side expression in a comparison.

resolveCollectionIndex

public java.util.LinkedList resolveCollectionIndex(VMActiveInstanceCtx agent,
                                                   VMFrameCtx frame)
                                            throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves the collection index of this operand, this method resolves the index value specified in this operand.

Parameters:
agent - the agent from which the belief set is to be used to resolve this operand
frame - the frame in which this operand is used, used to resolve variables.
Returns:
LinkedList a list of objectified values.
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the method was unable to get access to dynamic or static model elements

buildRSN

public void buildRSN(gov.nasa.arc.brahms.vm.engine.rsn.ReasoningStateNetwork rsn,
                     gov.nasa.arc.brahms.vm.engine.rsn.IRSNFrameNode frame,
                     gov.nasa.arc.brahms.vm.engine.rsn.RSNActivityRefNode actref,
                     int modifier)
              throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Adds this operand to the reasoning state network to build up a reasoning state network that maintains a state of what statements matched with the operand.

Parameters:
rsn - the ReasoningStateNetwork to be built
frame - the RSNFrameNode for the frame in which this condition element is used.
actref - the optional RSNActivityRefNode for the activity reference referencing a composite activity in which the frame and the precondition are specified.
modifier - the modifier of the (pre)condition
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an error occurs in building up the RSN with this expression

evaluate

public boolean evaluate(gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame,
                        int modifier,
                        int relop,
                        gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameEvaluationRecord evalRcd,
                        java.util.LinkedList values)
                 throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Evaluates the operand as part of a precondition determining whether or not the operand has a successfull match with a statement. If so the operand evaluates to true.

Parameters:
frame - the RSNFrameNode for the frame in which the operand's precondition is specified
modifier - the modifier of the (pre)condition
relop - relational operator used to find OA matches, -1 if relop can be ignored, otherwise one of Relation.EQ or Relation.NE
evalRcd - the record in which to store bindings for variables and statements matching preconditions
values - the list of values matching the operand
Returns:
true if the operand evaluates to true, false otherwise
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an internal error occurs

assign

public void assign(java.util.List<java.lang.Object> values,
                   VMActiveInstanceCtx agent,
                   VMFrameCtx frame,
                   Type collectType)
            throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Assigns a list of values to the element resulting from evaluating the left-hand side expression. the boolean collect parameter is true, the list of values is assigned as a single collection value to the left-hand side element. If the collect parameter is false only the first value in the list is assigned.

Specified by:
assign in interface IVMAssignmentLhs
Parameters:
values - the list of values to be assigned
agent - the VMActiveInstanceCtx for the agent performing the assignment operation
frame - the VMFrameCtx for the frame that is being executed
collectType - the collection element type if the values should be assigned as a collection to the left-hand side, else null
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an error occurs during the assignment

coerceValue

public java.lang.Object coerceValue(java.lang.Object value,
                                    Type brahmsType)
                             throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Attempts to coerce a value to a form that can be assigned to a variable of a given Brahms type. Returns null if unable to perform the coercion.

Parameters:
value - the value to be coerced
brahmsType - the Brahms type to which the value should be coerced
Returns:
Object the result of the coercion or null if the coercion fails
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an error occurs during the attempted coercion

getConditionElementID

public final java.lang.String getConditionElementID(gov.nasa.arc.brahms.vm.engine.rsn.IRSNFrameNode frame)
Returns the condition element id for this operand for the specified frame node.

Parameters:
frame - the IRSNFrameNode for which the condition element is requested
Returns:
String the condition element if it exists, null if no condition element is specified.


Copyright © 1997-2012 All Rights Reserved.