jess
Class Deffunction

java.lang.Object
  extended byjess.Deffunction
All Implemented Interfaces:
Named, java.io.Serializable, Userfunction, Visitable

public class Deffunction
extends java.lang.Object
implements Userfunction, java.io.Serializable, Visitable, Named

A Deffunction is a function defined in the Jess language. Note that you can create these from Java code and add them to a Rete engine using Rete.addUserfunction(jess.Userfunction).

(C) 2006 Sandia National Laboratories

See Also:
Serialized Form

Nested Class Summary
static class Deffunction.Argument
          Represents a formal parameter to a Deffunction.
 
Constructor Summary
Deffunction(java.lang.String name, java.lang.String docstring)
          Create a deffunction
 
Method Summary
 java.lang.Object accept(Visitor v)
          Deffunction participates in the visitor pattern.
 void addAction(Funcall fc)
          Add an action to this deffunction.
 void addArgument(Deffunction.Argument argument)
          Add a formal argument to this deffunction.
 void addArgument(java.lang.String name, int type)
          Add a formal argument to this deffunction.
 void addValue(Value val)
          Add a simple value to this deffunction.
 Value call(ValueVector call, Context context)
          Execute this deffunction.
 java.util.Iterator getActions()
          The body of this Deffunction
 java.util.Iterator getArguments()
          Return formal parameters to this Deffunction
 java.lang.String getConstructType()
          Identify this construct type.
 java.lang.String getDocstring()
          Fetch the documentation string of this Deffunction
 java.lang.String getName()
          Fetch the name of this Deffunction
 void setDocstring(java.lang.String ds)
          Set the documentation string of this Deffunction
 java.lang.String toString()
          Describe myself
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deffunction

public Deffunction(java.lang.String name,
                   java.lang.String docstring)
Create a deffunction

Parameters:
name - the name of the deffunction
docstring - the documentation string
Method Detail

getName

public final java.lang.String getName()
Fetch the name of this Deffunction

Specified by:
getName in interface Userfunction
Returns:
the name

getDocstring

public final java.lang.String getDocstring()
Fetch the documentation string of this Deffunction

Specified by:
getDocstring in interface Named
Returns:
the documentation string

setDocstring

public final void setDocstring(java.lang.String ds)
Set the documentation string of this Deffunction

Parameters:
ds - The documentation string

getArguments

public java.util.Iterator getArguments()
Return formal parameters to this Deffunction

Returns:
an Iterator over Deffunction.Argument objects

getActions

public java.util.Iterator getActions()
The body of this Deffunction

Returns:
an Iterator over Value objects representing the body of the Deffunction

addArgument

public void addArgument(java.lang.String name,
                        int type)
                 throws JessException
Add a formal argument to this deffunction. Only the last may be a MULTIVARIABLE. Note that arguments will appear in left-to-right order acording to the order in which they are added.

Parameters:
name - A name for the variable (without the leading '?')
type - RU.MULTIVARIABLE or RU.VARIABLE
Throws:
JessException

addArgument

public void addArgument(Deffunction.Argument argument)
                 throws JessException
Add a formal argument to this deffunction. Only the last may be a MULTIVARIABLE. Note that arguments will appear in left-to-right roder acording to the order in which they are added.

Parameters:
argument - A description of the argument
Throws:
JessException

addAction

public void addAction(Funcall fc)
               throws JessException
Add an action to this deffunction. The actions and values added to a deffunction will be stored in the order added, and thereby make up the body of the deffunction.

Parameters:
fc - the action
Throws:
JessException

addValue

public void addValue(Value val)
Add a simple value to this deffunction. The actions and values added to a deffunction will be stored in the order added, and thereby make up the body of the deffunction.

Parameters:
val - The value

call

public Value call(ValueVector call,
                  Context context)
           throws JessException
Execute this deffunction. Evaluate each action or value, in order. If no explicit (return) statement is encountered, the last evaluation result will be returned as the result of this deffunction.

Specified by:
call in interface Userfunction
Parameters:
call - The ValueVector form of the function call used to invoke this deffunction.
context - The execution context
Returns:
As described above.
Throws:
JessException - If anything goes wrong
See Also:
Value.resolveValue(jess.Context)

toString

public java.lang.String toString()
Describe myself

Returns:
a pretty-print representation of this function

accept

public java.lang.Object accept(Visitor v)
Deffunction participates in the visitor pattern.

Specified by:
accept in interface Visitable
Parameters:
v - a Visitor
Returns:
whatever the Visitor.visitDeffunction(jess.Deffunction) function returns

getConstructType

public final java.lang.String getConstructType()
Identify this construct type.

Specified by:
getConstructType in interface Named
Returns:
the string "deffunction".

© 2006 Sandia Corporation