Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectInputStream.java Wed Mar 23 09:56:34 2005 @@ -17,56 +17,84 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.io.IOException; - -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.util.JavaObject; - - -public class SimpleObjectInputStream extends ObjectInputStream { - public static ObjectInputStream getInstance() { - return getInstance(CdrInputStream.getInstance()); +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.rmi.*; +import org.apache.geronimo.interop.util.*; +import java.io.*; + +public class SimpleObjectInputStream extends ObjectInputStream +{ + //public static final Component component = new Component(SimpleObjectInputStream.class); + + public static ObjectInputStream getInstance() + { + ObjectInputStream ois = null; + try { + ois = new SimpleObjectInputStream(); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + return ois; // getInstance(CdrInputStream.getInstance()); } - public static ObjectInputStream getInstance(byte[] bytes) { + public static ObjectInputStream getInstance(byte[] bytes) + { return getInstance(CdrInputStream.getInstance(bytes)); } - public static ObjectInputStream getInstance(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) { - ObjectInputStream input = null; - try { - input = new SimpleObjectInputStream(); - } catch (Exception ex) { - throw new SystemException(ex); - } - + public static ObjectInputStream getInstance(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) + { + ObjectInputStream input = getInstance(); // (SimpleObjectInputStream)component.getInstance(); input.init(cdrInput); return input; } + public static ObjectInputStream getPooledInstance() + { + ObjectInputStream input = null; // (SimpleObjectInputStream)_pool.get(); + if (input == null) + { + input = getInstance(); + } + return input; + } + // ----------------------------------------------------------------------- // private data // ----------------------------------------------------------------------- + //private static ThreadLocalInstancePool _pool = new ThreadLocalInstancePool(SimpleObjectInputStream.class.getName()); + // ----------------------------------------------------------------------- // public methods // ----------------------------------------------------------------------- - public SimpleObjectInputStream() throws IOException { + public SimpleObjectInputStream() throws IOException + { super(); } - public void $reset() { + public void $reset() + { _cdrInput.reset(); } - public void recycle() { + public void recycle() + { $reset(); + //_pool.put(this); + } + + public Exception readException(ValueType type) + { + return (Exception)readObject(type); } - public Object readObject(ValueType type) { + public Object readObject(ValueType type) + { ObjectHelper h = type.helper; - if (h != null) { + if (h != null) + { return h.read(this); } byte[] bytes = _cdrInput.read_octet_sequence(); @@ -78,7 +106,8 @@ // protected methods // ----------------------------------------------------------------------- - protected void init(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) { + protected void init(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) + { super.init(cdrInput); } }
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SimpleObjectOutputStream.java Wed Mar 23 09:56:34 2005 @@ -17,53 +17,82 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.io.IOException; - -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.util.ArrayUtil; -import org.apache.geronimo.interop.util.JavaObject; - - -public class SimpleObjectOutputStream extends ObjectOutputStream { - public static ObjectOutputStream getInstance() { - return getInstance(CdrOutputStream.getInstance()); - } - - public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput) { - ObjectOutputStream output = null; +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.rmi.*; +import org.apache.geronimo.interop.util.*; +import java.io.*; + +public class SimpleObjectOutputStream extends ObjectOutputStream +{ + //public static final Component component = new Component(SimpleObjectOutputStream.class); + + public static ObjectOutputStream getInstance() + { + ObjectOutputStream oos = null; try { - output = new SimpleObjectOutputStream(); - } catch (Exception ex) { - throw new SystemException(ex); + oos = new SimpleObjectOutputStream(); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } + return oos; // getInstance(CdrOutputStream.getInstance()); + } + public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput) + { + ObjectOutputStream output = getInstance(); // (SimpleObjectOutputStream)component.getInstance(); output.init(cdrOutput); return output; } + public static ObjectOutputStream getPooledInstance() + { + ObjectOutputStream output = null; // (SimpleObjectOutputStream)_pool.get(); + if (output == null) + { + output = getInstance(); + } + return output; + } + // ----------------------------------------------------------------------- // private data // ----------------------------------------------------------------------- + //private static ThreadLocalInstancePool _pool = new ThreadLocalInstancePool(SimpleObjectOutputStream.class.getName()); + // ----------------------------------------------------------------------- // public methods // ----------------------------------------------------------------------- - public SimpleObjectOutputStream() throws IOException { + public SimpleObjectOutputStream() throws IOException + { super(); } - public void $reset() { + public void $reset() + { _cdrOutput.reset(); } - public void recycle() { + public void recycle() + { $reset(); + //_pool.put(this); + } + + public void writeException(ValueType type, Exception value) + { + String repositoryID = "IDL:" + type._class.getName().replace('.', '/') + ":1.0"; + _cdrOutput.write_string(repositoryID); + writeObject(type, value); + _hasException = true; } - public void writeObject(ValueType type, Object value) { + public void writeObject(ValueType type, Object value) + { ObjectHelper h = type.helper; - if (h != null) { + if (h != null) + { h.write(this, value); return; } @@ -76,7 +105,8 @@ // protected methods // ----------------------------------------------------------------------- - protected void init(CdrOutputStream cdrOutput) { + protected void init(CdrOutputStream cdrOutput) + { super.init(cdrOutput); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringHelper.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringHelper.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringHelper.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringHelper.java Wed Mar 23 09:56:34 2005 @@ -17,14 +17,17 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public class StringHelper implements ObjectHelper { +public class StringHelper implements ObjectHelper +{ public static final StringHelper SINGLETON = new StringHelper(); - public Object read(ObjectInputStream input) { + public Object read(ObjectInputStream input) + { return input._cdrInput.read_string(); } - public void write(ObjectOutputStream output, Object value) { - output._cdrOutput.write_string((String) value); + public void write(ObjectOutputStream output, Object value) + { + output._cdrOutput.write_string((String)value); } } Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java?view=auto&rev=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java (added) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHelper.java Wed Mar 23 09:56:34 2005 @@ -0,0 +1,109 @@ +/** + * + * Copyright 2004-2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.interop.rmi.iiop; + +/** + ** Generated by Sybase EAServer 5.0 - Thu Nov 04 15:51:10 NZDT 2004 + ** + ** from com::sybase::djc::rmi::iiop::StringSeq (file C:/easme/build/idl/com-sybase-djc-rmi-iiop.idl, line 13). + ** + ** Please do not modify this file. + **/ + +public abstract class StringSeqHelper +{ + public static java.lang.String[] clone + (java.lang.String[] _value) + { + if (_value == null) + { + return null; + } + int _16 = _value.length; + java.lang.String[] _clone = new java.lang.String[_16]; + for (int _17 = 0; _17 < _16; _17++) + { + _clone[_17] = _value[_17]; + } + return _clone; + } + + public static java.lang.String[] read + (org.omg.CORBA.portable.InputStream _input) + { + int _18 = _input.read_ulong(); + java.lang.String[] value = new java.lang.String[_18]; + for (int _19 = 0; _19 < _18; _19++) + { + value[_19] = _input.read_string(); + } + return value; + } + + public static void write + (org.omg.CORBA.portable.OutputStream _output, + java.lang.String[] value) + { + if (value == null) + { + value = new java.lang.String[0]; + } + int _20 = value.length; + _output.write_ulong(_20); + for (int _21 = 0; _21 < _20; _21++) + { + _output.write_string(value[_21]); + } + } + + public static org.omg.CORBA.TypeCode _type; + + public static org.omg.CORBA.TypeCode type() + { + if (_type == null) + { + org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); + _type = orb.create_sequence_tc(0, orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_string)); + } + return _type; + } + + public static void insert + (org.omg.CORBA.Any any, + java.lang.String[] value) + { + org.omg.CORBA.portable.OutputStream output = any.create_output_stream(); + write(output, value); + any.read_value(output.create_input_stream(), type()); + } + + public static java.lang.String[] extract + (org.omg.CORBA.Any any) + { + if (! any.type().equal(type())) + { + throw new org.omg.CORBA.BAD_OPERATION(); + } + return read(any.create_input_stream()); + } + + public static java.lang.String id() + { + return "IDL:com/sybase/djc/rmi/iiop/StringSeq:1.0"; + } +} Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java?view=auto&rev=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java (added) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringSeqHolder.java Wed Mar 23 09:56:34 2005 @@ -0,0 +1,58 @@ +/** + * + * Copyright 2004-2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.interop.rmi.iiop; + +/** + ** Generated by Sybase EAServer 5.0 - Thu Nov 04 15:51:10 NZDT 2004 + ** + ** from com::sybase::djc::rmi::iiop::StringSeq (file C:/easme/build/idl/com-sybase-djc-rmi-iiop.idl, line 13). + ** + ** Please do not modify this file. + **/ + +public final class StringSeqHolder implements org.omg.CORBA.portable.Streamable +{ + public java.lang.String[] value; + + public StringSeqHolder() + { + } + + public StringSeqHolder + (java.lang.String[] _value) + { + value = _value; + } + + public org.omg.CORBA.TypeCode _type() + { + return org.apache.geronimo.interop.rmi.iiop.StringSeqHelper.type(); + } + + public void _read + (org.omg.CORBA.portable.InputStream _input) + { + value = org.apache.geronimo.interop.rmi.iiop.StringSeqHelper.read(_input); + } + + public void _write + (org.omg.CORBA.portable.OutputStream _output) + { + org.apache.geronimo.interop.rmi.iiop.StringSeqHelper.write(_output, value); + } +} Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringValueHelper.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringValueHelper.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringValueHelper.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/StringValueHelper.java Wed Mar 23 09:56:34 2005 @@ -17,14 +17,17 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public class StringValueHelper implements ObjectHelper { +public class StringValueHelper implements ObjectHelper +{ public static final StringValueHelper SINGLETON = new StringValueHelper(); - public Object read(ObjectInputStream input) { + public Object read(ObjectInputStream input) + { return input._cdrInput.read_string(); } - public void write(ObjectOutputStream output, Object value) { - output._cdrOutput.write_string((String) value); + public void write(ObjectOutputStream output, Object value) + { + output._cdrOutput.write_string((String)value); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/TypeCode.java Wed Mar 23 09:56:34 2005 @@ -21,34 +21,55 @@ import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.TypeCodePackage.Bounds; - /** * * An implementation of CORBA 'TypeCode' for use with RMI-IIOP. */ -public class TypeCode extends org.omg.CORBA.TypeCode { +public class TypeCode + extends org.omg.CORBA.TypeCode +{ // ----------------------------------------------------------------------- // public data // ----------------------------------------------------------------------- public static final TypeCode NULL = new TypeCode(TCKind.tk_null); + public static final TypeCode VOID = new TypeCode(TCKind.tk_void); + public static final TypeCode ANY = new TypeCode(TCKind.tk_any); + public static final TypeCode BOOLEAN = new TypeCode(TCKind.tk_boolean); + public static final TypeCode CHAR = new TypeCode(TCKind.tk_char); + public static final TypeCode WCHAR = new TypeCode(TCKind.tk_wchar); + public static final TypeCode OCTET = new TypeCode(TCKind.tk_octet); + public static final TypeCode SHORT = new TypeCode(TCKind.tk_short); + public static final TypeCode USHORT = new TypeCode(TCKind.tk_ushort); + public static final TypeCode LONG = new TypeCode(TCKind.tk_long); + public static final TypeCode ULONG = new TypeCode(TCKind.tk_ulong); + public static final TypeCode LONGLONG = new TypeCode(TCKind.tk_longlong); + public static final TypeCode ULONGLONG = new TypeCode(TCKind.tk_ulonglong); + public static final TypeCode FLOAT = new TypeCode(TCKind.tk_float); + public static final TypeCode DOUBLE = new TypeCode(TCKind.tk_double); - public static final TypeCode LONGDOUBLE = new TypeCode(TCKind.tk_longdouble); + + public static final TypeCode LONGDOUBLE = new TypeCode( + TCKind.tk_longdouble); + public static final TypeCode STRING = new TypeCode(TCKind.tk_string); + public static final TypeCode WSTRING = new TypeCode(TCKind.tk_wstring); + public static final TypeCode OBJREF = new TypeCode(TCKind.tk_objref); + public static final TypeCode TYPECODE = new TypeCode(TCKind.tk_TypeCode); // ----------------------------------------------------------------------- @@ -95,10 +116,12 @@ /** * @param kind */ - public TypeCode(TCKind kind) { + public TypeCode(TCKind kind) + { _kind = kind; _default = -1; - if (kind.value() == TCKind._tk_objref) { + if (kind.value() == TCKind._tk_objref) + { _type = "Object"; } } @@ -107,60 +130,84 @@ * @param tc * @return */ - public boolean equal(org.omg.CORBA.TypeCode tc) { - if (_indirection) { + public boolean equal(org.omg.CORBA.TypeCode tc) + { + if (_indirection) + { return _ref.equal(tc); } - try { + try + { int tk = _kind.value(); - if (tk != tc.kind().value()) { + if (tk != tc.kind().value()) + { return false; } // TODO: compare id() - if (_member_name != null) { + if (_member_name != null) + { int n = _member_name.length; - if (n != tc.member_count()) { + if (n != tc.member_count()) + { return false; } - for (int i = 0; i < n; i++) { - if (!equalIfNotEmpty(member_name(i), tc.member_name(i))) { + for (int i = 0; i < n; i++) + { + if (!equalIfNotEmpty(member_name(i), tc.member_name(i))) + { return false; } - if (!member_type(i).equal(tc.member_type(i))) { + if (!member_type(i).equal(tc.member_type(i))) + { return false; } } } - if (tk == TCKind._tk_union) { - if (!discriminator_type().equal(tc.discriminator_type())) { + if (tk == TCKind._tk_union) + { + if (!discriminator_type().equal(tc.discriminator_type())) + { return false; } int n = _member_name.length; - for (int i = 0; i < n; i++) { - if (!member_label(i).equal(tc.member_label(i))) { + for (int i = 0; i < n; i++) + { + if (!member_label(i).equal(tc.member_label(i))) + { return false; } } } if (tk == TCKind._tk_array - || tk == TCKind._tk_sequence - || tk == TCKind._tk_string - || tk == TCKind._tk_wstring) { - if (length() != tc.length()) { + || + tk == TCKind._tk_sequence + || + tk == TCKind._tk_string + || tk == TCKind._tk_wstring) + { + if (length() != tc.length()) + { return false; } } if (tk == TCKind._tk_alias - || tk == TCKind._tk_array - || tk == TCKind._tk_sequence) { - if (!content_type().equal(tc.content_type())) { + || + tk == TCKind._tk_array + || tk == TCKind._tk_sequence) + { + if (!content_type().equal(tc.content_type())) + { return false; } } return true; - } catch (org.omg.CORBA.TypeCodePackage.BadKind ex) { + } + catch (org.omg.CORBA.TypeCodePackage.BadKind ex) + { throw new org.omg.CORBA.UNKNOWN(ex.toString()); - } catch (org.omg.CORBA.TypeCodePackage.Bounds ex) { + } + catch (org.omg.CORBA.TypeCodePackage.Bounds ex) + { throw new org.omg.CORBA.UNKNOWN(ex.toString()); } } @@ -170,14 +217,16 @@ * @return */ public boolean equivalent - (org.omg.CORBA.TypeCode tc) { + (org.omg.CORBA.TypeCode tc) + { throw new org.omg.CORBA.NO_IMPLEMENT(); } /** * @return */ - public org.omg.CORBA.TypeCode get_compact_typecode() { + public org.omg.CORBA.TypeCode get_compact_typecode() + { throw new org.omg.CORBA.NO_IMPLEMENT(); } @@ -186,10 +235,14 @@ * @param b * @return */ - private boolean equalIfNotEmpty(String a, String b) { - if (a.length() == 0 || b.length() == 0) { + private boolean equalIfNotEmpty(String a, String b) + { + if (a.length() == 0 || b.length() == 0) + { return true; - } else { + } + else + { return a.equals(b); } } @@ -197,8 +250,10 @@ /** * @return */ - public TCKind kind() { - if (_indirection) { + public TCKind kind() + { + if (_indirection) + { return _ref.kind(); } return _kind; @@ -209,14 +264,18 @@ * @throws BadKind */ public String id() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.id(); } - if (_id != null) { + if (_id != null) + { return _id; } - if (_type != null && _type.equals("Object")) { + if (_type != null && _type.equals("Object")) + { return ""; } return default_id(); @@ -226,19 +285,25 @@ /** * @param id */ - public void id(String id) { - if (!id.equals("")) { + public void id(String id) + { + if (!id.equals("")) + { _id = id; - if (id.startsWith("IDL:") && id.endsWith(":1.0")) { + if (id.startsWith("IDL:") && id.endsWith(":1.0")) + { // Infer _type field from standard IDL format _id id = id.substring(4, id.length() - 4); - if (id.startsWith("omg.org/")) { + if (id.startsWith("omg.org/")) + { id = id.substring(8); } _type = ""; - for (; ;) { + for (; ;) + { int slash = id.indexOf('/'); - if (slash == -1) { + if (slash == -1) + { break; } _type = _type + id.substring(0, slash) + "::"; @@ -254,8 +319,10 @@ * @throws BadKind */ public String name() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.name(); } /* TODO? @@ -264,7 +331,8 @@ _name = (String)_names.get(new Integer(_kind.value())); } */ - if (_name == null) { + if (_name == null) + { throw new BadKind(); } return _name; @@ -274,7 +342,8 @@ /** * @param name */ - public void name(String name) { + public void name(String name) + { _name = name; } @@ -283,11 +352,14 @@ * @throws BadKind */ public int member_count() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.member_count(); } - if (_member_name == null) { + if (_member_name == null) + { throw new BadKind(); } return _member_name.length; @@ -297,13 +369,16 @@ /** * @param count */ - public void member_count(int count) { + public void member_count(int count) + { _member_name = new String[count]; _member_type = new org.omg.CORBA.TypeCode[count]; - if (_kind.value() == TCKind._tk_union) { + if (_kind.value() == TCKind._tk_union) + { _member_label = new org.omg.CORBA.Any[count]; } - if (_kind.value() == TCKind._tk_value) { + if (_kind.value() == TCKind._tk_value) + { _member_visibility = new short[count]; } } @@ -315,14 +390,18 @@ * @throws Bounds */ public String member_name(int index) - throws BadKind, Bounds { - if (_indirection) { + throws BadKind, Bounds + { + if (_indirection) + { return _ref.member_name(index); } - if (_member_name == null) { + if (_member_name == null) + { throw new BadKind(); } - if (index < 0 || index >= _member_name.length) { + if (index < 0 || index >= _member_name.length) + { throw new Bounds(); } return _member_name[index]; @@ -333,7 +412,8 @@ * @param index * @param name */ - public void member_name(int index, String name) { + public void member_name(int index, String name) + { _member_name[index] = name; } @@ -344,14 +424,18 @@ * @throws Bounds */ public org.omg.CORBA.TypeCode member_type(int index) - throws BadKind, Bounds { - if (_indirection) { + throws BadKind, Bounds + { + if (_indirection) + { return _ref.member_type(index); } - if (_member_type == null) { + if (_member_type == null) + { throw new BadKind(); } - if (index < 0 || index >= _member_type.length) { + if (index < 0 || index >= _member_type.length) + { throw new Bounds(); } return _member_type[index]; @@ -362,7 +446,8 @@ * @param index * @param type */ - public void member_type(int index, org.omg.CORBA.TypeCode type) { + public void member_type(int index, org.omg.CORBA.TypeCode type) + { _member_type[index] = type; } @@ -373,14 +458,18 @@ * @throws Bounds */ public org.omg.CORBA.Any member_label(int index) - throws BadKind, Bounds { - if (_indirection) { + throws BadKind, Bounds + { + if (_indirection) + { return _ref.member_label(index); } - if (_member_label == null) { + if (_member_label == null) + { throw new BadKind(); } - if (index < 0 || index >= _member_label.length) { + if (index < 0 || index >= _member_label.length) + { throw new Bounds(); } return _member_label[index]; @@ -391,7 +480,8 @@ * @param index * @param label */ - public void member_label(int index, org.omg.CORBA.Any label) { + public void member_label(int index, org.omg.CORBA.Any label) + { _member_label[index] = label; } @@ -400,12 +490,15 @@ * @throws BadKind */ public org.omg.CORBA.TypeCode discriminator_type() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.discriminator_type(); } if (_ref == null - || _kind.value() != TCKind._tk_union) { + || _kind.value() != TCKind._tk_union) + { throw new BadKind(); } return _ref; @@ -415,7 +508,8 @@ /** * @param disc */ - public void discriminator_type(org.omg.CORBA.TypeCode disc) { + public void discriminator_type(org.omg.CORBA.TypeCode disc) + { _ref = disc; } @@ -424,11 +518,14 @@ * @throws BadKind */ public int default_index() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.default_index(); } - if (_kind.value() != TCKind._tk_union) { + if (_kind.value() != TCKind._tk_union) + { throw new BadKind(); } return _default; @@ -438,9 +535,11 @@ /** * @param index */ - public void default_index(int index) { + public void default_index(int index) + { _default = index; - if (index != -1) { + if (index != -1) + { // We must store the member label for the discriminator type // as some legal value, so we use zero. _member_label[index] = new Any(_ref, "0"); @@ -452,13 +551,17 @@ * @throws BadKind */ public int length() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.length(); } int tk = _kind.value(); - if (tk != TCKind._tk_string && tk != TCKind._tk_wstring - && tk != TCKind._tk_sequence && tk != TCKind._tk_array) { + if (tk != TCKind._tk_string && + tk != TCKind._tk_wstring + && tk != TCKind._tk_sequence && tk != TCKind._tk_array) + { throw new BadKind(); } return _length; @@ -468,7 +571,8 @@ /** * @param length */ - public void length(int length) { + public void length(int length) + { _length = length; } @@ -477,16 +581,21 @@ * @throws BadKind */ public org.omg.CORBA.TypeCode content_type() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.content_type(); } int tk = _kind.value(); if (_ref == null || (tk != TCKind._tk_alias - && tk != TCKind._tk_array - && tk != TCKind._tk_sequence - && tk != TCKind._tk_value_box)) { + && + tk != TCKind._tk_array + && + tk != TCKind._tk_sequence + && tk != TCKind._tk_value_box)) + { throw new BadKind(); } return _ref; @@ -496,7 +605,8 @@ /** * @param type */ - public void content_type(org.omg.CORBA.TypeCode type) { + public void content_type(org.omg.CORBA.TypeCode type) + { _ref = type; } @@ -505,12 +615,15 @@ * @throws BadKind */ public short fixed_digits() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.fixed_digits(); } int tk = _kind.value(); - if (tk != TCKind._tk_fixed) { + if (tk != TCKind._tk_fixed) + { throw new BadKind(); } return _digits; @@ -520,7 +633,8 @@ /** * @param digits */ - public void fixed_digits(short digits) { + public void fixed_digits(short digits) + { _digits = digits; } @@ -529,12 +643,15 @@ * @throws BadKind */ public short fixed_scale() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.fixed_scale(); } int tk = _kind.value(); - if (tk != TCKind._tk_fixed) { + if (tk != TCKind._tk_fixed) + { throw new BadKind(); } return _scale; @@ -544,7 +661,8 @@ /** * @param scale */ - public void fixed_scale(short scale) { + public void fixed_scale(short scale) + { _scale = scale; } @@ -555,15 +673,19 @@ * @throws Bounds */ public short member_visibility - (int index) - throws BadKind, Bounds { - if (_indirection) { + (int index) + throws BadKind, Bounds + { + if (_indirection) + { return _ref.member_visibility(index); } - if (_member_type == null) { + if (_member_type == null) + { throw new BadKind(); } - if (index < 0 || index >= _member_visibility.length) { + if (index < 0 || index >= _member_visibility.length) + { throw new Bounds(); } return _member_visibility[index]; @@ -574,7 +696,8 @@ * @param index * @param visibility */ - public void member_visibility(int index, short visibility) { + public void member_visibility(int index, short visibility) + { _member_visibility[index] = visibility; } @@ -583,12 +706,15 @@ * @throws BadKind */ public short type_modifier() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.type_modifier(); } int tk = _kind.value(); - if (tk != TCKind._tk_value) { + if (tk != TCKind._tk_value) + { throw new BadKind(); } return _type_modifier; @@ -598,7 +724,8 @@ /** * @param modifier */ - public void type_modifier(short modifier) { + public void type_modifier(short modifier) + { _type_modifier = modifier; } @@ -607,12 +734,15 @@ * @throws BadKind */ public org.omg.CORBA.TypeCode concrete_base_type() - throws BadKind { - if (_indirection) { + throws BadKind + { + if (_indirection) + { return _ref.concrete_base_type(); } int tk = _kind.value(); - if (tk != TCKind._tk_value) { + if (tk != TCKind._tk_value) + { throw new BadKind(); } return _ref; @@ -622,7 +752,8 @@ /** * @param base */ - public void concrete_base_type(org.omg.CORBA.TypeCode base) { + public void concrete_base_type(org.omg.CORBA.TypeCode base) + { _ref = base; } @@ -630,7 +761,8 @@ /** * @param ref */ - public void indirection(org.omg.CORBA.TypeCode ref) { + public void indirection(org.omg.CORBA.TypeCode ref) + { _ref = ref; _indirection = true; } @@ -639,7 +771,8 @@ /** * @param id */ - public void recursive(String id) { + public void recursive(String id) + { _id = id; _ref = null; _indirection = true; @@ -649,16 +782,21 @@ /** * */ - public void fix_recursive_members() { + public void fix_recursive_members() + { String id = _id == null ? default_id() : _id; int n = _member_type.length; - for (int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) + { TypeCode mt = (TypeCode) _member_type[i]; - if (mt._kind.value() == TCKind._tk_sequence) { + if (mt._kind.value() == TCKind._tk_sequence) + { TypeCode ct = (TypeCode) mt._ref; if (ct._indirection - && ct._ref == null - && ct._id.equals(id)) { + && + ct._ref == null + && ct._id.equals(id)) + { ct._ref = this; } } @@ -671,19 +809,23 @@ /** * @return */ - private String default_id() { + private String default_id() + { // Take _type, and generate _id, e.g. // if _type = "SessionManager::Manager", // then _id = "IDL:SessionManager/Manager:1.0". - if (_type == null) { + if (_type == null) + { return ""; } StringBuffer id = new StringBuffer(_type.length() + 10); id.append("IDL:"); int n = _type.length(); - for (int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) + { char c = _type.charAt(i); - if (c == ':' && i + 1 < n && _type.charAt(i + 1) == ':') { + if (c == ':' && i + 1 < n && _type.charAt(i + 1) == ':') + { i++; } id.append(c == ':' ? '/' : c); Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/UnsupportedProtocolVersionException.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/UnsupportedProtocolVersionException.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/UnsupportedProtocolVersionException.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/UnsupportedProtocolVersionException.java Wed Mar 23 09:56:34 2005 @@ -17,8 +17,10 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public class UnsupportedProtocolVersionException extends RuntimeException { - public UnsupportedProtocolVersionException(String version) { +public class UnsupportedProtocolVersionException extends RuntimeException +{ + public UnsupportedProtocolVersionException(String version) + { super(version); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java Wed Mar 23 09:56:34 2005 @@ -17,60 +17,50 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.ObjectStreamClass; -import java.io.Serializable; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.security.DigestOutputStream; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.rmi.*; +import org.apache.geronimo.interop.util.*; +import java.io.*; +import java.lang.reflect.*; +import java.security.*; +import java.util.*; import org.omg.CORBA.TCKind; -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.util.ArrayUtil; -import org.apache.geronimo.interop.util.ExceptionUtil; -import org.apache.geronimo.interop.util.JavaClass; -import org.apache.geronimo.interop.util.JavaType; -import org.apache.geronimo.interop.util.SystemUtil; - - -/** - * * A wrapper over java.lang.Class to help improve performance of using - * * the Java reflection API for valuetype marshalling. We keep as much - * * derived information as possible for optimal performance. - */ -public class ValueType { - public static ValueType getInstance(Class forClass) { - ValueType vt = (ValueType) _valueTypeMap.get(forClass); - if (vt == null) { - synchronized (_valueTypeMap) { - vt = (ValueType) _valueTypeMap.get(forClass); - if (vt == null) { +public class ValueType +{ + //public static final Component component = new Component(ValueType.class); + + public static ValueType getInstance(Class forClass) + { + ValueType vt = (ValueType)_valueTypeMap.get(forClass); + if (vt == null) + { + synchronized (_valueTypeMap) + { + vt = (ValueType)_valueTypeMap.get(forClass); + if (vt == null) + { + //vt = (ValueType)component.getInstance(); vt = new ValueType(); - vt.init(forClass); _valueTypeMap.put(forClass, vt); + vt.init(forClass); } } } return vt; } - public static ValueType getInstanceByID(String id) { + public static ValueType getInstanceByID(String id) + { // TODO: handle multiple class loaders??? - ValueType vt = (ValueType) _idTypeMap.get(id); - if (vt == null) { - synchronized (_idTypeMap) { - vt = (ValueType) _idTypeMap.get(id); - if (vt == null) { + ValueType vt = (ValueType)_idTypeMap.get(id); + if (vt == null) + { + synchronized (_idTypeMap) + { + vt = (ValueType)_idTypeMap.get(id); + if (vt == null) + { Class theClass = getClass(id); vt = getInstance(theClass); _idTypeMap.put(id, vt); @@ -119,13 +109,13 @@ // package-private data // ----------------------------------------------------------------------- - static final int NULL_VALUE_TAG = 0; - static final int NO_TYPE_VALUE_TAG = 0x7fffff00; - static final int SINGLE_TYPE_VALUE_TAG = 0x7fffff02; - static final int TRUNCATABLE_NO_TYPE_VALUE_TAG = 0x7fffff08; + static final int NULL_VALUE_TAG = 0; + static final int NO_TYPE_VALUE_TAG = 0x7fffff00; + static final int SINGLE_TYPE_VALUE_TAG = 0x7fffff02; + static final int TRUNCATABLE_NO_TYPE_VALUE_TAG = 0x7fffff08; static final int TRUNCATABLE_SINGLE_TYPE_VALUE_TAG = 0x7fffff0a; - static final int TYPE_LIST_VALUE_TAG = 0x7fffff06; - static final int INDIRECTION_TAG = 0xffffffff; + static final int TYPE_LIST_VALUE_TAG = 0x7fffff06; + static final int INDIRECTION_TAG = 0xffffffff; static final int CASE_ARRAY = 1; static final int CASE_CLASS = 2; @@ -178,20 +168,27 @@ // static initializer // ----------------------------------------------------------------------- - static { + static + { TC_ABSTRACT_BASE = new TypeCode(TCKind.tk_abstract_interface); TC_ABSTRACT_BASE.id("IDL:omg.org/CORBA/AbstractBase:1.0"); TC_ABSTRACT_BASE.name(""); - try { - if (JDK14) { - _newInstance = java.io.ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[]{}); + try + { + if (JDK14) + { + _newInstance = java.io.ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[] {}); _newInstance.setAccessible(true); - } else { - _allocateNewObject = java.io.ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[]{Class.class, Class.class}); + } + else + { + _allocateNewObject = java.io.ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[] { Class.class, Class.class }); _allocateNewObject.setAccessible(true); } - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } @@ -200,70 +197,105 @@ // public methods // ----------------------------------------------------------------------- - public Object newInstance() { - try { - if (JDK14) { - if (_class == Object.class) { + public Object newInstance() + { + try + { + if (JDK14) + { + if (_class == Object.class) + { return new Object(); - } else { + } + else + { return _newInstance.invoke(_objectStreamClass, ArrayUtil.EMPTY_OBJECT_ARRAY); } - } else { + } + else + { return _allocateNewObject.invoke(null, _allocateNewObjectArgs); } - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } - public String toString() { + public String toString() + { return "ValueType:" + JavaType.getName(_class); } - public void readObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) { - try { + public void readObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) + { + try + { _readObject.invoke(_this, input.thisAsObjectArray); - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } - public void writeObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - try { + public void writeObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) + { + try + { _writeObject.invoke(_this, output.thisAsObjectArray); - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } - public Object readResolve(Object _this) { - try { + public Object readResolve(Object _this) + { + try + { return _readResolve.invoke(_this, ArrayUtil.EMPTY_OBJECT_ARRAY); - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } - public Object writeReplace(Object _this) { - try { + public Object writeReplace(Object _this) + { + try + { return _writeReplace.invoke(_this, ArrayUtil.EMPTY_OBJECT_ARRAY); - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } - public void readExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) { - try { + public void readExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) + { + try + { _readExternal.invoke(_this, input.thisAsObjectArray); - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } - public void writeExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - try { + public void writeExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) + { + try + { _writeExternal.invoke(_this, output.thisAsObjectArray); - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); } } @@ -272,50 +304,67 @@ // protected methods // ----------------------------------------------------------------------- - protected void init(Class theClass) { + protected void init(Class theClass) + { boolean recursive = false; - if (_initMap.get(theClass) != null) { + if (_initMap.get(theClass) != null) + { // recursive = true; return; // Already initializing (recursive 'init' call). } _initMap.put(theClass, Boolean.TRUE); - try { + try + { _class = theClass; _objectStreamClass = ObjectStreamClass.lookup(_class); if (org.omg.CORBA.Object.class.isAssignableFrom(theClass) || javax.ejb.EJBHome.class.isAssignableFrom(theClass) || javax.ejb.EJBObject.class.isAssignableFrom(theClass) - || java.rmi.Remote.class.isAssignableFrom(theClass)) { + || java.rmi.Remote.class.isAssignableFrom(theClass)) + { helper = ObjectRefHelper.getInstance(theClass); isObjectRef = true; readWriteCase = CASE_IDL_OBJECT; - } else if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(theClass)) { + } + else if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(theClass)) + { helper = IDLEntityHelper.getInstance(theClass); isIDLEntity = true; readWriteCase = CASE_IDL_ENTITY; - } else if (theClass == String.class) { + } + else if (theClass == String.class) + { helper = StringHelper.SINGLETON; readWriteCase = CASE_STRING; - } else if (theClass.isArray()) { + } + else if (theClass.isArray()) + { Class elementClass = theClass.getComponentType(); element = getInstance(elementClass); isArray = true; - if (elementClass.isPrimitive()) { + if (elementClass.isPrimitive()) + { primitiveArray = PrimitiveType.get(elementClass); helper = PrimitiveType.getArrayHelper(elementClass); - } else { + } + else + { helper = new ArrayHelper(elementClass); } readWriteCase = CASE_ARRAY; - } else if (theClass == Class.class) { + } + else if (theClass == Class.class) + { readWriteCase = CASE_CLASS; } - if (_allocateNewObject != null) { + if (_allocateNewObject != null) + { Class bc = _class; - while (Serializable.class.isAssignableFrom(bc) && (bc.getSuperclass() != null)) { + while (Serializable.class.isAssignableFrom(bc) && (bc.getSuperclass() != null)) + { bc = bc.getSuperclass(); } - _allocateNewObjectArgs = new Object[]{_class, bc}; + _allocateNewObjectArgs = new Object[] { _class, bc }; } isAny = _class == java.lang.Object.class @@ -323,13 +372,15 @@ || _class == java.io.Serializable.class; isExternalizable = java.io.Externalizable.class.isAssignableFrom(_class); - if (isExternalizable) { - _readExternal = _class.getDeclaredMethod("readExternal", new Class[]{ObjectInput.class}); - _writeExternal = _class.getDeclaredMethod("writeExternal", new Class[]{ObjectOutput.class}); + if (isExternalizable) + { + _readExternal = _class.getDeclaredMethod("readExternal", new Class[] { ObjectInput.class } ); + _writeExternal = _class.getDeclaredMethod("writeExternal", new Class[] { ObjectOutput.class } ); } // SG: Hopefully we got all the info that is needed - if (recursive) { + if(recursive) + { return; } @@ -337,75 +388,89 @@ java.lang.Class tmpClass = _class; ArrayList fieldList = new ArrayList(); Field[] javaFields = tmpClass.getDeclaredFields(); - + // TODO: suppress sort for IDL-generated valuetypes Arrays.sort(javaFields, FieldComparator.SINGLETON); - + // Create vector of non-static, non-transient fields. // Ensure that all fields are readable/writable using reflection. int nf = javaFields.length; - for (int f = 0; f < nf; f++) { + for (int f = 0; f < nf; f++) + { Field javaField = javaFields[f]; int modifiers = javaField.getModifiers(); - if ((modifiers & (Modifier.STATIC | Modifier.TRANSIENT)) != 0) { + if ((modifiers & (Modifier.STATIC | Modifier.TRANSIENT)) != 0) + { continue; } - if (!javaField.isAccessible()) { + if (! javaField.isAccessible()) + { javaField.setAccessible(true); } ValueTypeField field = new ValueTypeField(javaField); fieldList.add(field); } - fields = (ValueTypeField[]) fieldList.toArray(new ValueTypeField[fieldList.size()]); + fields = (ValueTypeField[])fieldList.toArray(new ValueTypeField[fieldList.size()]); // Check methods for readObject/writeObject. Also check for // abstract interfaces. Method[] methods = _class.getDeclaredMethods(); int countThrowsRemoteException = 0; int nm = methods.length; - for (int m = 0; m < nm; m++) { + for (int m = 0; m < nm; m++) + { Method method = methods[m]; Class[] types = method.getParameterTypes(); if (types.length == 1 && types[0] == java.io.ObjectInputStream.class && (method.getModifiers() & Modifier.PRIVATE) != 0 - && method.getName().equals("readObject")) { + && method.getName().equals("readObject")) + { _readObject = method; - if (!_readObject.isAccessible()) { + if (! _readObject.isAccessible()) + { _readObject.setAccessible(true); } } if (types.length == 1 && types[0] == java.io.ObjectOutputStream.class && (method.getModifiers() & Modifier.PRIVATE) != 0 - && method.getName().equals("writeObject")) { + && method.getName().equals("writeObject")) + { _writeObject = method; - if (!_writeObject.isAccessible()) { + if (! _writeObject.isAccessible()) + { _writeObject.setAccessible(true); } } if (types.length == 0 && method.getReturnType() == java.lang.Object.class - && method.getName().equals("writeReplace")) { + && method.getName().equals("writeReplace")) + { _writeReplace = method; - if (!_writeReplace.isAccessible()) { + if (! _writeReplace.isAccessible()) + { _writeReplace.setAccessible(true); } } if (types.length == 0 - && method.getReturnType() == java.lang.Object.class - && method.getName().equals("readResolve")) { + && method.getReturnType() == java.lang.Object.class + && method.getName().equals("readResolve")) + { _readResolve = method; - if (!_readResolve.isAccessible()) { + if (! _readResolve.isAccessible()) + { _readResolve.setAccessible(true); } } Class[] exceptions = method.getExceptionTypes(); - for (int i = 0; i < exceptions.length; i++) { + for (int i = 0; i < exceptions.length; i++) + { Class exception = exceptions[i]; - if (exception.isAssignableFrom(java.rmi.RemoteException.class)) { + if (exception.isAssignableFrom(java.rmi.RemoteException.class)) + { // TODO: check Java to IDL wording for this countThrowsRemoteException++; break; @@ -419,20 +484,21 @@ hasWriteReplace = _writeReplace != null; hasReadResolve = _readResolve != null; - isAbstractInterface = !isObjectRef - && _class.isInterface() - && countThrowsRemoteException == methods.length; + isAbstractInterface = ! isObjectRef + && _class.isInterface() + && countThrowsRemoteException == methods.length; Class superclass = _class.getSuperclass(); - if ((superclass != null) && (superclass != java.lang.Object.class) && (!isIDLEntity)) { + if((superclass != null) && (superclass != java.lang.Object.class) && (!isIDLEntity )) + { parent = getInstance(superclass); } hasParentState = parent != null - && (parent.fields.length > 0 - || parent.isExternalizable - || parent.hasReadOrWriteObject - || parent.hasParentState); + && (parent.fields.length > 0 + || parent.isExternalizable + || parent.hasReadOrWriteObject + || parent.hasParentState); requiresCustomSerialization = hasWriteObject || isExternalizable; @@ -440,44 +506,57 @@ initTypeCode(); isAnyOrObjectRefOrAbstractInterface = isAny || isObjectRef || isAbstractInterface; - } catch (Exception ex) { + } + catch (Exception ex) + { throw ExceptionUtil.getRuntimeException(ex); - } finally { - if (!recursive) { - _initMap.remove(theClass); - } + } + finally + { + if(!recursive) + { + _initMap.remove(theClass); } } + } - protected void initRepositoryID() { + protected void initRepositoryID() + { final String sixteenZeros = "0000000000000000"; final int requiredLength = 16; - if (isAny) { + if (isAny) + { id = "#ANY-TODO#"; return; } - if (isArray && primitiveArray != 0) { + if (isArray && primitiveArray != 0) + { id = "#ARRAY-TODO#"; return; } - if (_class == String.class) { + if (_class == String.class) + { id = "IDL:omg.org/CORBA/WStringValue:1.0"; return; } - if (isObjectRef) { + if (isObjectRef) + { id = "RMI:" + _class.getName() + ":" + sixteenZeros; return; } - if (_class == java.lang.Class.class) { + if (_class == java.lang.Class.class) + { id = "RMI:javax.rmi.CORBA.ClassDesc:2BABDA04587ADCCC:CFBF02CF5294176B"; return; } - if (_class == java.math.BigInteger.class) { + if (_class == java.math.BigInteger.class) + { id = "RMI:java.math.BigInteger:8CAD1A3C6C0A9DF0:8CFC9F1FA93BFB1D"; skipCustomFlags = true; // TODO: move this and check usage return; } - if (_objectStreamClass == null) { + if (_objectStreamClass == null) + { id = "???"; return; } @@ -488,56 +567,80 @@ int currentLength; int lengthNeeded; currentLength = structuralUIDString.length(); - if (currentLength < requiredLength) { + if (currentLength < requiredLength) + { lengthNeeded = requiredLength - currentLength; structuralUIDString = sixteenZeros.substring(0, lengthNeeded) + structuralUIDString; } currentLength = serialVersionUIDString.length(); - if (currentLength < requiredLength) { + if (currentLength < requiredLength) + { lengthNeeded = requiredLength - currentLength; serialVersionUIDString = sixteenZeros.substring(0, lengthNeeded) + serialVersionUIDString; } id = "RMI:" + _class.getName() + ":" + structuralUIDString + ":" + serialVersionUIDString; } - protected void initTypeCode() { - if (isObjectRef) { + protected void initTypeCode() + { + if (isObjectRef) + { tc = new TypeCode(TCKind.tk_objref); tc.id(id); tc.name(""); - } else if (isArray || isIDLEntity || _class == String.class) { + } + else if (isArray || isIDLEntity || _class == String.class) + { tc = new TypeCode(TCKind.tk_value_box); tc.id(id); tc.name(""); - if (_class == String.class) { + if (_class == String.class) + { tc.content_type(new TypeCode(TCKind.tk_wstring)); - } else if (isArray) { + } + else if (isArray) + { TypeCode seqTC = new TypeCode(TCKind.tk_sequence); - if (primitiveArray != 0) { + if (primitiveArray != 0) + { seqTC.content_type(PrimitiveType.getTypeCode(primitiveArray)); - } else { + } + else + { seqTC.content_type(element.tc); } tc.content_type(seqTC); - } else if (isIDLEntity) { + } + else if (isIDLEntity) + { // TODO tc.content_type(helper.type()); } - } else { + } + else + { tc = new TypeCode(TCKind.tk_value); tc.id(id); tc.name(""); // TODO: value modifier - if (requiresCustomSerialization) { - tc.type_modifier((short) 1); - } else if (isAbstractInterface) { - tc.type_modifier((short) 2); - } else { - tc.type_modifier((short) 0); + if (requiresCustomSerialization) + { + tc.type_modifier((short)1); + } + else if (isAbstractInterface) + { + tc.type_modifier((short)2); + } + else + { + tc.type_modifier((short)0); } - if (parent == null) { + if (parent == null) + { tc.concrete_base_type(TC_NULL); - } else { + } + else + { // TODO: check validity of this tc.concrete_base_type(TC_NULL); // tc.concrete_base_type(getTypeCode(parent)); @@ -547,128 +650,119 @@ } } - static long computeStructuralUID(ValueType vt) { + static long computeStructuralUID(ValueType vt) + { Class c = vt._class; ObjectStreamClass osc = vt._objectStreamClass; ByteArrayOutputStream devnull = new ByteArrayOutputStream(512); long h = 0; - try { - if (!java.io.Serializable.class.isAssignableFrom(c) - || c.isInterface()) { + try + { + if (! java.io.Serializable.class.isAssignableFrom(c) + || c.isInterface()) + { return 0; } - if (java.io.Externalizable.class.isAssignableFrom(c)) { + if (java.io.Externalizable.class.isAssignableFrom(c)) + { return 1; } MessageDigest md = MessageDigest.getInstance("SHA"); DigestOutputStream mdo = new DigestOutputStream(devnull, md); DataOutputStream data = new DataOutputStream(mdo); - if (vt.parent != null) { + if (vt.parent != null) + { data.writeLong(computeStructuralUID(vt.parent)); } - if (vt.hasWriteObject) { + if (vt.hasWriteObject) + { data.writeInt(2); - } else { + } + else + { data.writeInt(1); } List fieldList = new ArrayList(vt.fields.length); - for (int i = 0; i < vt.fields.length; i++) { + for (int i = 0; i < vt.fields.length; i++) + { fieldList.add(vt.fields[i].javaField); } - Field[] fields = (Field[]) fieldList.toArray(new Field[fieldList.size()]); + Field[] fields = (Field[])fieldList.toArray(new Field[fieldList.size()]); Arrays.sort(fields, FieldByNameComparator.SINGLETON); - for (int i = 0; i < vt.fields.length; i++) { + for (int i = 0; i < vt.fields.length; i++) + { Field f = fields[i]; data.writeUTF(f.getName()); data.writeUTF(JavaClass.getSignature(f.getType())); } data.flush(); byte[] hasharray = md.digest(); - for (int i = 0; i < Math.min(8, hasharray.length); i++) { - h += (long) (hasharray[i] & 255) << (i * 8); + for (int i = 0; i < Math.min(8, hasharray.length); i++) + { + h += (long)(hasharray[i] & 255) << (i * 8); } return h; - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } /** - * * Map an RMI/IDL Repository ID to a java.lang.Class. - */ - static Class getClass(String id) { - if (id.startsWith("RMI:")) { + ** Map an RMI/IDL Repository ID to a java.lang.Class. + **/ + static Class getClass(String id) + { + if (id.startsWith("RMI:")) + { int endClass = id.indexOf(':', 4); - if (endClass == -1) { + if (endClass == -1) + { throw new org.omg.CORBA.INV_IDENT(id); } String className = id.substring(4, endClass); - if (className.equals("javax.rmi.CORBA.ClassDesc")) { + if (className.equals("javax.rmi.CORBA.ClassDesc")) + { return Class.class; - } else { + } + else + { return loadClass(className); } - } else if (id.equals("IDL:omg.org/CORBA/WStringValue:1.0")) { + } + else if (id.equals("IDL:omg.org/CORBA/WStringValue:1.0")) + { return java.lang.String.class; - } else if (id.startsWith("IDL:omg.org/")) { + } + else if (id.startsWith("IDL:omg.org/")) + { int endClass = id.indexOf(':', 12); - if (endClass == -1) { + if (endClass == -1) + { throw new org.omg.CORBA.INV_IDENT(id); } - String className = "org.omg" + id.substring("IDL:omg.org".length(), endClass).replace('/', '.'); + String className = "org.omg" + id.substring( "IDL:omg.org".length(), endClass).replace('/', '.'); return loadClass(className); - } else if (id.startsWith("IDL:")) { + } + else if (id.startsWith("IDL:")) + { int endClass = id.indexOf(':', 4); - if (endClass == -1) { + if (endClass == -1) + { throw new org.omg.CORBA.INV_IDENT(id); } String className = id.substring(4, endClass).replace('/', '.'); return loadClass(className); - } else { - throw new org.omg.CORBA.INV_IDENT(id); } - } - - static Class loadClass(String className) { - Class c = null; - - System.out.println("loadClass(): " + className); - - try { - //c = Class.forName( className ); - c = ClassLoader.getSystemClassLoader().loadClass(className); - } catch (Exception e) { - e.printStackTrace(); + else + { + throw new org.omg.CORBA.INV_IDENT(id); } - - //return ThreadContext.loadClass(className); - return c; } - public static void main(String args[]) - throws Exception { - Class c = Class.forName(args[0]); - ValueType vt = ValueType.getInstance(c); - System.out.println("vt = " + vt.toString()); - System.out.println("vt.id = " + vt.id); - System.out.println("vt.tc = " + vt.tc.id()); - - c = Class.forName("org.omg.CosNaming.NameComponent"); - vt = ValueType.getInstance(c); - System.out.println("vt = " + vt.toString()); - System.out.println("vt.id = " + vt.id); - System.out.println("vt.tc = " + vt.tc.id()); - - c = ValueType.getClass("RMI:mark.comps.Add:0000000000000000"); - System.out.println("c.getName() = " + c.getName()); - - c = ValueType.getClass("RMI:org.omg.CosNaming.NameComponent:7FD3FB2290230F5E:F164A2194A66282A"); - System.out.println("c.getName() = " + c.getName()); - - c = ValueType.getClass("IDL:omg.org/CosNaming/NameComponent:1.0"); - System.out.println("c.getName() = " + c.getName()); - - c = ValueType.getClass("RMI:mark.AddData:4165959D0B2418DD:747FE23938318E95"); - System.out.println("c.getName() = " + c.getName()); + static Class loadClass(String className) + { + return ThreadContext.loadClass(className); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java Wed Mar 23 09:56:34 2005 @@ -17,169 +17,320 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.lang.reflect.Field; +import org.apache.geronimo.interop.*; +import java.lang.reflect.*; -import org.apache.geronimo.interop.SystemException; - - -public class ValueTypeField { +public class ValueTypeField +{ public final Field javaField; public final int primitive; public final ValueType type; - public ValueTypeField(Field field) { + private final boolean isFinal; + + private FinalFieldSetter finalFieldSetter; + + public ValueTypeField(Field field) + { javaField = field; - if (field.getType().isPrimitive()) { + if (field.getType().isPrimitive()) + { primitive = PrimitiveType.get(field.getType()); type = null; - } else { + } + else + { primitive = 0; type = ValueType.getInstance(field.getType()); } + if(Modifier.isFinal(field.getModifiers())) + { + isFinal = true; + finalFieldSetter = FinalFieldSetter.getInstance(field); + } + else + { + isFinal = false; + } } - public boolean getBoolean(Object that) { - try { + public boolean getBoolean(Object that) + { + try + { return javaField.getBoolean(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public byte getByte(Object that) { - try { + public byte getByte(Object that) + { + try + { return javaField.getByte(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public char getChar(Object that) { - try { + public char getChar(Object that) + { + try + { return javaField.getChar(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public double getDouble(Object that) { - try { + public double getDouble(Object that) + { + try + { return javaField.getDouble(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public float getFloat(Object that) { - try { + public float getFloat(Object that) + { + try + { return javaField.getFloat(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public int getInt(Object that) { - try { + public int getInt(Object that) + { + try + { return javaField.getInt(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public long getLong(Object that) { - try { + public long getLong(Object that) + { + try + { return javaField.getLong(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public short getShort(Object that) { - try { + public short getShort(Object that) + { + try + { return javaField.getShort(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public Object get(Object that) { - try { + public Object get(Object that) + { + try + { return javaField.get(that); - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setBoolean(Object that, boolean value) { - try { - javaField.setBoolean(that, value); - } catch (Exception ex) { + public void setBoolean(Object that, boolean value) + { + try + { + if(isFinal) + { + finalFieldSetter.setBoolean(that, value); + } + else + { + javaField.setBoolean(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setByte(Object that, byte value) { - try { - javaField.setByte(that, value); - } catch (Exception ex) { + public void setByte(Object that, byte value) + { + try + { + if(isFinal) + { + finalFieldSetter.setByte(that, value); + } + else + { + javaField.setByte(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setChar(Object that, char value) { - try { - javaField.setChar(that, value); - } catch (Exception ex) { + public void setChar(Object that, char value) + { + try + { + if(isFinal) + { + finalFieldSetter.setChar(that, value); + } + else + { + javaField.setChar(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setDouble(Object that, double value) { - try { - javaField.setDouble(that, value); - } catch (Exception ex) { + public void setDouble(Object that, double value) + { + try + { + if(isFinal) + { + finalFieldSetter.setDouble(that, value); + } + else + { + javaField.setDouble(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setFloat(Object that, float value) { - try { - javaField.setFloat(that, value); - } catch (Exception ex) { + public void setFloat(Object that, float value) + { + try + { + if(isFinal) + { + finalFieldSetter.setFloat(that, value); + } + else + { + javaField.setFloat(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setInt(Object that, int value) { - try { - javaField.setInt(that, value); - } catch (Exception ex) { + public void setInt(Object that, int value) + { + try + { + if(isFinal) + { + finalFieldSetter.setInt(that, value); + } + else + { + javaField.setInt(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setLong(Object that, long value) { - try { - javaField.setLong(that, value); - } catch (Exception ex) { + public void setLong(Object that, long value) + { + try + { + if(isFinal) + { + finalFieldSetter.setLong(that, value); + } + else + { + javaField.setLong(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void setShort(Object that, short value) { - try { - javaField.setShort(that, value); - } catch (Exception ex) { + public void setShort(Object that, short value) + { + try + { + if(isFinal) + { + finalFieldSetter.setShort(that, value); + } + else + { + javaField.setShort(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } } - public void set(Object that, Object value) { - try { - javaField.set(that, value); - } catch (Exception ex) { + public void set(Object that, Object value) + { + try + { + if(isFinal) + { + finalFieldSetter.set(that, value); + } + else + { + javaField.set(that, value); + } + } + catch (Exception ex) + { throw new SystemException(ex); } }