Re: JESS: Userfunctions and Jess - Java type conversion

2005-12-01 Thread ejfried
I think erich.oliphant wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
 Hmm, ok thanks, I understand better now.  However, jess.Userfunctions return
 Value's so is there anything I can do in that case to activate the type
 conversion?  I tried Value.resolve() but that did not help.
 

You know, there's not actually a public API for getting Jess to do
those conversions on demand from Java, although you've made a good
case as to why there should be. The method you want is the static
method jess.ReflectFunctions.objectToValue(), which takes two
arguments, the object and the class of the Object; this is so that you
can pass (for example) java.lang.Boolean as a Boolean.class or as a
Boolean.TYPE -- i.e., a primitive. You could simply use obj and
obj.getClass() as the two arguments. Since it's private, you could
either change the source to make it public, or you could call the method
reflectively using something like

   Object prop = ...
   Method oTV = 
Class.forName(jess.ReflectFunctions).getMethod(objectToValue);
   oTV.setAccessible(true);
   Value result = (Value) oTV.invoke(null, new Object[] {prop, 
prop.getClass()});

Of course, you'd probably want to get the Method object and cache it
in a member variable someplace, and then stick all of this into your
own objectToValue method.


-
Ernest Friedman-Hill  
Advanced Software Research  Phone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov


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]




Re: JESS: Userfunctions and Jess - Java type conversion

2005-12-01 Thread ejfried
I think erich.oliphant wrote:
 I tried that function, but it doesn't seem to exist on the
 jess.ReflectFunctions class (I am using 7.0 beta 4.  There seems to be a a
 static Value a(Class, Object) throws JessException method based on browsing
 the class file. Could this be it?  

You're not using a licensed version of Jess. Contact Craig Smith,
[EMAIL PROTECTED], to obtain a license.

 
 Also, in regards to the original question, just thought about something. 
 Since returning new Value(Boolean()) from my userfunction returns the Java
 Object, I'm still not clear about why this didn't work:
 
 (test (eq (ognl-get ?obj booleanProperty) (Boolean.TRUE)))
 
 shouldn't 'eq' call returnedObj.equals(Boolean.TRUE) ?

The Jess function (Boolean.TRUE) returns the symbol TRUE, which is not
the same at the Java object Boolean.TRUE; as I said before, calling a
Java function from Jess reflectively always converts the result to a
Jess data type.


-
Ernest Friedman-Hill  
Advanced Software Research  Phone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov


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]