Thanks for your suggestion.
The modified JESS code snippet now looks like the following one:

(defrule myRule
        ?fA <- (factA (slotA_name...) (slotB_name...))
        ?fB <- (factB (slotC_name...) (slotD_name...))
=>
(bind ?fC (assert 
                (factC 
                        (slotE_name (?fA getSlotValue OBJECT))
                        (slotF_name...)
                )
        ))
)
(call-my-java-method (?fc getSlotValue OBJECT)))

I've used getSlotValue method two times in order to show you the following
behaviour:

The first one getSlotValue call works correctly and the actual ?fA fact is
stored into slotE_name.
The second call (?fc getSlotValue OBJECT)  returns  NIL both if used into
the JESS side (as shown above) and if used in Java with
val.factValue(context).getSlotValue("OBJECT").
What's wrong in the binding operation?

Thanks in advance
  Marco Zappatore





Ernest Friedman-Hill wrote:
> 
> Nothing wrong with that, if that's what you need to do. Every shadow  
> fact also has a slot named OBJECT which contains the actual object,  
> and so if you wanted to match that, you could call "getClass()" on it  
> rather than using Class.forName().
> 
> Note if you use getShadowClassName() as suggested below, then you'll  
> get the name of the class used to define the template, which might be  
> an interface (in which case you can't instantiate it, of course.) If  
> you use the OBJECT slot, as I suggest, then you'll get the actual  
> class of the object behind the fact, and that may or may not be what  
> you actually want.
> 
> 
> 
> On Nov 3, 2009, at 7:26 AM, Marco Zappatore wrote:
> 
>>
>> I think that a possible solution could be the following
>>
>> val.factValue(context).getDeftemplate().getShadowClassName()
>>
>> and then instantiate a new instance starting from the string that  
>> the above
>> method returns...
>>
>> In any case, I'd like to know your opinion...
>>
>>
>>
>> Marco Zappatore wrote:
>>>
>>> Dear Jess users,
>>> I have a rule "myrule" that fires whenever two facts with specific  
>>> slot
>>> contents are found within the working memory.
>>> These facts are shadow facts.
>>> Then I have a java user function "myUserFunction" that passes those  
>>> two
>>> facts (using their pointers, let's say ?f1 and ?f2) to a Java  
>>> program.
>>> My question is: is it possible to get those facts and instantiate  
>>> them
>>> again in Java?
>>> In other words the procedure is:
>>> 1) define a java bean
>>> 2) assert shadow facts from that java bean with different slot  
>>> contents
>>> each time
>>> 3) find a given fact with a given content using a proper rule
>>> 4) pass the fact to a java program
>>> 5) create a new instance of the java bean with the content just  
>>> retrieved
>>>
>>> the problem resides at point n°5 because actually I'm using
>>> Value val = vv.get(1).resolveValue(context);
>>> Using val.factValue(context)) I can verify that the content is  
>>> correct but
>>> how can I use val to instantiate a new Java Bean?
>>>
>>> Any help is appreciated, thanks in advance.
>>>
>>> Marco Zappatore
>>>
>>
>> -- 
>> View this message in context:
>> http://old.nabble.com/Retrieve-facts-from-Jess-and-re-instantiate-them-in-Java-tp26160053p26160091.html
>> Sent from the Jess mailing list archive at Nabble.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] 
>> .
>> --------------------------------------------------------------------
> 
> ---------------------------------------------------------
> 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