JESS: Problem calling java methods from Jess with Object parameters

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

JESS: Problem calling java methods from Jess with Object parameters

Richard, Kevin R.
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 | Threaded
Open this post in threaded view
|

Re: JESS: Problem calling java methods from Jess with Object parameters

friedman_hill ernest j
I think Richard, Kevin R. wrote:

>   ;; 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.

In the constructor call, that ought to be the variable "?elem", not
the symbol "elem", right?  If this is just a typo in your email, as
opposed to the rule itself, then can you show me the declaration of
the constructor you're trying to call, and also let me know what
version of Jess you're using?


---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [hidden email]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

RE: JESS: Problem calling java methods from Jess with Object parameters

Richard, Kevin R.
In reply to this post by Richard, Kevin R.
Yup, my mistake; the first argument should be '?elem'.  Here is the
constructor:

  public void MyObject(MyObject parent, String type)
  {
    setType(type);
    this.parent = parent;
  }

I'm using version 70b1.

Thanks.

- Kevin

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of [hidden email]
Sent: Tuesday, August 30, 2005 10:21 AM
To: [hidden email]
Subject: Re: JESS: Problem calling java methods from Jess with Object
parameters

I think Richard, Kevin R. wrote:

>   ;; 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.

In the constructor call, that ought to be the variable "?elem", not the
symbol "elem", right?  If this is just a typo in your email, as opposed
to the rule itself, then can you show me the declaration of the
constructor you're trying to call, and also let me know what version of
Jess you're using?


---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [hidden email]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list (use
your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Problem calling java methods from Jess with Object parameters

friedman_hill ernest j
I think Richard, Kevin R. wrote:
> Yup, my mistake; the first argument should be '?elem'.  Here is the
> constructor:
>
>   public void MyObject(MyObject parent, String type)

That's not a constructor -- it's a method returning void whose name
just happens to be the same as the class. You couldn't construct an
object with this from Java code, either. Remove that "void" and you
should be OK.

---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [hidden email]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------