jess
Class Deftemplate

java.lang.Object
  |
  +--jess.Deftemplate

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

Class used to parse, print and represent deftemplates.

(C) 1998 E.J. Friedman-Hill and the Sandia Corporation

See Also:
Serialized Form

Constructor Summary
Deftemplate(java.lang.String name, java.lang.String docstring)
          Constructor.
Deftemplate(java.lang.String name, java.lang.String docstring, Deftemplate dt)
          Constructor.
 
Method Summary
 void addMultiSlot(java.lang.String name, Value value)
          Create a new multislot in this deftemplate.
 void addSlot(java.lang.String name, Value value, java.lang.String typename)
          Create a new slot in this deftemplate.
 void doBackwardChaining()
          Make this deftemplate backwards-chaining reactive.
 void forgetParent()
          Sever the link with this deftemplate's parent.
 boolean getBackwardChaining()
          Get the backchaining reactivity of this deftemplate.
 java.lang.String getDocstring()
          Get the docstring of this deftemplate
 java.lang.String getName()
          Get the name of this deftemplate
 int getNSlots()
          Return the number of slots in this deftemplate
 Deftemplate getParent()
          return the parent of this deftemplate.
 int getSlotDataType(int index)
          Returns the slot data type (one of the constants in jess.RU) for the slot given by the zero-based index.
 Value getSlotDefault(int index)
          Returns the default value of a slot given by the zero-based index.
 int getSlotIndex(java.lang.String slotname)
          Return the index (0, 1, 2 ...
 java.lang.String getSlotName(int index)
          Return the name of a given slot in this deftemplate
 int getSlotType(int index)
          Returns the slot type (RU.SLOT or RU.MULTISLOT) of the slot in this deftemplate given by the zero-based index.
 java.lang.String toString()
          Turn this deftemplate into a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deftemplate

public Deftemplate(java.lang.String name,
                   java.lang.String docstring)
Constructor.
Parameters:
name - The deftemplate name
docstring - The deftemplate's documentation string

Deftemplate

public Deftemplate(java.lang.String name,
                   java.lang.String docstring,
                   Deftemplate dt)
            throws JessException
Constructor. Create a deftemplate 'derived from' another one
Parameters:
name - The deftemplate name
docstring - The deftemplate's documentation string
dt - The 'parent' of this deftemplate
Method Detail

getParent

public Deftemplate getParent()
return the parent of this deftemplate. The parent is another deftemplate this one extends, or null.
Returns:
The parent deftemplate.

forgetParent

public void forgetParent()
Sever the link with this deftemplate's parent. useful when creating similar, but unrelated deftemplates.

getName

public final java.lang.String getName()
Get the name of this deftemplate
Returns:
The name of this deftemplate

getDocstring

public final java.lang.String getDocstring()
Get the docstring of this deftemplate
Returns:
The docstring

doBackwardChaining

public final void doBackwardChaining()
Make this deftemplate backwards-chaining reactive.

getBackwardChaining

public final boolean getBackwardChaining()
Get the backchaining reactivity of this deftemplate.
Returns:
True if this deftemplate can stimulate backwards chaining.

addSlot

public void addSlot(java.lang.String name,
                    Value value,
                    java.lang.String typename)
             throws JessException
Create a new slot in this deftemplate. If the slot already exists, just change the default value.
Parameters:
name - Name of the slot
value - default value for the slot
typename - Type of the slot: INTEGER, FLOAT, ANY, etc.
Throws:
JessException - If something goes wrong

addMultiSlot

public void addMultiSlot(java.lang.String name,
                         Value value)
                  throws JessException
Create a new multislot in this deftemplate. If the slot already exists, just change the default value. Public so reflectfunctions can use.
Parameters:
name - Name of the slot
value - default value for the slot
Throws:
JessException - If something goes wrong

getSlotDataType

public int getSlotDataType(int index)
                    throws JessException
Returns the slot data type (one of the constants in jess.RU) for the slot given by the zero-based index.
Parameters:
index - The zero-based index of the slot (0, 1, 2 ... getNSlots()-1)
Returns:
The data type of that slot (RU.INTEGER, RU.ATOM, etc., or RU.NONE)

getSlotDefault

public Value getSlotDefault(int index)
                     throws JessException
Returns the default value of a slot given by the zero-based index.
Parameters:
index - The zero-based index of the slot (0, 1, 2 ... getNSlots()-1)
Returns:
The default value for that slot (can be Funcall.NIL or Funcall.NILLIST for none

getSlotType

public int getSlotType(int index)
                throws JessException
Returns the slot type (RU.SLOT or RU.MULTISLOT) of the slot in this deftemplate given by the zero-based index.
Parameters:
index - The zero-based index of the slot (0, 1, 2 ... getNSlots()-1)
Returns:
The type of that slot (RU.SLOT or RU.MULTISLOT)

getSlotIndex

public int getSlotIndex(java.lang.String slotname)
                 throws JessException
Return the index (0, 1, 2 ... getNSlots()-1) of the named slot, or -1 if there is no such slot
Parameters:
slotname - The name of the slot
Returns:
The zero-based index of the slot

getSlotName

public java.lang.String getSlotName(int index)
                             throws JessException
Return the name of a given slot in this deftemplate
Parameters:
index - The zero-based index of the slot (0, 1, 2 ... getNSlots()-1)
Returns:
The name of that slot
Throws:
JessException - If something is horribly wrong

getNSlots

public int getNSlots()
Return the number of slots in this deftemplate
Returns:
The number of slots in this deftemplate

toString

public java.lang.String toString()
Turn this deftemplate into a String
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Deftemplate

© 1997 E.J. Friedman-Hill and Sandia Corporation