I understand the principle.
That's true the following code give me an access to the java object:
(defrule validate-virtualsite
    (VirtualSite (inetModem ?inetModem))
    =>
    (printout t "Virtual site: " ?inetModem crlf)
)
With the following output :
Virtual site: <Java-Object:be.uniway.rvk.jesstest.model.InetModem>

But (because there's sadly a but)

The notation with the Object slot doesn't seems to work. Eclipse warn me with 
this message if it can help:
Created implied ordered template at token 'OBJECT'

I'm completely lost :/

Thanks for your help!

Romain Van der Keilen.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of Ernest Friedman-Hill
Sent: vendredi 21 août 2009 17:14
To: jess-users
Subject: Re: JESS: Accessing Java objects fields from a defrule

Ah, OK, here's the thing: your patterns


   ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress))
                 (VirtualSite (inetModem ?inetModem))

are checking that the jess.Fact object representing the InetModem in
working memory is in the inetModem slot of the VirtualSite fact -- but
it's not. The inetModem slot contains the actual Java InetModem
object. You get at that object by using the OBJECT slot, not by
binding the whole fact:


    (InetModem (publicIpAddress ?publicIpAddress) (OBJECT ?inetModem)
    (VirtualSite (inetModem ?inetModem))

That should do you.



On Aug 21, 2009, at 11:04 AM, Romain Van der Keilen wrote:

> All getters and setters are present, respecting the jababeans
> conventions:
>
> Those methods are in Virtualsite
>        public InetModem getInetModem() {
>                return inetModem;
>        }
>        public void setInetModem(InetModem inetModem) {
>                this.inetModem = inetModem;
>        }
> And those are in InetModem
>        public String getPublicIpAddress() {
>                return publicIpAddress;
>        }
>        public void setPublicIpAddress(String publicIpAddress) {
>                this.publicIpAddress = publicIpAddress;
>        }
>
> So I don't really see what's wrong ...
>
> Thanks,
>
> Romain Van der Keilen.
>
> -----Original Message-----
> From: [email protected] [mailto:owner-jess-
> [email protected]] On Behalf Of Ernest Friedman-Hill
> Sent: vendredi 21 août 2009 16:54
> To: jess-users
> Subject: Re: JESS: Accessing Java objects fields from a defrule
>
>
> Normally, slots in Jess templates are based on JavaBeans properties --
> i.e., a method named "getInetModem" will give rise to a slot named
> "inetModem". If you include the "include-variables TRUE" declaration,
> then  slots will also be created based on *public* member variables.
> Under no circumstances will Jess create slots based on private member
> variables.
>
>
>
> On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote:
>
>> Here is the exact code I use:
>>
>> (import be.uniway.rvk.jesstest.model.*)
>> (deftemplate VirtualSite        (declare (from-class VirtualSite)))
>> (deftemplate InetModem          (declare (from-class InetModem)))
>>
>> (defrule validate-virtualsite
>>       "Just put the validate attribute to true!"
>>   ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress))
>>                 (VirtualSite (inetModem ?inetModem))
>>   =>
>>   (printout t "Internet modem address: " ?publicIpAddress crlf)
>> )
>>
>>
>> Using:
>>
>> VirtualSite
>> + private InetModem inetModem
>>
>> InetModem
>> + private String publicIpAddress
>>
>> Maybe the private fields are disturbing Jess?
>>
>> Regards,
>>
>> Romain Van der Keilen.
>>
>>
>>
>> From: [email protected] [mailto:owner-jess-
>> [email protected]] On Behalf Of Romain Van der Keilen
>> Sent: vendredi 21 août 2009 16:15
>> To: [email protected]
>> Subject: RE: JESS: Accessing Java objects fields from a defrule
>>
>> Thanks for the response,
>>
>> You've exactly put the finger on what I wish do, but I just tried
>> that and I've no output :s
>>
>> From: [email protected] [mailto:owner-jess-
>> [email protected]] On Behalf Of Wolfgang Laun
>> Sent: vendredi 21 août 2009 15:41
>> To: [email protected]
>> Subject: Re: JESS: Accessing Java objects fields from a defrule
>>
>> First, you bind to the contained object, and then you locate the
>> containing object.
>>
>> (defrule mydoor
>>  ?door <- (Door (weight ?weight)(color ?color))
>>                 (House (myDoor ?door)(owner "Mick"))
>> =>
>>  (printout t "Weight of Mick's door :" ?weight crlf)
>> )
>>
>> Restrictions on weight or color, e.g., to paint red doors black ;-)
>> can be added in the usual way.
>>
>> -W
>> On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen 
>> <[email protected]
>>> wrote:
>> Hi there,
>>
>> I have a little question for you I can't fix by myself: how to
>> access the fields of a java Object that is itself a field of an
>> other java object?
>> Here is a tiny sample :
>>
>> Object Door
>> + int weight
>> + String color
>>
>> Object House
>> + Door myDoor
>>
>> Now I give the House to the Rete engine, how can I access (and
>> manipulate) for example the weight of my door?
>>
>> By now I just can display it like this:
>> (defrule mydoor
>>  (House (myDoor ?myDoor))
>>  =>
>>  (printout t "Weight of my house's door :" ?myDoor.weight crlf)
>> )
>> But the thing I want to do is to catch that weight to make some
>> checks on it, then displaying the checks' results (for examples, is
>> my door heavier than 25kg).
>>
>> Thanks for help
>>
>> Romain Van der Keilen
>>
>>
>>
>> --------------------------------------------------------------------
>> 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]
>> .
>> --------------------------------------------------------------------
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences          Phone: (925) 294-2154
> Sandia National Labs
> PO Box 969, MS 9012                            [email protected]
> Livermore, CA 94550                             http://www.jessrules.com
>
>
>
>
>
> --------------------------------------------------------------------
> 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]
> .
> --------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







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