Class ArgumentBasedContext
java.lang.Object
edu.tufts.hrilab.action.execution.Context
edu.tufts.hrilab.action.execution.ArgumentBasedContext
- Direct Known Subclasses:
AsynchronousContext
,CatchContext
,DatabaseEntryContext
,ExitContext
,ForContext
,ForeachContext
,GoalContext
,JoinContext
,ObservationContext
,TradeServiceContext
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinkedHashMap<String,
ActionBinding> Arguments defined in this context.protected static Pattern
Fields inherited from class edu.tufts.hrilab.action.execution.Context
caller, childContexts, cmd, constraints, endTime, log, maxTime, startTime, stateMachine
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ArgumentBasedContext
(Context caller, StateMachine sm, String cmd) protected
ArgumentBasedContext
(Context caller, StateMachine sm, String cmd, ExecutionType executionType) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
addArgument
(String bName, Class<?> javaType, Object bValue, boolean bLocal, boolean bReturn) Adds a new argument to the current context.protected boolean
addArgument
(String bName, Class<?> javaType, String semanticType, Object bValue, String bDefault, boolean bLocal, boolean bReturn, boolean bIsVarArg) Adds a new argument to the current contextbindPredicate
(Symbol orig) Given the original Predicate, for each argument that is an unbound variable, create a binding and put it in a new Predicate.protected String
Parses text and replaces args with their values.protected void
copyArguments
(LinkedHashMap<String, ActionBinding> argumentsToCopy) Copy arguments into this Context.protected ActionBinding
getArgument
(String bname) Finds the ActionBinding in this or parent contexts.Get list of copied and evaluated arguments in order.protected ActionBinding
getArgumentSilent
(String bname) Same as getArgument method but does not generate a log statement in the case the argument is not found.Class<?>
getArgumentType
(String bname) Retrieve the type of an argumentgetArgumentValue
(String bname) Retrieve the (deep) value of an argument, evaluating any unevaluated arguments in the process.protected ActionBinding
getEvaluatedArgument
(String bname) Return an ActionBinding with the (deep) value of an argument.protected ActionBinding
getLocalArgument
(String bname) Get a local argument without recursing up the context tree.Create predicate from the context cmd and arguments: "cmd(arg0, arg1, ...)".boolean
hasArgumentInScope
(String bname) Check if the specified argument exists in action scope.boolean
hasLocalArgument
(String bname) Check if this context explicitly has the specified argument.protected void
protected void
setArgument
(String bname, Object val) Specify the (deep) value of an argumentprotected abstract void
setupArguments
(List<? extends Object> inputArgs, List<? extends Object> returnArgs) Methods inherited from class edu.tufts.hrilab.action.execution.Context
acquireLocks, addEvent, addEvent, addEvent, causedFailure, copy, copyInternal, createSimulatedEquivalent, doStep, getActor, getActualLogicalValue, getChildContexts, getCommand, getConstraints, getContextDescription, getContextDescription, getDuration, getElapsedTime, getEndTime, getEquivalentContext, getExecType, getId, getJustification, getLogicalValue, getMaxTime, getNearestTerminatedAncestor, getNextStep, getNextStepForType, getParentContext, getRootContext, getStartTime, getStateMachine, getStateUpdates, getStatus, hasNormCheckingAncestor, isAction, isApproved, isAsynchronous, isFailure, isSimulation, isSuccess, isTerminated, performAdditionalStatusUpdates, releaseLocks, resetConcreteContext, resetContext, resetCoreContext, setChildContexts, setConstraints, setEndTime, setExecType, setLogicalValue, setStartTime, setStartTime, setStateMachine, setStatus, setStatus, setTimeout, setupNextStep, setupNextStep, startOverAllMonitor, toString, updatePerformanceModels, verifyEffects, verifyReturnValue, waitForTermination, waitForTermination
-
Field Details
-
arguments
Arguments defined in this context. -
variable
-
-
Constructor Details
-
ArgumentBasedContext
-
ArgumentBasedContext
protected ArgumentBasedContext(Context caller, StateMachine sm, String cmd, ExecutionType executionType)
-
-
Method Details
-
setupArguments
-
getSignatureInPredicateForm
Create predicate from the context cmd and arguments: "cmd(arg0, arg1, ...)".- Overrides:
getSignatureInPredicateForm
in classContext
- Returns:
-
getArguments
Get list of copied and evaluated arguments in order. ?actor role is alwyas first.- Overrides:
getArguments
in classContext
- Returns:
-
hasLocalArgument
Check if this context explicitly has the specified argument. This does not search the entire action scope.- Parameters:
bname
- argument name- Returns:
- true if argument exists
-
hasArgumentInScope
Check if the specified argument exists in action scope. Scope in the context tree is defined as within an ActionContext (i.e., will not search outside of the containing ActionContextzs).- Parameters:
bname
-- Returns:
-
getArgumentValue
Retrieve the (deep) value of an argument, evaluating any unevaluated arguments in the process. Recurses up the caller tree to find argument, if it exists.- Overrides:
getArgumentValue
in classContext
- Parameters:
bname
- the argument's name- Returns:
- the deep binding associated with that name in the current context
-
getEvaluatedArgument
Return an ActionBinding with the (deep) value of an argument. This will attempt to evaluate any unevaluated arguments (e.g., strings containing free variables), and return them in a (potentially cloned) ActionBinding instance. Recurses up the caller tree to find argument, if it does not exist in this context.- Overrides:
getEvaluatedArgument
in classContext
- Parameters:
bname
- the argument's name- Returns:
- an (potentially cloned) ActionBinding associated with the bname in the current context
-
getArgumentType
Retrieve the type of an argument- Overrides:
getArgumentType
in classContext
- Parameters:
bname
- the argument's name- Returns:
- the type associated with that name in the current context
-
getArgument
Finds the ActionBinding in this or parent contexts. Returns null if no binding with that name exists. Similar to getEvaluatedArgument but does not attempt to evaluate or modify the ActionBinding in an way.- Overrides:
getArgument
in classContext
- Parameters:
bname
- Binding name- Returns:
- the closest binding with that name in the context tree
-
getArgumentSilent
Description copied from class:Context
Same as getArgument method but does not generate a log statement in the case the argument is not found. This is useful for method like hasArgumentInScope(bname) so that confusing log error statements aren't made.- Overrides:
getArgumentSilent
in classContext
- Returns:
-
getLocalArgument
Description copied from class:Context
Get a local argument without recursing up the context tree. Only classes that extend ArgumentBasedContext will have local arguments, so this return null by default.- Overrides:
getLocalArgument
in classContext
- Returns:
-
copyArguments
Copy arguments into this Context. This is currently only used to copy a Context. This first clears any existing arguments and then performs a deep copy on the passed in arguments.- Parameters:
argumentsToCopy
-
-
addArgument
protected boolean addArgument(String bName, Class<?> javaType, Object bValue, boolean bLocal, boolean bReturn) Adds a new argument to the current context. This is convenience method to the more general addArgument. This method sets the following values for fields that are not exposed: semanticType : null isVarArgs : false defaultValue : null- Parameters:
bName
- the name of the argumentjavaType
- the java type of the argumentbValue
- the value of the argumentbLocal
- whether the argument is a local script variable or notbReturn
- whether the argument is a return variable or not- Returns:
- true if argument was added to context, false if it conflicts with existing argument with same name
-
addArgument
protected boolean addArgument(String bName, Class<?> javaType, String semanticType, Object bValue, String bDefault, boolean bLocal, boolean bReturn, boolean bIsVarArg) Adds a new argument to the current context- Parameters:
bName
- the name of the argumentjavaType
- the java type of the argumentsemanticType
- the semantic type of the argumentbValue
- the value of the argumentbDefault
- the default value of the argumentbLocal
- whether the argument is a local script variable or notbReturn
- whether the argument is a return variable or notbIsVarArg
- whether the argument is a varArg argument ()- Returns:
- true if argument was added to context, false if it conflicts with existing argument with same name
-
setArgument
Specify the (deep) value of an argument- Parameters:
bname
- the argument's nameval
- the value to which the argument should be bound
-
bindPredicate
Given the original Predicate, for each argument that is an unbound variable, create a binding and put it in a new Predicate.- Parameters:
orig
-- Returns:
- New Predicate with unbound arguments bound, if possible.
-
redistributeArguments
protected void redistributeArguments() -
bindText
Parses text and replaces args with their values.- Parameters:
inText
- text to parse- Returns:
- text with args replaced by their values
-