Vikram-

Here's an example .clp segment using beans that I'm working on:  Note that
wxcond (stands for WeatherCondition) is the external object "registered" in
the defclass statement.  The OBJECT is the external reference, and the
?wxcond (in your case the ?bulb) is the handle to that reference.  You can
then call methods (not just get and set) of the Java Bean from Jess-see the
setElementStatus and issueWarning method calls below.  Note also that you
can create instances of classes from Java as well using the Funcall class
(see below).

(defclass wxcond jess.examples.wc8.WeatherCondition)

(defrule high-dp
  "Dewpoint higher than temperature - severity red"
  (wxcond (id ?id) (intInitVal ?initVal) (tempC ?tempC) (dewpointC
?dewpointC)
          (OBJECT ?wxcond))
  (test (<> ?initVal ?tempC))
  (test (<> ?initVal ?dewpointC))
  (not (warning dp ?id))
  (test (< ?tempC ?dewpointC))
  =>
  (assert (warning dp ?id))
  (printout t "WARNING: ID " ?id  " dewpoint higher than temp." crlf)
  (set ?wxcond redWarning TRUE)
  (?wxcond setElementStatus "dewpointC" "red")
  (?wxcond setElementStatus "tempC" "red")
  (?wxcond issueWarning "Dewpoint higher than temp." "red" "high-dp"))

Creating instance from Java:

                WeatherCondition wc = new WeatherCondition();
                reteEngine = new Rete((args for i.o));

                try
                {
                        Funcall f = new Funcall("definstance", reteEngine);
                        f.add(new Value("wxcond", RU.ATOM));
                        f.add(new Value(wc, RU.EXTERNAL_ADDRESS));
                        f.simpleExecute(f, reteEngine.globalContext());
                }
                catch (ReteException re)
                {
                        System.out.println("ERROR DURING WeatherCondition FUNCALL 
CALL");
                }

Hope this helps...

//Darryl Leon//

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Alan Moore
Sent: Thursday, January 27, 2000 2:17 PM
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: JESS: Referencing instances of JavaBeans in Jess

I *think* you need to do something like this (?l is just the shadow fact
id):

(defclass Sphere Sphere)
(defclass LightBulb LightBulb)
(definstance LightBulb (new LightBulb "Halogen" 30))
(definstance LightBulb (new LightBulb "Floroscent" 40))

(defrule Rule1
    (LightBulb (OBJECT ?bulb) (type "Halogen") (visRep))
     =>
     (bind ?sphere (new Sphere))
     (definstance Sphere ?sphere dynamic)
     (call ?bulb setVisRep ?sphere)
)
(run)


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 27, 2000 7:58 AM
> To: [EMAIL PROTECTED]
> Subject: JESS: Referencing instances of JavaBeans in Jess
>
>
>
> Can somebody help me in determining how to refer the
> instances of JavaBeans
> in Jess as for following example?
>
> ON JAVA  SIDE
> Two JavaBeans "Sphere", "LightBulb" are defined as follows
>
> class LightBulb {
>      private String type;
>      private int watts;
>      private Object visRep;
>
>      public LightBulb{}
>
>      public LightBulb(String type, int watts) {
>           ...
>      }
>      get/set methods and propert_change_support_methods...
> }
>
> class Sphere {
>      private float center;
>      private float radius;
>
>      get/set methods and propert_change_support_methods...
> }
>
>
> ON JESS SIDE
>
> (defclass Sphere Sphere)
> (defclass LightBulb LightBulb)
> (definstance LightBulb (new LightBulb "Halogen" 30))
> (definstance LightBulb (new LightBulb "Floroscent" 40))
>
> (defrule Rule1
>     ?l <- (LightBulb (type "Halogen") (visRep))
>      =>
>      (bind ?sphere (new Sphere))
>      (definstance Sphere ?sphere dynamic)
>      (call ?l setVisRep ?sphere)
> )
> (run)
>
>
> Here we try to determine if lightbulb is of halogen type then set its
> visual representation as spherical shape.
> BUT ABOVE STMT (call ?l setVisRep ?sphere) fails.
>
> 1. Since after creation of JavaBeans in Jess, it creates
> shadow image as
> facts, now problem arises when trying to define rules which
> work over the
> facts and how to refer instances of JavaBeans corresponding
> to facts as in
> above case.
>
> 2. In Jess, the fact created corresponding to first instance
> of LightBulb
> is as follows
>     (LightBulb (class <External-Address::java.lang.Class>)
> (type "Halogen")
> (watts 30) (visRep nil) (OBJECT <External-Address::LightBulb>)
>
>     Does this OBJECT slotv alue refers to same instance of
> JavaBean?? Is it
> same as if I refered by "lb" variable as follows
>
> (bind ?lb (new LightBulb "Halogen" 30))
> (definstance LightBulb ?lb dynamic)
>
> 3. When I try to make any change to the corresponding JavaBean, Jess
> removes the original fact and creates a new fact with
> modified image of the
> JavaBean.
>
>
> Thanks in advance for any comments/help.
>
> Regards,
> Vikram
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users
> [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list (use your own address!) List problems? Notify
> [EMAIL PROTECTED]
> ---------------------------------------------------------------------
>
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify
[EMAIL PROTECTED]
---------------------------------------------------------------------

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

Reply via email to