// The goal of this class is to make the name of the currently firing // rule available to that rule's RHS. Oh, the pain! import jess.*; public class CurrentRuleName implements JessListener { private String m_name; // Only one of these objects should be created, ideally bound to a // global variable. The constructor will install the listener with // the engine it must have as an argument. public CurrentRuleName(Rete engine) { engine.addJessListener(this); engine.setEventMask(engine.getEventMask() | JessEvent.DEFRULE_FIRED); } // The event handler will store the rule's name in this object, // making it available to JESS code. public void eventHappened(JessEvent je) { if (je.getType() == JessEvent.DEFRULE_FIRED) m_name = ((Defrule) je.getObject()).getName(); } // The bean-like method (not that this is intended to be used in // defclass, you understand). public String getName() { return m_name; } }