Title: Problem calling java methods from Jess with Object parameters

I have an application that stores and asserts facts in java and refers to these facts from Jess.  All facts use a similar template that includes a link to a Java object.  The template is created using java code similar to:

      ...
      String desc = new String("Element Template for type - " + type);
      template = new Deftemplate(type, desc, engine);
      template.addSlot("__element", Funcall.NIL, "OBJECT");
      …

and the object slot is filled with code:

      MyObject elem = new MyObject();
      ...
      f = new Fact(elem.getType(), engine);
      f.setSlotValue(OBJECT_SLOT_NAME, new Value(elem));

I can access, and call methods on, the object within a rule with code similar to:

(defrule thickness_throw_rule
  ?line <- (PDF_OBJ_MARKING_LINE(PDF_ATR_MARKING_LINE_TYPE "BEAM"))
  =>
  (bind ?elem (fact-slot-value ?line __element))
  (call ?elem print "print this")  ;; works fine
  (printout t "element = " ?elem)  ;; prints the full path of MyObject
  ;; the next line will fail
  ;; Jess complains about not finding the constructor
  (bind ?thickness_throw (new MyObject elem "PDF_ATR_MARKING_LINE_CURVE"))

The rule above attempts to generate a new object using the object that I retrieved from the fact as an argument to its constructor.  However, Jess can't find the constructor.  Using the empty constructor on MyObject works, however.  Also, passing the object retrieved from the fact to another method on the instantiated object does not work either.  I suspect that Jess is not casting the object that I use in the method call to the correct type.

Am I doing something wrong?

Thanks.

Kevin Richard
Northrop Grumman IT
Defense Enterprise Solutions
55 Walkers Brook Drive
Reading, Ma 01867
781.205.7748

Reply via email to