Issue 1704: Proposed change sto IDL/Java mapping (java-rtf) Source: (, ) Nature: Revision Severity: Summary: Summary: The following proposal describes changes to the IDL/Java mapping that will allow values to be marshalled and demarshalled more efficiently in both the "forward mapping" and "reverse mapping" cases. It also allows other IDLEntity types to be marshalled and demarshalled more efficiently in the reverse mapping case, and it fixes some problems in the existing spec with marshalling and demarshalling values and boxed strings. Resolution: closed issue Revised Text: Actions taken: July 20, 1998: received issue July 30, 1998: closed issue Discussion: End of Annotations:===== Return-Path: Date: Mon, 20 Jul 1998 12:43:04 +0100 From: Simon Nash Reply-To: nash@hursley.ibm.com Organization: IBM To: obv-rtf@omg.org Cc: java-rtf@omg.org, java2idl-rtf@omg.org, issues@omg.org Subject: Proposed changes to IDL/Java mapping The following proposal describes changes to the IDL/Java mapping that will allow values to be marshalled and demarshalled more efficiently in both the "forward mapping" and "reverse mapping" cases. It also allows other IDLEntity types to be marshalled and demarshalled more efficiently in the reverse mapping case, and it fixes some problems in the existing spec with marshalling and demarshalling values and boxed strings. 1. Add two new interfaces: package org.omg.CORBA.portable; public interface Helper { Object read_Object(org.omg.CORBA.portable.InputStream istream); void write_Object(org.omg.CORBA.portable.OutputStream ostream, Object obj); } public interface ValueHelper extends Helper { java.io.Serializable read_Value( org.omg.CORBA.portable.InputStream istream); void write_Value(org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable obj); String get_id(); Class get_class(); String[] get_safe_base_ids(); } 2. All generated helper classes for values shall implement the ValueHelper interface, and all other helper classes shall implement the Helper interface. 3. Have a static method get_instance on each generated value helper class that returns an instance of the Helper class, creating it if necessary. The signature is: public static ValueHelper get_instance() { ... } 4. All generated helper classes shall have a public default constructor. 5. Add overloaded write_Value and read_Value methods to the portable OutputStream and InputStream classes: void write_Value(java.io.Serializable obj, ValueHelper helper); java.io.Serializable read_Value(ValueHelper helper); 6. In the stub that marshals a Foo value, generate a call out.write_Value(myFoo, FooHelper.get_instance()); 7. In the skeleton that demarshals a Foo value, generate a call val = in.read_Value(FooHelper.get_instance()); 8. When the stream's write_Value marshals a value, it calls get_id on its ValueHelper parameter to check that the ValueHelper parameter is the correct one to be used to marshal the value's type. If not, it creates an instance of the correct ValueHelper for the runtime type of the value that it received. It can cache this instance to improve efficiency. It marshals the value by calling write_Value on the ValueHelper instance, using a normal Java call (not reflection) through the ValueHelper interface. This is more efficient than the approach used in the current spec. 9. When the stream's read_Value demarshals a value, it calls get_id on its ValueHelper parameter to check that the ValueHelper parameter is the correct one to be used to demarshal the value's type. If not, it creates an instance of the correct ValueHelper for the runtime type of the value that it received. It can cache this instance to improve efficiency. It demarshals the value by calling read_Value on the ValueHelper instance, using a normal Java call (not reflection) through the ValueHelper interface. This is more efficient than the approach used in the current spec. 10. Redefine the native type ValueFactory to be the Java type ValueHelper. 11. For efficient demarshalling of IDLEntity types by the Java IIOP serialization, we can create a Helper instance, then call the read_Object method of the Helper instance. For values, read_Object calls istream.read_Value(this), which will call back to the ValueHelper read_Value method to demarshal the state. We can cache the Helper instance so that we don't need to new up a Helper instance more than once per type. 12. For efficient marshalling of IDLEntity types by the Java IIOP serialization, we would do the same as demarshalling. The write_Object method of the Helper interface would check that the obj parameter is of the correct type, and throw BAD_PARAM if it isn't. 13. For compatibility with today's code, we would still generate static read, write, and id methods in each type's helper class. read_Object would call read, write_Object would call write, and get_id would call id. Comments, questions? Simon -- Simon C Nash, IBM Java Technology Centre, Hursley, UK MailPoint 146, x245156 Tel. 01962 815156 or +44-1962-815156 Internet: nash@hursley.ibm.com Notes mail: Simon Nash@ibmgb