Thanks for your help Phil, I'll take a look at this to digest you method.
Very much appreciate your reply!!

-----Original Message-----
From: phil [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 15, 2002 7:14 PM
To: [EMAIL PROTECTED]
Subject: RE: JESS: Q: Java w/Jess


Hey Joey,
I had a simple scheduling application where I created a scheduled course
beans.  I beat my head against the wall for some time trying to figure
out how to create a bean and send addressability to it back to Java.  In
my case I was creating a linked list of scheduled courses and I only
returned the head of the list to Java.  Of course I would not have been
able to make this work without the help of Ernest. 

I built a wrapper around the JESS Rule engine to do the basic rule
engine functions and that has the simple methods parseRules, addObjects,
and fireRules.  These were the basic rule engine operations described in
JSR-000094.  I later added getRete because addressability to the rete
object was required to do a fetch.  The wrapper is attached.


Here is the rule:

(defrule AnyRoomThreeCreditClass
 (declare (salience +500))
        (FocusOfAttention  BuildSchedule)
 ?SN <- (ScheduleNext  ?RD) 
 ?CS <- (Course (ID ?ID) (Dept $? ?Dept $?))
 ?RC <- (RequestedCourse (ID ?ID) (processed FALSE) (OBJECT ?C))
 ?R  <- (availableRoom (RoomDay ?RD) (RoomTimeSlot ?RT))   
 ?P  <- (availableProfessor  (ProfessorName ?N) (ProfessorDept $? ?Dept
$?))
        (not (ScheduledCourse (day ?RD) (timeSlot ?RT) (professorName
?N))) 
  =>
        (printout t "Course Requested: "  ?Dept  crlf)
        (schedule-course ?SN ?R ?RD ?P ?RC ?C ?CS)
)

Here is the schedule-course function where I do a "store" of the head of
the list for the first course scheduled:

(deffunction schedule-course (?SchedNext ?Room ?RoomDay ?Professor
?RequestedCourse ?RCO ?CS)
        (bind ?SC (new AcademicScheduling.bin.ScheduledCourse))
        (definstance ScheduledCourse ?SC static)
        (call ?SC setID (gav ?RequestedCourse ID))
        (call ?SC setDay ?RoomDay)
        (call ?SC setName (gav ?CS Name))
        (call ?SC setRoom (gav ?Room RoomNumber))
        (call ?SC setBuilding (gav ?Room RoomBuilding))
        (call ?SC setTimeSlot (gav ?Room RoomTimeSlot))
        (call ?SC setProfessorName (gav ?Professor ProfessorName))      
        (call ?SC setNext nil)
        
        (bind ?*SCCount* (+ ?*SCCount* 1))
        (if (= ?*SCCount* 1) then
                (store "headOfList" ?SC))

        (if (neq ?*previousCourse* nil) then
                (call ?*previousCourse* setNext ?SC))
                        
        (retract ?SchedNext)
        (if (= (str-compare ?RoomDay "M/W/F") 0) then
                (assert (ScheduleNext "T/TH"))
         else
                (assert (ScheduleNext "M/W/F")))
                
        (retract ?Room)
        (retract ?Professor)
        (bind ?*previousCourse* ?SC)
        (set ?RCO processed TRUE)           
)


and here is the java to retrieve the results, put the head of the list
in tempCourse and later pass it on to a frame object that will display
the whole list:

                try
                {
   tempCourse =
(ScheduledCourse)ruleengine.getRete().fetch("headOfList").externalAddres
sValue(null);
                  }
        catch (JessException re)
                  {
                        re.printStackTrace();
                        System.out.println("Jess Exception ");
                  }


Thanx Again Ernest!



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
On Behalf Of Garcia Joey J Contr SMC Det 12/VOC
Sent: Thursday, August 15, 2002 6:37 PM
To: '[EMAIL PROTECTED]'
Subject: JESS: Q: Java w/Jess

Greetings:

I was wondering if you had a moment for a Java/Jess question?  

If so, we are using Jess with Java, and our application passes in a
JavaBean
that has the data needed to run against our rules.  The original plan
was to
have Jess put the results into a ResultBean but we just can't seem to
figure
out how to cast a Value object to our own custom JavaBean (i.e.,
ResultBean), therefore we are stuck with a Value object that can't be
cast
into another object type.

We are guessing that this may have something to do with the
external_address, but we don't know what a "Context" is or how to use
it?
The documentation is vague to us on this topic.

We used this line of code to try to get our ResultBean back out: Value
rbValue = rete.fetch("JessResults");

And after this, we tried everything we could think of to get it to be a
bean
again but nothing worked.  We tried both passing in a Bean, and creating
one
inside our .clp file, neither approach yielded us any success.


Below is the contents of our .clp file (reflecting our last approach):

(defglobal ?*count* = 0)
(defglobal ?*flag* = 0)
(defglobal ?*cdb* = nil)
(defglobal ?*rbean* = nil)

(set-reset-globals nil)

(defrule test-100
=>
(bind ?*rbean* (new mil.af.dtb.cabr.ResultBean))
(call ?*rbean* setvehFamily "Family2")
(call ?*rbean* setvehNumber "6450")
(bind ?antrad (fetch ANT-RAD-STATUS))
(if (neq ?antrad nil)
        then 
          (bind ?antstat (call ?antrad getvalue))
          (bind ?antnm (call ?antrad getname))
          (printout t "--name--------- " ?antnm crlf)
          (assert (input-1 ?antstat))))


(defrule compute-result-A
   (input-1 ?a&:(eq 0 (str-compare ?a "passive")))
  =>
   (call ?*rbean* setsecAssessmentAnomaly 2 )
   (call ?*rbean* setpriAA1ColorCode 1)
   (printout t "--sending assesment 2 color 1" crlf)
   (store JessResults ?*rbean* ))
   )

(defrule compute-result-A1
   (input-1 ?a&:(eq 0 (str-compare ?a "active")))
  =>
   (call ?*rbean* setsecAssessmentAnomaly 4 )
      (call ?*rbean* setpriAA1ColorCode 3)
      (printout t "--sending assesment 4 color 3" crlf)
      (store JessResults "test"))
   )


This .clp file should set the family name and the vehicle number at a
minimium.


Thanks in advance,

        Joey

*****************************************************
Senior Software Engineer, Lockheed Martin M.S.
Center For Research and Support (CERES)
    Schriever AFB, Colorado Springs, CO
(719) 567-8463, [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