Oh my goodness... 
I didn't know it was so wonderfully easy !
 
Many thanks for throwing a life-line, Jeff!
Greg.
On Thu, Oct 27, 2011 at 12:54 PM, Jeff Emanuel <jemanuel@frii.com> wrote:

Sorry, last line ought to be

  Message alsoTheMessage = (Message)interp.get("message",Message.class);

Jeff Emanuel wrote:
>
> If you don't need to create or subclass "Message" in the script, then the
> object factory is overkill.  If so, call set/get on the PythonInterpreter
> before/after executing the script.
>
>  Message theMessage = new Message();
>  interp.set("message", theMessage);  // Pass to Jython
>  interp.exec("message.setName('namefromscript')");  // Act on it in
> Jython script
>  Message alsoTheMessage = (Message)interp.get("message");  // Retrieve
> from Jython.
>
> greg.perry@daimler.com wrote:
>>
>> Hello Jython-Gurus.
>>
>> I have a question regarding "referencing a Jython object" after
>> creation.
>>
>> My "big picture" goal is to send a Java object  called "Message",
>> pass it into a Python script and possibly send it back out (on the
>> same thread?)
>>
>> I have gratefully copied some of the code at this informative page -
>>  http://jythonpodcast.hostjava.net/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications
>>
>>
>> I used the section "*Making Use of a Loosely Coupled Object Factory*"
>>  as a template.
>>
>> I created a MessageType interface for my Message class:
>> MessageType.java
>> *public**interface*MessageType {
>>
>>         *public*Object[] getData();
>>         *public**void*setData(Object ... objects);
>>
>>         *public**void*setName(String name);
>>         *public*String getName(String name);
>> }
>>
>> The JythonObjectFactory dutifully creates the object :
>>
>>          javaInt =
>> newObj.__tojava__(Class./forName/(interfaceType.toString().substring(
>>                         interfaceType.toString().indexOf(" ")+1,
>>                         interfaceType.toString().length())));
>>
>> And I have a handle of it in the Java-World and can manipulate data
>> like so :
>>
>> MessageType msg = (MessageType) JythonObjectFactory./createObject/(
>>         MessageType.*class*, "Message");
>>    String s1 = *new*String("Hello");        String s2 =
>> *new*String("World");
>>        msg.setName("clock");
>>     msg.setData(s1, s2);
>>
>> My question is :
>> If I still have the same interpreter which was used to create the
>> object,   "How do I get a Python object reference in script executed
>> after object creation?"
>> For example :
>>
>>         String moreScripting = *new*String ("msg = ????Where's my new
>> MessageType interface???\n");
>>         moreScripting += "name = msg.getName()\n";
>>         moreScripting += "data = msg.getData()\n";
>>         interpreter.exec(moreScripting);
>>
>> Other questions :
>>         1. msg.getData returns an Object array - can "if" i get a
>> reference in Python to the message will I be able to pull out
>> different types with data if the appropriate imports are used in my
>> "moreScripting" ?
>>         2. In my "moreScripting" if I set data elements are they
>> accesable to the Java side automagically?  Or is there some methods
>>  calls on either the Python or Java side which moves the data back?
>>
>> Thanks for helping someone who is flailing about in the deep lake....
>> If you are not the intended addressee, please inform us immediately
>> that you have received this e-mail in error, and delete it. We thank
>> you for your cooperation.
>>
>> ------------------------------------------------------------------------
>>
>> ------------------------------------------------------------------------------
>>
>> The demand for IT networking professionals continues to grow, and the
>> demand for specialized networking skills is growing even more rapidly.
>> Take a complimentary Learning@Cisco Self-Assessment and learn about
>> Cisco certifications, training, and career opportunities.
>> http://p.sf.net/sfu/cisco-dev2dev
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Jython-users mailing list
>> Jython-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>
>

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users