jess
Class Context

java.lang.Object
  extended byjess.Context
All Implemented Interfaces:
java.io.Serializable

public class Context
extends java.lang.Object
implements java.io.Serializable

A Context represents a scope in which variables can be declared. It also holds a pointer to a Rete object in which code can be executed.

You can use getVariable(java.lang.String) and setVariable(java.lang.String, jess.Value) to get and change the value of a variable from Java code, respectively.

The function getEngine() gives any Userfunction access to the Rete object in which it is executing. When a Userfunction is called, a Context argument is passed in as the final argument. You should pass this jess.Context to any methods you call that expect a Context argument themselves. you make.

(C) 2005 Sandia National Laboratories

See Also:
Serialized Form

Constructor Summary
Context(Context c)
          Create a new context subordinate to an existing one.
Context(Context c, Rete engine)
          Create a new context subordinate to an existing one.
 
Method Summary
 void addDebugInfo(Funcall funcall)
           
 void clearReturnValue()
          Clear the return flag and return value for this context.
 Value getBindingVariable(java.lang.String varName)
           
 Rete getEngine()
          Returns the Rete engine associated with this context.
 Fact getFact()
          If this context represents a join network node from a rule LHS, this will return the right input of the node.
 Funcall getFuncall()
           
 LineNumberRecord getLineNumberRecord()
           
 jess.LogicalNode getLogicalSupportNode()
          If this context represents the RHS of a rule which is firing, and the LHS of the rule has provided logical support, this method will return the LogicalNode that lends support.
 Context getParent()
           
 Value getReturnValue()
          Get the value set via setReturnValue
 Token getToken()
          If this context represents a join network node from a rule LHS, this will return the left input of the node.
 Value getVariable(java.lang.String name)
          Get the value of a variable
 java.util.Iterator getVariableNames()
           
 boolean isVariableDefined(java.lang.String name)
          Report whether a variable has a value in this context
 Context pop()
          Pop this context off the execution stack.
 Context push()
          Create and return a new context subordinate to this one.
 boolean returning()
          Returns true if the return flag has been set in this context.
 void setExistingVariable(java.lang.String name, Value value)
          Set an existing variable in an ancestor of this context to a value; if no existing variable, value is set in this context.
 Value setReturnValue(Value val)
          Set the return flag to true, and supply a value to be returned.
 void setVariable(java.lang.String name, Value value)
          Set a variable in this context to some type and value.
 java.lang.String toString()
          Returns a useful debug representation of the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Context

public Context(Context c)
Create a new context subordinate to an existing one. The method getEngine() will return c.getEngine(). Use push() instead of calling this directly.

Parameters:
c - The parent for the new context
See Also:
push()

Context

public Context(Context c,
               Rete engine)
Create a new context subordinate to an existing one. The method getEngine() will return the given Rete object.

Parameters:
c - The parent for the new context
engine - The value to be returned from getEngine
Method Detail

getToken

public final Token getToken()
If this context represents a join network node from a rule LHS, this will return the left input of the node.

Returns:
The Token

getFact

public final Fact getFact()
If this context represents a join network node from a rule LHS, this will return the right input of the node.

Returns:
The Fact object

getLogicalSupportNode

public final jess.LogicalNode getLogicalSupportNode()
If this context represents the RHS of a rule which is firing, and the LHS of the rule has provided logical support, this method will return the LogicalNode that lends support.

Returns:
The supporting node.

returning

public final boolean returning()
Returns true if the return flag has been set in this context. The Jess (return) function sets the return flag in the local context.

Returns:
The value of the return flag

setReturnValue

public final Value setReturnValue(Value val)
Set the return flag to true, and supply a value to be returned.

Parameters:
val - The value that should be returned from this context
Returns:
The argument

getReturnValue

public final Value getReturnValue()
Get the value set via setReturnValue

Returns:
The return value

clearReturnValue

public final void clearReturnValue()
Clear the return flag and return value for this context.


getVariableNames

public java.util.Iterator getVariableNames()

getEngine

public final Rete getEngine()
Returns the Rete engine associated with this context.

Returns:
The engine to use with this context

push

public Context push()
Create and return a new context subordinate to this one.

Returns:
The next context

pop

public Context pop()
Pop this context off the execution stack. If this context has no parent, just return this context. If it has a parent, transfer the values of the return flag and the return value to the parent, then return the parent.

Returns:
The context as described

getParent

public Context getParent()

getVariable

public Value getVariable(java.lang.String name)
                  throws JessException
Get the value of a variable

Parameters:
name - The name of the variable with no leading '?' or '$' characters
Throws:
JessException - If the variable is undefined

isVariableDefined

public boolean isVariableDefined(java.lang.String name)
                          throws JessException
Report whether a variable has a value in this context

Parameters:
name - The name of the variable with no leading '?' or '$' characters
Throws:
JessException

setVariable

public void setVariable(java.lang.String name,
                        Value value)
                 throws JessException
Set a variable in this context to some type and value. Defglobals are always set in the global context.

Parameters:
name - Name of the variable
value - The value of the variable
Throws:
JessException

setExistingVariable

public void setExistingVariable(java.lang.String name,
                                Value value)
                         throws JessException
Set an existing variable in an ancestor of this context to a value; if no existing variable, value is set in this context.

Parameters:
name - Name of the variable
value - The value of the variable
Throws:
JessException

addDebugInfo

public void addDebugInfo(Funcall funcall)
                  throws JessException
Throws:
JessException

toString

public java.lang.String toString()
Returns a useful debug representation of the context.

Returns:
A string with information about this context.

getFuncall

public Funcall getFuncall()

getLineNumberRecord

public LineNumberRecord getLineNumberRecord()

getBindingVariable

public Value getBindingVariable(java.lang.String varName)
                         throws JessException
Throws:
JessException

© 2006 Sandia Corporation