jess
Class Deftemplate

java.lang.Object
  extended byjess.Deftemplate
All Implemented Interfaces:
Modular, java.io.Serializable, Visitable

public class Deftemplate
extends java.lang.Object
implements java.io.Serializable, Visitable, Modular

Class used to represent Jess deftemplates.

(C) 2003 E.J. Friedman-Hill and the Sandia Corporation
$Id: Deftemplate.java,v 1.4 2003/03/24 15:49:04 ejfried Exp $

See Also:
Serialized Form

Constructor Summary
Deftemplate(java.lang.String name, java.lang.String docstring, Deftemplate dt, Rete engine)
          Create a deftemplate 'derived from' another one.
Deftemplate(java.lang.String name, java.lang.String docstring, Rete engine)
          Create a template.
 
Method Summary
 java.lang.Object accept(Visitor v)
           
 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.
 boolean equals(java.lang.Object o)
           
 void forgetParent()
          Sever the link with this deftemplate's parent.
 Deftemplate getBackchainingTemplate(Rete engine)
           
 java.lang.String getBackchainingTemplateName()
           
 boolean getBackwardChaining()
          Get the backchaining reactivity of this deftemplate.
 java.lang.String getBaseName()
          Get the name of this deftemplate unqualified by the module name
static Deftemplate getClearTemplate()
          The template for a special fact used internally by Jess.
 java.lang.String getDocstring()
          Get the docstring of this deftemplate
static Deftemplate getInitialTemplate()
          The template for "initial-fact".
 java.lang.String getModule()
           
 java.lang.String getName()
          Get the name of this deftemplate qualified by the module name
 java.lang.String getNameWithoutBackchainingPrefix()
           
 int getNSlots()
          Return the number of slots in this deftemplate
static Deftemplate getNullTemplate()
          The template for a special fact used internally by Jess.
 Deftemplate getParent()
          Return the parent of this deftemplate.
static Deftemplate getRootTemplate()
          All deftemplates ultimately extend this root template.
 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 through getNSlots()-1) of the named slot, or -1 if there is no such slot.
 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.
 int hashCode()
           
 boolean isBackwardChainingTrigger()
           
 java.lang.String toString()
          Turn this deftemplate into a String
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deftemplate

public Deftemplate(java.lang.String name,
                   java.lang.String docstring,
                   Rete engine)
            throws JessException
Create a template.

Parameters:
name - The deftemplate name
docstring - The deftemplate's documentation string

Deftemplate

public Deftemplate(java.lang.String name,
                   java.lang.String docstring,
                   Deftemplate dt,
                   Rete engine)
            throws JessException
Create a deftemplate 'derived from' another one. If the name contains a module name, it will be used. Otherwise, the template will be in the current module.

Parameters:
name - The deftemplate name
docstring - The deftemplate's documentation string
dt - The 'parent' of this deftemplate
Method Detail

getRootTemplate

public static Deftemplate getRootTemplate()
All deftemplates ultimately extend this root template.

Returns:
The singleton root template.

getInitialTemplate

public static Deftemplate getInitialTemplate()
The template for "initial-fact".

Returns:
A deftemplate.

getClearTemplate

public static Deftemplate getClearTemplate()
The template for a special fact used internally by Jess.

Returns:
A deftemplate

getNullTemplate

public static Deftemplate getNullTemplate()
The template for a special fact used internally by Jess.

Returns:
A deftemplate

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()

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 qualified by the module name

Specified by:
getName in interface Modular
Returns:
The name of this deftemplate

getBaseName

public final java.lang.String getBaseName()
Get the name of this deftemplate unqualified by the module name

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)
Throws:
JessException

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
Throws:
JessException

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)
Throws:
JessException

getSlotIndex

public int getSlotIndex(java.lang.String slotname)
                 throws JessException
Return the index (0 through 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
Throws:
JessException

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

Returns:
a string representation of the Deftemplate

accept

public java.lang.Object accept(Visitor v)
Specified by:
accept in interface Visitable

getModule

public java.lang.String getModule()
Specified by:
getModule in interface Modular

isBackwardChainingTrigger

public boolean isBackwardChainingTrigger()

getBackchainingTemplateName

public java.lang.String getBackchainingTemplateName()

getNameWithoutBackchainingPrefix

public java.lang.String getNameWithoutBackchainingPrefix()

getBackchainingTemplate

public Deftemplate getBackchainingTemplate(Rete engine)
                                    throws JessException
Throws:
JessException

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