How do I match a property of a property of a Java Bean 
in a Jess rule and bind it to a variable? Does Jess 
support nested properties?

I have two Java Beans Trade and Security: 

    public class Trade()
    {
        /* requestId property */
        private int mRequestId
        public int getRequestId() { return mRequestId; }
        public void setRequestId(int r) { mRequestId = r; }

        /* security property */
        private Security mSecurity;
        public Security getSecurity() { return mSecurity; }
        public void setSecurity(Security s) {mSecurity = s;}
    }

    public class Security()
    {
        /* secId property */
        private String mSecId;
        public String getSecId() { return mSecId; }
        public void setSecurity(String s) { mSecId = s; }

        /* secType property */
        private String mSecType;
        public String getSecType() { return mSecType; }
        public void setSecType(String s) { mSecType = s; }

    }

The Trade java bean has two properties - requestId and security.
The Security java bean has two properties - secId and secType.

I am asserting both the Trade and its Security object in Java
code as follows:

        /* assert Trade */
        Funcall lFuncall = new Funcall("definstance", mRete);
        lFuncall.add(new Value(aName, RU.ATOM));
        lFuncall.add(new Value(aTrade));
        lFuncall.execute(mRete.getGlobalContext());

        /* assert Security*/
        lFuncall = new Funcall("definstance", mRete);
        lFuncall.add(new Value(aName, RU.ATOM));
        lFuncall.add(new Value(aTrade.getSecurity()));
        lFuncall.execute(mRete.getGlobalContext());

I am trying to write the following rule (pseudocode):

    when a trade and its corresponding security asserted
    get the security associated with the trade
    get the secType of the security
    if secType is CASH
        (assert trade-is-cash ?requestId)

Why doesn't Jess accept the following:
(defrule is-cash
    (trade (requestId ?requestId) (security ?security))
    (?security (secType "CASH"))
  =>
    (assert trade-is-cash ?requestId)
)

Or using nested properties:
(defrule is-cash
    (trade (requestId ?requestId) (security.secType CASH))
  =>
    (assert trade-is-cash ?requestId)
)

-Shoeb


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.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]
--------------------------------------------------------------------

Reply via email to