Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FieldComparator.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FieldComparator.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FieldComparator.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FieldComparator.java Fri Mar 25 03:54:30 2005 @@ -17,35 +17,46 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.lang.reflect.Field; -import java.util.Comparator; - +import java.lang.reflect.*; +import java.util.*; /** - * * Sort fields in the order they must be marshalled for RMI-IIOP. - */ -public class FieldComparator implements Comparator { + ** Sort fields in the order they must be marshalled for RMI-IIOP. + **/ +public class FieldComparator implements Comparator +{ public static final FieldComparator SINGLETON = new FieldComparator(); - public int compare(Object x, Object y) { - Field a = (Field) x; - Field b = (Field) y; - if (a.getType().isPrimitive()) { - if (b.getType().isPrimitive()) { + public int compare(Object x, Object y) + { + Field a = (Field)x; + Field b = (Field)y; + if (a.getType().isPrimitive()) + { + if (b.getType().isPrimitive()) + { return a.getName().compareTo(b.getName()); - } else { + } + else + { return -1; } - } else { - if (b.getType().isPrimitive()) { + } + else + { + if (b.getType().isPrimitive()) + { return 1; - } else { + } + else + { return a.getName().compareTo(b.getName()); } } } - public boolean equals(Object x) { + public boolean equals(Object x) + { // shouldn't be used return false; }
Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetter.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetter.java?view=auto&rev=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetter.java (added) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetter.java Fri Mar 25 03:54:30 2005 @@ -0,0 +1,50 @@ +/** + * + * 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; + +import org.apache.geronimo.interop.util.SystemUtil; + +import java.lang.reflect.Field; + +public abstract class FinalFieldSetter +{ + private static final boolean JDK14 = SystemUtil.isJDK14(); + + public static FinalFieldSetter getInstance(Field f) + { + if(JDK14) + { + return new FinalFieldSetterJdk14(f); + } + else + { + throw new RuntimeException("FinalFieldSetter is not implemented for jdk version: " + + SystemUtil.getVmVersion()); + } + } + + public abstract void setBoolean(Object that, boolean value); + public abstract void setByte(Object that, byte value); + public abstract void setChar(Object that, char value); + public abstract void setDouble(Object that, double value); + public abstract void setFloat(Object that, float value); + public abstract void setInt(Object that, int value); + public abstract void setLong(Object that, long value); + public abstract void setShort(Object that, short value); + public abstract void set(Object that, Object value); +} Added: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetterJdk14.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetterJdk14.java?view=auto&rev=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetterJdk14.java (added) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/FinalFieldSetterJdk14.java Fri Mar 25 03:54:30 2005 @@ -0,0 +1,107 @@ +/** + * + * 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; + +import java.lang.reflect.Field; + +/* + * FinalFields that are sent across the wire .. how to unmarshall and recreate the object on the + * receiving side? We don't want to invoke the constructor since it would establish values for + * final fields. We have to recreate the final field exactly like it was on the sender side. + * + * The sun.misc.Unsafe does this for us. + */ + +public class FinalFieldSetterJdk14 extends FinalFieldSetter +{ + private final long fieldOffset; + private static final sun.misc.Unsafe unsafe; //Only available for Sun's JDK1.4+ + + static + { + sun.misc.Unsafe val = null; + try + { + Class unsafeClass = Class.forName("sun.misc.Unsafe"); + Field unsafeField = unsafeClass.getDeclaredField("theUnsafe"); + unsafeField.setAccessible(true); + val = (sun.misc.Unsafe)unsafeField.get((java.lang.Object)null); + } + catch(Throwable e) + { + } + unsafe = val; + } + + public FinalFieldSetterJdk14(Field field) + { + if(unsafe != null) + { + fieldOffset = unsafe.objectFieldOffset(field); + } + else + { + fieldOffset = -1; + } + } + + public void setBoolean(Object that, boolean value) + { + unsafe.putBoolean(that, fieldOffset, value); + } + + public void setByte(Object that, byte value) + { + unsafe.putByte(that, fieldOffset, value); + } + + public void setChar(Object that, char value) + { + unsafe.putChar(that, fieldOffset, value); + } + + public void setDouble(Object that, double value) + { + unsafe.putDouble(that, fieldOffset, value); + } + + public void setFloat(Object that, float value) + { + unsafe.putFloat(that, fieldOffset, value); + } + + public void setInt(Object that, int value) + { + unsafe.putInt(that, fieldOffset, value); + } + + public void setLong(Object that, long value) + { + unsafe.putLong(that, fieldOffset, value); + } + + public void setShort(Object that, short value) + { + unsafe.putShort(that, fieldOffset, value); + } + + public void set(Object that, Object value) + { + unsafe.putObject(that, fieldOffset, value); + } +} Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopMessage.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopMessage.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopMessage.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopMessage.java Fri Mar 25 03:54:30 2005 @@ -19,8 +19,8 @@ import org.apache.geronimo.interop.GIOP.*; - -public class GiopMessage { +public class GiopMessage +{ public int size; public int type; public int giopVersion; @@ -28,7 +28,8 @@ public LocateRequestHeader_1_2 locateRequest; public ReplyHeader_1_2 reply; - public String toString() { + public String toString() + { StringBuffer sb = new StringBuffer("GiopMessage("); /* TODO if (header != null) Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopVersion.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopVersion.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopVersion.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/GiopVersion.java Fri Mar 25 03:54:30 2005 @@ -17,7 +17,8 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public class GiopVersion { +public class GiopVersion +{ public static final int VERSION_1_0 = 0; public static final int VERSION_1_1 = 1; public static final int VERSION_1_2 = 2; Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IDLEntityHelper.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IDLEntityHelper.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IDLEntityHelper.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IDLEntityHelper.java Fri Mar 25 03:54:30 2005 @@ -17,14 +17,13 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.lang.reflect.Method; +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.util.*; +import java.lang.reflect.*; import java.util.HashMap; -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.util.ThreadContext; - - -public class IDLEntityHelper implements ObjectHelper { +public class IDLEntityHelper implements ObjectHelper +{ private static Class[] EMPTY_CLASS_ARRAY = {}; private static Object[] EMPTY_OBJECT_ARRAY = {}; @@ -39,71 +38,105 @@ private Method _write; - static IDLEntityHelper getInstance(Class theClass) { - IDLEntityHelper helper = (IDLEntityHelper) _helperMap.get(theClass); - if (helper == null) { - synchronized (_helperMap) { - helper = (IDLEntityHelper) _helperMap.get(theClass); - if (helper == null) { - helper = new IDLEntityHelper(theClass); - _helperMap.put(theClass, helper); - } - } + static IDLEntityHelper getInstance(Class theClass) + { + IDLEntityHelper helper = (IDLEntityHelper)_helperMap.get(theClass); + if (helper == null) + { + synchronized (_helperMap) + { + helper = (IDLEntityHelper)_helperMap.get(theClass); + if (helper == null) + { + helper = new IDLEntityHelper(theClass); + _helperMap.put(theClass, helper); + } + } } return helper; } - private IDLEntityHelper(Class theClass) { - try { + private IDLEntityHelper(Class theClass) + { + try + { Class helper = ThreadContext.loadClass(theClass.getName() + "Helper", theClass); _id = helper.getDeclaredMethod("id", EMPTY_CLASS_ARRAY); _type = helper.getDeclaredMethod("type", EMPTY_CLASS_ARRAY); - _read = helper.getDeclaredMethod("read", new Class[]{org.omg.CORBA.portable.InputStream.class}); - _write = helper.getDeclaredMethod("write", new Class[]{org.omg.CORBA.portable.OutputStream.class, theClass}); - } catch (SystemException ex) { - throw ex; - } catch (Exception ex) { - throw new SystemException(ex); + _read = helper.getDeclaredMethod("read", new Class[] { org.omg.CORBA.portable.InputStream.class }); + _write = helper.getDeclaredMethod("write", new Class[] { org.omg.CORBA.portable.OutputStream.class, theClass }); + } + catch (SystemException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new SystemException(ex); } } - public String id() { - try { - return (String) _id.invoke(null, EMPTY_OBJECT_ARRAY); - } catch (SystemException ex) { - throw ex; - } catch (Exception ex) { - throw new SystemException(ex); + public String id() + { + try + { + return (String)_id.invoke(null, EMPTY_OBJECT_ARRAY); + } + catch (SystemException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new SystemException(ex); } } - public org.omg.CORBA.TypeCode type() { - try { - return (org.omg.CORBA.TypeCode) _type.invoke(null, EMPTY_OBJECT_ARRAY); - } catch (SystemException ex) { - throw ex; - } catch (Exception ex) { - throw new SystemException(ex); + public org.omg.CORBA.TypeCode type() + { + try + { + return (org.omg.CORBA.TypeCode)_type.invoke(null, EMPTY_OBJECT_ARRAY); + } + catch (SystemException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new SystemException(ex); } } - public Object read(ObjectInputStream input) { - try { - return _read.invoke(null, new Object[]{input._cdrInput}); - } catch (SystemException ex) { - throw ex; - } catch (Exception ex) { - throw new SystemException(ex); + public Object read(ObjectInputStream input) + { + try + { + return _read.invoke(null, new Object[] { input._cdrInput }); } - } + catch (SystemException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new SystemException(ex); + } + } - public void write(ObjectOutputStream output, Object value) { - try { - _write.invoke(null, new Object[]{output._cdrOutput, value}); - } catch (SystemException ex) { - throw ex; - } catch (Exception ex) { - throw new SystemException(ex); + public void write(ObjectOutputStream output, Object value) + { + try + { + _write.invoke(null, new Object[] { output._cdrOutput, value }); } - } + catch (SystemException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new SystemException(ex); + } + } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IiopVersion.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IiopVersion.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IiopVersion.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/IiopVersion.java Fri Mar 25 03:54:30 2005 @@ -17,5 +17,6 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public class IiopVersion { +public class IiopVersion +{ } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ListenerInfo.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ListenerInfo.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ListenerInfo.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ListenerInfo.java Fri Mar 25 03:54:30 2005 @@ -1,26 +0,0 @@ -/** - * - * 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; - -public class ListenerInfo { - public int protocol; - - public String host; - - public int port; -} Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/NameServiceOperations_Skeleton.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/NameServiceOperations_Skeleton.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/NameServiceOperations_Skeleton.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/NameServiceOperations_Skeleton.java Fri Mar 25 03:54:30 2005 @@ -1,373 +0,0 @@ -// -// CORBA RMI-IIOP Skeleton Generator -// Interface: NameServiceOperations_Skeleton -// Date: Wed Dec 08 15:22:39 EST 2004 - -/** - * - * 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; - -import java.util.HashMap; - - -public class NameServiceOperations_Skeleton - extends RemoteObject - implements RemoteInterface { - // - // Fields - // - public java.lang.String[] _ids = {"org.apache.geronimo.interop.rmi.iiop.NameServiceOperations", "RMI:org.apache.geronimo.interop.rmi.iiop.NameServiceOperations:0000000000000000", "NameService"}; - public java.util.HashMap _methods = new HashMap(10); - public org.apache.geronimo.interop.rmi.iiop.NameServiceOperations _servant = null; - public java.lang.String _f3 = "f1"; - public java.lang.String[] _f4 = {"f1", "f2"}; - public org.apache.geronimo.interop.rmi.iiop.ValueType vt$0 = org.apache.geronimo.interop.rmi.iiop.ValueType.getInstance(java.lang.String.class); - public org.apache.geronimo.interop.rmi.iiop.ValueType vt$1 = org.apache.geronimo.interop.rmi.iiop.ValueType.getInstance(org.apache.geronimo.interop.CosNaming.NameComponent[].class); - public org.apache.geronimo.interop.rmi.iiop.ValueType vt$2 = org.apache.geronimo.interop.rmi.iiop.ValueType.getInstance(org.omg.CORBA.Object.class); - public org.apache.geronimo.interop.rmi.iiop.ValueType vt$3 = org.apache.geronimo.interop.rmi.iiop.ValueType.getInstance(org.apache.geronimo.interop.CosNaming.BindingListHolder.class); - public org.apache.geronimo.interop.rmi.iiop.ValueType vt$4 = org.apache.geronimo.interop.rmi.iiop.ValueType.getInstance(org.apache.geronimo.interop.CosNaming.BindingIteratorHolder.class); - public org.apache.geronimo.interop.rmi.iiop.ValueType vt$5 = org.apache.geronimo.interop.rmi.iiop.ValueType.getInstance(org.apache.geronimo.interop.CosNaming.NamingContext.class); - - // - // Constructors - // - public NameServiceOperations_Skeleton() { - super(); - - registerMethods(); - } - - protected void registerMethods() { - super.registerMethods(); - - registerMethod("resolve_host", 0); - registerMethod("to_string", 1); - registerMethod("to_name", 2); - registerMethod("to_url", 3); - registerMethod("resolve_str", 4); - registerMethod("list", 5); - registerMethod("resolve", 6); - registerMethod("bind", 7); - registerMethod("bind_context", 8); - registerMethod("rebind", 9); - registerMethod("rebind_context", 10); - registerMethod("unbind", 11); - registerMethod("new_context", 12); - registerMethod("bind_new_context", 13); - } - - // - // Methods - // - - public void registerMethod(java.lang.String name, int id) { - _methods.put(name, new Integer(id)); - } - - public java.lang.String[] getIds() { - return _ids; - } - - public RemoteInterface $getSkeleton() { - return this; - } - - public ObjectRef $getObjectRef() { - org.apache.geronimo.interop.rmi.iiop.ObjectRef or = new ObjectRef(); - or.$setID("RMI:org.apache.geronimo.interop.rmi.iiop.NameServiceOperations:0000000000000000"); - or.$setObjectKey("org.apache.geronimo.interop.rmi.iiop.NameServiceOperations"); - return or; - } - - public void $invoke(java.lang.String methodName, byte[] objectKey, java.lang.Object instance, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - java.lang.Integer m = (Integer) _methods.get(methodName); - if (m == null) { - throw new org.omg.CORBA.BAD_OPERATION(methodName); - } - - _servant = (org.apache.geronimo.interop.rmi.iiop.NameServiceOperations) instance; - - if (m.intValue() < 0) { - super.invoke(m.intValue(), objectKey, instance, input, output); - } - - - switch (m.intValue()) { - case 0: - { - resolve_host(input, output); - } - break; - case 1: - { - to_string(input, output); - } - break; - case 2: - { - to_name(input, output); - } - break; - case 3: - { - to_url(input, output); - } - break; - case 4: - { - resolve_str(input, output); - } - break; - case 5: - { - list(input, output); - } - break; - case 6: - { - resolve(input, output); - } - break; - case 7: - { - bind(input, output); - } - break; - case 8: - { - bind_context(input, output); - } - break; - case 9: - { - rebind(input, output); - } - break; - case 10: - { - rebind_context(input, output); - } - break; - case 11: - { - unbind(input, output); - } - break; - case 12: - { - new_context(input, output); - } - break; - case 13: - { - bind_new_context(input, output); - } - break; - } - } - - public void resolve_host(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - java.lang.String rc; - - try { - java.lang.String p0 = (java.lang.String) input.readObject(vt$0); - rc = _servant.resolve_host(p0); - output.writeObject(vt$0, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void to_string(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - java.lang.String rc; - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - rc = _servant.to_string(p0); - output.writeObject(vt$0, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void to_name(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - org.apache.geronimo.interop.CosNaming.NameComponent[] rc; - - try { - java.lang.String p0 = (java.lang.String) input.readObject(vt$0); - rc = _servant.to_name(p0); - output.writeObject(vt$1, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void to_url(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - java.lang.String rc; - - try { - java.lang.String p0 = (java.lang.String) input.readObject(vt$0); - java.lang.String p1 = (java.lang.String) input.readObject(vt$0); - rc = _servant.to_url(p0, p1); - output.writeObject(vt$0, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void resolve_str(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - org.omg.CORBA.Object rc; - - try { - java.lang.String p0 = (java.lang.String) input.readObject(vt$0); - rc = _servant.resolve_str(p0); - output.writeObject(vt$2, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void list(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - - try { - int p0 = input.readInt(); - org.apache.geronimo.interop.CosNaming.BindingListHolder p1 = (org.apache.geronimo.interop.CosNaming.BindingListHolder) input.readObject(vt$3); - org.apache.geronimo.interop.CosNaming.BindingIteratorHolder p2 = (org.apache.geronimo.interop.CosNaming.BindingIteratorHolder) input.readObject(vt$4); - _servant.list(p0, p1, p2); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void resolve(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - org.omg.CORBA.Object rc; - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - rc = _servant.resolve(p0); - output.writeObject(vt$2, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void bind(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - org.omg.CORBA.Object p1 = (org.omg.CORBA.Object) input.readObject(vt$2); - _servant.bind(p0, p1); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void bind_context(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - org.apache.geronimo.interop.CosNaming.NamingContext p1 = (org.apache.geronimo.interop.CosNaming.NamingContext) input.readObject(vt$5); - _servant.bind_context(p0, p1); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void rebind(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - org.omg.CORBA.Object p1 = (org.omg.CORBA.Object) input.readObject(vt$2); - _servant.rebind(p0, p1); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void rebind_context(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - org.apache.geronimo.interop.CosNaming.NamingContext p1 = (org.apache.geronimo.interop.CosNaming.NamingContext) input.readObject(vt$5); - _servant.rebind_context(p0, p1); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void unbind(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - _servant.unbind(p0); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void new_context(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - org.apache.geronimo.interop.CosNaming.NamingContext rc; - - try { - rc = _servant.new_context(); - output.writeObject(vt$5, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } - - public void bind_new_context(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { - org.apache.geronimo.interop.CosNaming.NamingContext rc; - - try { - org.apache.geronimo.interop.CosNaming.NameComponent[] p0 = (org.apache.geronimo.interop.CosNaming.NameComponent[]) input.readObject(vt$1); - rc = _servant.bind_new_context(p0); - output.writeObject(vt$5, rc); - } catch (java.lang.Exception ex) { - ex.printStackTrace(); - } catch (java.lang.Error er) { - er.printStackTrace(); - } - } -} Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectHelper.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectHelper.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectHelper.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectHelper.java Fri Mar 25 03:54:30 2005 @@ -17,7 +17,8 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public interface ObjectHelper { +public interface ObjectHelper +{ public Object read(ObjectInputStream input); public void write(ObjectOutputStream output, Object value); Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectInputStream.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectInputStream.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectInputStream.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectInputStream.java Fri Mar 25 03:54:30 2005 @@ -17,39 +17,48 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.io.IOException; -import java.io.NotActiveException; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.HashMap; - import org.omg.CORBA.TCKind; - -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.util.ArrayUtil; import org.apache.geronimo.interop.util.IntegerCache; +import org.apache.geronimo.interop.util.ArrayUtil; +import org.apache.geronimo.interop.SystemException; +import java.io.IOException; +import java.io.NotActiveException; +import java.util.HashMap; +import java.util.ArrayList; +import java.lang.reflect.Array; -public class ObjectInputStream extends java.io.ObjectInputStream { - public static ObjectInputStream getInstance() { - return getInstance(CdrInputStream.getInstance()); - } - - public static ObjectInputStream getInstance(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) { - ObjectInputStream input = null; +/** + ** TODO: package-private methods??? + **/ +public class ObjectInputStream extends java.io.ObjectInputStream +{ + //public static final Component component = new Component(ObjectInputStream.class); + + public static ObjectInputStream getInstance() + { + ObjectInputStream ois = null; try { - input = new ObjectInputStream(); - } catch (Exception ex) { - throw new SystemException(ex); + ois = new ObjectInputStream(); //getInstance(CdrInputStream.getInstance()); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + ois = null; } + return ois; + } + public static ObjectInputStream getInstance(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) + { + ObjectInputStream input = getInstance(); // (ObjectInputStream)component.getInstance(); input.init(cdrInput); return input; } - public static ObjectInputStream getPooledInstance() { - ObjectInputStream input = null; //(ObjectInputStream)_pool.get(); - if (input == null) { + public static ObjectInputStream getPooledInstance() + { + ObjectInputStream input = null; // (ObjectInputStream)_pool.get(); + if (input == null) + { input = getInstance(); } return input; @@ -59,12 +68,14 @@ // inner classes // ----------------------------------------------------------------------- - protected static class StreamState { + protected static class StreamState + { ValueType type; Object value; int offset; - StreamState(ValueType type, Object value, int offset) { + StreamState(ValueType type, Object value, int offset) + { this.type = type; this.value = value; this.offset = offset; @@ -101,15 +112,19 @@ // public methods // ----------------------------------------------------------------------- - public ObjectInputStream() throws IOException { + public ObjectInputStream() throws IOException + { } - public void $reset() { + public void $reset() + { _cdrInput.reset(); - if (_indirection != null) { + if (_indirection != null) + { _indirection.clear(); } - if (_stack != null) { + if (_stack != null) + { _stack.clear(); } _blockLength = MAXIMUM_BLOCK_LENGTH; @@ -117,50 +132,61 @@ _isChunked = false; } - public void recycle() { + public void recycle() + { $reset(); //_pool.put(this); } // public methods from java.io.ObjectInputStream - public boolean readBoolean() { + public boolean readBoolean() + { return _cdrInput.read_boolean(); } - public char readChar() { + public char readChar() + { return _cdrInput.read_wchar(); } - public byte readByte() { + public byte readByte() + { return _cdrInput.read_octet(); } - public short readShort() { + public short readShort() + { return _cdrInput.read_short(); } - public int readInt() { + public int readInt() + { return _cdrInput.read_long(); } - public long readLong() { + public long readLong() + { return _cdrInput.read_longlong(); } - public float readFloat() { + public float readFloat() + { return _cdrInput.read_float(); } - public double readDouble() { + public double readDouble() + { return _cdrInput.read_double(); } - public Object readObjectOverride() { + public Object readObjectOverride() + { return readObject(ValueType.OBJECT_VALUE_TYPE, false); } - public void defaultReadObject() throws IOException, ClassNotFoundException, NotActiveException { + public void defaultReadObject() throws IOException, ClassNotFoundException, NotActiveException + { StreamState state = top(); readDeclaredFields(state.type, state.value); } @@ -169,11 +195,13 @@ // public methods used by generated and package-internal code // ----------------------------------------------------------------------- - public Exception readException(ValueType type) { - return (Exception) readObject(type, false); + public Exception readException(ValueType type) + { + return (Exception)readObject(type, false); } - public Object readObject(ValueType type) { + public Object readObject(ValueType type) + { return readObject(type, false); } @@ -181,101 +209,135 @@ // protected methods // ----------------------------------------------------------------------- - protected void init(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) { + protected void init(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput) + { _cdrInput = cdrInput; - thisAsObjectArray = new Object[]{this}; + thisAsObjectArray = new Object[] { this }; } - protected void putIndirection(Integer key, Object value) { - if (_indirection == null) { + protected void putIndirection(Integer key, Object value) + { + if (_indirection == null) + { _indirection = new HashMap(); } _indirection.put(key, value); } - protected Object readObject(ValueType declaredType, boolean calledByCustomSerialization) { + protected Object readObject(ValueType declaredType, boolean calledByCustomSerialization) + { org.omg.CORBA.TypeCode tc = null; int tag = _cdrInput.read_ulong(); int saveOffset = _cdrInput._offset - 4; Object value; - if (tag == ValueType.INDIRECTION_TAG) { + if (tag == ValueType.INDIRECTION_TAG) + { // Indirection to value already read (or cyclic value being read). saveOffset = _cdrInput._offset; int offset = _cdrInput.read_long(); Integer key = IntegerCache.get(saveOffset + offset); - if (_indirection != null) { + if (_indirection != null) + { value = _indirection.get(key); - if (value != null) { + if (value != null) + { return value; } } throw new org.omg.CORBA.MARSHAL("invalid indirection offset = " + offset); - } else { + } + else + { _cdrInput._offset = saveOffset; } - if (calledByCustomSerialization) { + if (calledByCustomSerialization) + { boolean isObjectRef = _cdrInput.read_boolean(); - if (isObjectRef) { + if (isObjectRef) + { org.omg.CORBA.Object ref = _cdrInput.read_Object(); endBlock(); - if (_blockLength == MAXIMUM_BLOCK_LENGTH) { + if (_blockLength == MAXIMUM_BLOCK_LENGTH) + { startBlock(); } return ref; - } else { + } + else + { _cdrInput._offset = saveOffset; } - } else if (declaredType.isAnyOrObjectRefOrAbstractInterface) { + } + else if (declaredType.isAnyOrObjectRefOrAbstractInterface) + { boolean isObjectRef = false; - if (declaredType.isObjectRef) { + if (declaredType.isObjectRef) + { return _cdrInput.read_Object(); - } else if (declaredType.isAny) { + } + else if (declaredType.isAny) + { tc = _cdrInput.read_TypeCode(); int kind = tc.kind().value(); - if (kind == TCKind._tk_null) { + if(kind == TCKind._tk_null) + { return null; } - if (kind == TCKind._tk_objref) { + if(kind == TCKind._tk_objref) + { isObjectRef = true; - } else if (kind == TCKind._tk_abstract_interface) { + } + else if(kind == TCKind._tk_abstract_interface) + { isObjectRef = _cdrInput.read_boolean(); } - if (isObjectRef) { + if(isObjectRef) + { saveOffset = _cdrInput._offset; int checkValue = _cdrInput.read_ulong(); - if (checkValue == 0) { + if(checkValue == 0) + { return null; } _cdrInput._offset = saveOffset; return _cdrInput.read_Object(); } - } else if (declaredType.isAbstractInterface) { + } + else if (declaredType.isAbstractInterface) + { isObjectRef = _cdrInput.read_boolean(); - if (isObjectRef) { + if (isObjectRef) + { return _cdrInput.read_Object(); } - } else { + } + else + { throw new IllegalStateException(declaredType.toString()); } } saveOffset = _cdrInput._offset; tag = _cdrInput.read_long(); - if (tag == ValueType.NULL_VALUE_TAG) { + if (tag == ValueType.NULL_VALUE_TAG) + { return null; } - if (tag == ValueType.INDIRECTION_TAG) { + if (tag == ValueType.INDIRECTION_TAG) + { // Indirection to value already read (or cyclic value being read). saveOffset = _cdrInput._offset; int offset = _cdrInput.read_long(); Integer key = IntegerCache.get(saveOffset + offset); - if (_indirection != null) { + if (_indirection != null) + { value = _indirection.get(key); - if (value != null) { + if (value != null) + { return value; } } @@ -285,26 +347,35 @@ boolean saveIsChunked = _isChunked; _isChunked = (tag & 0x00000008) != 0; String codebaseURL = null; - if ((tag & 0x00000001) == 1) { + if ((tag & 0x00000001) == 1) + { codebaseURL = readMetaString(); } - switch (tag & 0x00000006) { + switch (tag & 0x00000006) + { case 0: // NO_TYPE_VALUE_TAG { actualType = declaredType; - if (tc != null) { - try { + if (tc != null) + { + try + { String id = tc.id(); - if (id != null) { + if (id != null) + { int kind = tc.kind().value(); - if (kind == TCKind._tk_value_box) { + if (kind == TCKind._tk_value_box) + { kind = tc.content_type().kind().value(); - if (kind == TCKind._tk_wstring) { + if (kind == TCKind._tk_wstring) + { actualType = ValueType.STRING_VALUE_TYPE; } } } - } catch (Exception ex) { + } + catch (Exception ex) + { throw new SystemException(ex); } } @@ -320,13 +391,15 @@ case 6: // TYPE_LIST_VALUE_TAG { int n = _cdrInput.read_ulong(); - if (n < 1) { + if (n < 1) + { throw new org.omg.CORBA.MARSHAL("invalid type list length = " + n); } String repositoryID = readMetaString(); // TODO requiresCustomSerialization = (Boolean)_specialCaseReposIds.get(repositoryID); actualType = ValueType.getInstanceByID(repositoryID); - for (int i = 1; i < n; i++) { + for (int i = 1; i < n; i++) + { String ignore = readMetaString(); } } @@ -334,16 +407,19 @@ default: throw new org.omg.CORBA.MARSHAL("invalid value tag = " + tag); } - if (actualType.isObjectRef) { + if (actualType.isObjectRef) + { value = actualType.helper.read(this); return value; } startBlock(); - if (_isChunked) { + if (_isChunked) + { _endLevel--; } Integer key = new Integer(saveOffset); - switch (actualType.readWriteCase) { + switch (actualType.readWriteCase) + { case ValueType.CASE_ARRAY: value = readArray(actualType, key); break; @@ -355,7 +431,7 @@ value = actualType.helper.read(this); putIndirection(key, value); break; - // case ValueType.CASE_IDL_OBJECT: // already handled above + // case ValueType.CASE_IDL_OBJECT: // already handled above case ValueType.CASE_STRING: value = _cdrInput.read_wstring(); putIndirection(key, value); @@ -364,7 +440,8 @@ value = actualType.newInstance(); putIndirection(key, value); Object newValue = readObjectState(actualType, value, false); // requiresCustomSerialization); - if (newValue != value) { + if (newValue != value) + { value = newValue; putIndirection(key, value); } @@ -376,19 +453,24 @@ return value; } - protected String readMetaString() { + protected String readMetaString() + { String id; int saveOffset = _cdrInput._offset; int tag = _cdrInput.read_long(); - if (tag == ValueType.INDIRECTION_TAG) { + if (tag == ValueType.INDIRECTION_TAG) + { saveOffset = _cdrInput._offset; int offset = _cdrInput.read_long(); Integer key = IntegerCache.get(saveOffset + offset); - id = _indirection == null ? null : (String) _indirection.get(key); - if (id == null) { + id = _indirection == null ? null : (String)_indirection.get(key); + if (id == null) + { throw new org.omg.CORBA.MARSHAL("invalid indirection offset = " + offset); } - } else { + } + else + { _cdrInput._offset = saveOffset; id = _cdrInput.read_string(); putIndirection(IntegerCache.get(saveOffset), id); @@ -396,16 +478,20 @@ return id; } - protected Object readObjectState(ValueType valueType, Object value, boolean requiresCustomSerialization) { - if (valueType.isExternalizable) { + protected Object readObjectState(ValueType valueType, Object value, boolean requiresCustomSerialization) + { + if (valueType.isExternalizable) + { byte format = _cdrInput.read_octet(); valueType.readExternal(value, this); return value; } - if (valueType.hasParentState) { + if (valueType.hasParentState) + { value = readObjectState(valueType.parent, value, false); } - if (valueType.hasReadObject) { + if (valueType.hasReadObject) + { push(new StreamState(valueType, value, _cdrInput._offset)); /* TODO if (repositoryID.equals(_SUN_JDK_BIG_DECIMAL_REPOSID)) @@ -435,57 +521,80 @@ else */ { - if (valueType.hasWriteObject || requiresCustomSerialization) { + if (valueType.hasWriteObject || requiresCustomSerialization) + { byte format = _cdrInput.read_octet(); boolean defaultWriteObjectCalled = _cdrInput.read_boolean(); } valueType.readObject(value, this); } pop(); - } else { + } + else + { readDeclaredFields(valueType, value); } - if (valueType.hasReadResolve) { + while (value != null && valueType.hasReadResolve) + { value = valueType.readResolve(value); + if(value != null) + { + Class vc = value.getClass(); + valueType = ValueType.getInstance(vc); + } } return value; } - protected void readDeclaredFields(ValueType valueType, Object value) { + protected void readDeclaredFields(ValueType valueType, Object value) + { int n = valueType.fields.length; - for (int f = 0; f < n; f++) { + for (int f = 0; f < n; f++) + { ValueTypeField field = valueType.fields[f]; int primitive = field.primitive; - if (primitive != 0) { + if (primitive != 0) + { readPrimitive(primitive, field, value); - } else { + } + else + { field.set(value, readObject(field.type, false)); } } } - protected Object readClassDesc() { - String codebase = (String) readObject(ValueType.STRING_VALUE_TYPE); - String id = (String) readObject(ValueType.STRING_VALUE_TYPE); + protected Object readClassDesc() + { + String codebase = (String)readObject(ValueType.STRING_VALUE_TYPE); + String id = (String)readObject(ValueType.STRING_VALUE_TYPE); return ValueType.getInstanceByID(id)._class; } - protected Object readArray(ValueType arrayType, Integer key) { + protected Object readArray(ValueType arrayType, Integer key) + { Object value = null; int primitive = arrayType.primitiveArray; int n = _cdrInput.read_ulong(); - if (primitive != 0) { + if (primitive != 0) + { value = arrayType.helper.read(this); putIndirection(key, value); - } else { + } + else + { Object[] array; - try { - array = n == 0 ? ArrayUtil.EMPTY_OBJECT_ARRAY : (Object[]) Array.newInstance(arrayType.element._class, n); - } catch (Exception ex) { + try + { + array = n == 0 ? ArrayUtil.EMPTY_OBJECT_ARRAY : (Object[])Array.newInstance(arrayType.element._class, n); + } + catch (Exception ex) + { throw new SystemException(ex); } putIndirection(key, array); - for (int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) + { array[i] = readObject(arrayType.element, false); } value = array; @@ -493,8 +602,10 @@ return value; } - private void readPrimitive(int primitive, ValueTypeField field, Object value) { - switch (primitive) { + private void readPrimitive(int primitive, ValueTypeField field, Object value) + { + switch (primitive) + { case PrimitiveType.BOOLEAN: field.setBoolean(value, _cdrInput.read_boolean()); break; @@ -525,65 +636,82 @@ } /** - * * This method handle end tag compaction. Note that it is lazy in the - * * sense that it always assumes a tag has been compacted if the end tag - * * is not what it expected. - */ - protected void readEndTag() { - if (_isChunked) { + ** This method handle end tag compaction. Note that it is lazy in the + ** sense that it always assumes a tag has been compacted if the end tag + ** is not what it expected. + **/ + protected void readEndTag() + { + if (_isChunked) + { int anEndTag = _cdrInput.read_long(); - if (anEndTag != _endLevel) { + if (anEndTag != _endLevel) + { _cdrInput._offset -= 4; } _endLevel++; } } - protected void startBlock() { - if (!_isChunked) { + protected void startBlock() + { + if (! _isChunked) + { return; } _blockLength = _cdrInput.read_long(); if (_blockLength >= 0 - && _blockLength < MAXIMUM_BLOCK_LENGTH) { + && _blockLength < MAXIMUM_BLOCK_LENGTH) + { _blockLength += _cdrInput._offset; - } else { + } + else + { // Not a chunk length field. _blockLength = MAXIMUM_BLOCK_LENGTH; _cdrInput._offset -= 4; } } - protected void endBlock() { + protected void endBlock() + { // If in a chunk, check for underflow or overflow. - if (_blockLength != MAXIMUM_BLOCK_LENGTH) { - if (_blockLength == _cdrInput._offset) { + if (_blockLength != MAXIMUM_BLOCK_LENGTH) + { + if (_blockLength == _cdrInput._offset) + { // Chunk ended correctly. _blockLength = MAXIMUM_BLOCK_LENGTH; } } } - protected void push(StreamState state) { - if (_stack == null) { + protected void push(StreamState state) + { + if (_stack == null) + { _stack = new ArrayList(); } _stack.add(state); } - protected void pop() { + protected void pop() + { int n = _stack.size(); - if (n == 0) { + if (n == 0) + { throw new SystemException("pop: state stack empty"); } _stack.remove(n - 1); } - protected StreamState top() { + protected StreamState top() + { int n = _stack.size(); - if (n == 0) { + if (n == 0) + { throw new SystemException("top: state stack empty"); } - return (StreamState) _stack.get(n - 1); + return (StreamState)_stack.get(n - 1); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectKey.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectKey.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectKey.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectKey.java Fri Mar 25 03:54:30 2005 @@ -17,14 +17,12 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.util.Iterator; -import java.util.List; +import org.apache.geronimo.interop.security.*; +import org.apache.geronimo.interop.util.*; +import java.util.*; -import org.apache.geronimo.interop.security.User; -import org.apache.geronimo.interop.util.ListUtil; - - -public class ObjectKey { +public class ObjectKey +{ public static final int TYPE_MANAGER = 'M'; public static final int TYPE_SESSION = 'S'; @@ -35,7 +33,8 @@ public String component = ""; public String sessionID = ""; - public byte[] encode() { + public byte[] encode() + { int un = username.length(); int pn = password.length(); int cn = component.length(); @@ -47,34 +46,45 @@ keyBuffer.append(password); keyBuffer.append("\tC="); keyBuffer.append(component); - if (sn > 0) { + if (sn > 0) + { keyBuffer.append("\tS="); keyBuffer.append(sessionID); } byte[] bytes = SecurityInfo.encode(keyBuffer.toString()); - bytes[0] = (byte) type; + bytes[0] = (byte)type; return bytes; } - public void decode(byte[] bytes) { + public void decode(byte[] bytes) + { type = bytes.length == 0 ? 0 : bytes[0]; String key = SecurityInfo.decode(bytes); List items = ListUtil.getListWithSeparator(key, "\t"); - for (Iterator i = items.iterator(); i.hasNext();) { - String item = (String) i.next(); - if (item.startsWith("U=")) { + for (Iterator i = items.iterator(); i.hasNext();) + { + String item = (String)i.next(); + if (item.startsWith("U=")) + { username = item.substring(2); - } else if (item.startsWith("P=")) { + } + else if (item.startsWith("P=")) + { password = item.substring(2); - } else if (item.startsWith("C=")) { + } + else if (item.startsWith("C=")) + { component = item.substring(2); - } else if (item.startsWith("S=")) { + } + else if (item.startsWith("S=")) + { sessionID = item.substring(2); } } } - public void checkPassword() { + public void checkPassword() + { User.getInstance(username).login(password); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectOutputStream.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectOutputStream.java?view=diff&r1=159004&r2=159005 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectOutputStream.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectOutputStream.java Fri Mar 25 03:54:30 2005 @@ -17,34 +17,39 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.io.IOException; -import java.util.ArrayList; +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.util.*; +import java.io.*; +import java.util.*; + +public class ObjectOutputStream extends java.io.ObjectOutputStream +{ + //public static final Component component = new Component(ObjectOutputStream.class); -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.util.IntegerCache; -import org.apache.geronimo.interop.util.SimpleIdentityHashMap; - - -public class ObjectOutputStream extends java.io.ObjectOutputStream { - public static ObjectOutputStream getInstance() { - return getInstance(CdrOutputStream.getInstance()); - } - - public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput) { - ObjectOutputStream output = null; + public static ObjectOutputStream getInstance() + { + ObjectOutputStream oos = null; try { - output = new ObjectOutputStream(); - } catch (Exception ex) { - throw new SystemException(ex); + oos = new ObjectOutputStream(); //getInstance(CdrOutputStream.getInstance()); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + oos = null; } + return oos; + } + public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput) + { + ObjectOutputStream output = getInstance(); // (ObjectOutputStream)component.getInstance(); output.init(cdrOutput); return output; } - public static ObjectOutputStream getPooledInstance() { - ObjectOutputStream output = null; //(ObjectOutputStream)_pool.get(); - if (output == null) { + public static ObjectOutputStream getPooledInstance() + { + ObjectOutputStream output = null; // (ObjectOutputStream)_pool.get(); + if (output == null) + { output = getInstance(); } return output; @@ -54,12 +59,14 @@ // private data // ----------------------------------------------------------------------- - protected static class StreamState { + protected static class StreamState + { ValueType type; Object value; int offset; - StreamState(ValueType type, Object value, int offset) { + StreamState(ValueType type, Object value, int offset) + { this.type = type; this.value = value; this.offset = offset; @@ -106,16 +113,20 @@ // public methods // ----------------------------------------------------------------------- - public ObjectOutputStream() throws IOException { + public ObjectOutputStream() throws IOException + { super(); } - public void $reset() { + public void $reset() + { _cdrOutput.reset(); - if (_indirection != null) { + if (_indirection != null) + { _indirection.clear(); } - if (_stack != null) { + if (_stack != null) + { _stack.clear(); } _blockSizeIndex = -1; @@ -126,7 +137,8 @@ _booleanIndex = -1; } - public void recycle() { + public void recycle() + { $reset(); //_pool.put(this); } @@ -135,43 +147,53 @@ // public methods from java.io.ObjectOutputStream // ----------------------------------------------------------------------- - public void writeBoolean(boolean value) { + public void writeBoolean(boolean value) + { _cdrOutput.write_boolean(value); } - public void writeChar(char value) { + public void writeChar(char value) + { _cdrOutput.write_wchar(value); } - public void writeByte(byte value) { + public void writeByte(byte value) + { _cdrOutput.write_octet(value); } - public void writeShort(short value) { + public void writeShort(short value) + { _cdrOutput.write_short(value); } - public void writeInt(int value) { + public void writeInt(int value) + { _cdrOutput.write_long(value); } - public void writeLong(long value) { + public void writeLong(long value) + { _cdrOutput.write_longlong(value); } - public void writeFloat(float value) { + public void writeFloat(float value) + { _cdrOutput.write_float(value); } - public void writeDouble(double value) { + public void writeDouble(double value) + { _cdrOutput.write_double(value); } - public void writeObjectOverride(Object value) { + public void writeObjectOverride(Object value) + { writeObject(OBJECT_VALUE_TYPE, value); } - public void defaultWriteObject() throws IOException { + public void defaultWriteObject() throws IOException + { StreamState state = top(); // TODO: check this int saveOffset = _cdrOutput._offset; @@ -185,16 +207,23 @@ // public methods used by generated and package-internal code // ----------------------------------------------------------------------- - public boolean hasException() { + public boolean hasException() + { return _hasException; } - public void writeException(ValueType type, Exception value) { + public void writeException(ValueType type, Exception value) + { + String className = type._class.getName(); + String exType = StringUtil.removeSuffix(className, "Exception") + "Ex"; + String repositoryID = "IDL:" + exType.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) + { writeObject(type, value, false); } @@ -202,111 +231,153 @@ // protected methods // ----------------------------------------------------------------------- - protected void init(CdrOutputStream cdrOutput) { + protected void init(CdrOutputStream cdrOutput) + { _cdrOutput = cdrOutput; - thisAsObjectArray = new Object[]{this}; + thisAsObjectArray = new Object[] { this }; } - protected void putIndirection(Object value, Integer ref) { - if (_indirection == null) { + protected void putIndirection(Object value, Integer ref) + { + if (_indirection == null) + { _indirection = new SimpleIdentityHashMap(8); } _indirection.put(value, ref); } - protected void writeObject(ValueType declaredType, Object value, boolean calledFromCustomSerialization) { + protected void writeObject(ValueType declaredType, Object value, boolean calledFromCustomSerialization) + { ValueType actualType = declaredType; - if (value != null) { + while (value != null) + { Class vc = value.getClass(); - if (vc != declaredType._class) { + if (vc != declaredType._class) + { actualType = ValueType.getInstance(vc); } - if (actualType.hasWriteReplace) { + if (actualType.hasWriteReplace) + { value = actualType.writeReplace(value); } + else + { + break; + } } boolean saveIsChunked = _isChunked; - if (_inBlock) { - if (actualType != null) { - if (!(declaredType.isAny && actualType.isObjectRef)) { + if (_inBlock) + { + if (actualType != null) + { + if (! (declaredType.isAny && actualType.isObjectRef)) + { endBlock(); } } } - if (value == null) { - if (calledFromCustomSerialization) { + if (value == null) + { + if (calledFromCustomSerialization) + { _cdrOutput.write_boolean(actualType.isObjectRef); - if (actualType.isObjectRef) { - _cdrOutput.write_Object((org.omg.CORBA.Object) value); + if(actualType.isObjectRef) + { + _cdrOutput.write_Object((org.omg.CORBA.Object)value); endBlock(); - } else { - _cdrOutput.write_long(ValueType.NULL_VALUE_TAG); + } + else + { + _cdrOutput.write_long(ValueType.NULL_VALUE_TAG); } return; } - if (declaredType.isAny) { + if (declaredType.isAny) + { _cdrOutput.write_TypeCode(ValueType.TC_ABSTRACT_BASE); _cdrOutput.write_boolean(false); } - if (declaredType.isObjectRef) { - _cdrOutput.write_Object((org.omg.CORBA.Object) value); - } else { - if (declaredType.isAbstractInterface) { + if (declaredType.isObjectRef) + { + _cdrOutput.write_Object((org.omg.CORBA.Object)value); + } + else + { + if (declaredType.isAbstractInterface) + { _cdrOutput.write_boolean(false); } _cdrOutput.write_long(ValueType.NULL_VALUE_TAG); } return; } - if (declaredType.isAny && !calledFromCustomSerialization) { + if (declaredType.isAny && ! calledFromCustomSerialization) + { org.omg.CORBA.TypeCode tc = actualType.tc; _cdrOutput.write_TypeCode(tc); - } else if (declaredType.isAbstractInterface || calledFromCustomSerialization) { + } + else if (declaredType.isAbstractInterface || calledFromCustomSerialization) + { _cdrOutput.write_boolean(actualType.isObjectRef); - if (actualType.isObjectRef) { - _cdrOutput.write_Object((org.omg.CORBA.Object) value); + if (actualType.isObjectRef) + { + _cdrOutput.write_Object((org.omg.CORBA.Object)value); return; } } - if (actualType.isObjectRef) { - if (value instanceof RemoteInterface) { - value = ((RemoteInterface) value).$getObjectRef(); + if (actualType.isObjectRef) + { + if (value instanceof RemoteInterface) + { + ObjectRef objectRef = ((RemoteInterface)value).getObjectRef(); + //if (value instanceof AutomaticFailover) + //{ + // objectRef.$setAutomaticFailover(); + //} + value = objectRef; } - _cdrOutput.write_Object((org.omg.CORBA.Object) value); + _cdrOutput.write_Object((org.omg.CORBA.Object)value); return; } - Integer ref = _indirection == null ? null : (Integer) _indirection.get(value); - if (ref != null) { + Integer ref = _indirection == null ? null : (Integer)_indirection.get(value); + if (ref != null) + { _cdrOutput.write_long(ValueType.INDIRECTION_TAG); _cdrOutput.write_long(ref.intValue() - _cdrOutput._offset); return; - } else { + } + else + { _cdrOutput.write_align(4, 4); // write any necessary padding ref = IntegerCache.get(_cdrOutput._offset); putIndirection(value, ref); } - if (saveIsChunked || actualType.requiresCustomSerialization) { + if (saveIsChunked || actualType.requiresCustomSerialization) + { _cdrOutput.write_long(ValueType.TRUNCATABLE_SINGLE_TYPE_VALUE_TAG); _isChunked = true; - } else { + } + else + { _cdrOutput.write_long(ValueType.SINGLE_TYPE_VALUE_TAG); _isChunked = false; } writeMetaString(actualType.id); startBlock(); - switch (actualType.readWriteCase) { + switch (actualType.readWriteCase) + { case ValueType.CASE_ARRAY: writeArray(actualType, value); break; case ValueType.CASE_CLASS: - writeClassDesc((java.lang.Class) value); + writeClassDesc((java.lang.Class)value); break; case ValueType.CASE_IDL_ENTITY: actualType.helper.write(this, value); break; - // case ValueType.IDL_OBJECT: // already handled above + // case ValueType.IDL_OBJECT: // already handled above case ValueType.CASE_STRING: - _cdrOutput.write_wstring((String) value); + _cdrOutput.write_wstring((String)value); break; default: writeObjectState(actualType, value); @@ -316,77 +387,103 @@ _isChunked = saveIsChunked; } - protected void writeMetaString(String ms) { - Integer ref = (Integer) _indirection.get(ms); - if (ref != null) { + protected void writeMetaString(String ms) + { + Integer ref = (Integer)_indirection.get(ms); + if (ref != null) + { _cdrOutput.write_long(ValueType.INDIRECTION_TAG); _cdrOutput.write_long(ref.intValue() - _cdrOutput._offset); - } else { + } + else + { ref = IntegerCache.get(_cdrOutput._offset); _cdrOutput.write_string(ms); putIndirection(ms, ref); } } - protected void writeObjectState(ValueType type, Object value) { - if (type.isExternalizable) { - _cdrOutput.write_octet((byte) 1); + protected void writeObjectState(ValueType type, Object value) + { + if (type.isExternalizable) + { + _cdrOutput.write_octet((byte)1); type.writeExternal(value, this); return; } - if (type.hasParentState) { + if (type.hasParentState) + { writeObjectState(type.parent, value); } - if (type.hasWriteObject && type.hasReadObject) { + if (type.hasWriteObject && type.hasReadObject) + { push(new StreamState(type, value, _cdrOutput._offset)); - if (type.skipCustomFlags) { + if (type.skipCustomFlags) + { _booleanIndex = _cdrOutput._offset; - } else { - _cdrOutput.write_octet((byte) 1); + } + else + { + _cdrOutput.write_octet((byte)1); _cdrOutput.write_boolean(false); _booleanIndex = _cdrOutput._offset - 1; } type.writeObject(value, this); pop(); - } else { + } + else + { writeDeclaredFields(type, value); } } - protected void writeDeclaredFields(ValueType type, Object value) { + protected void writeDeclaredFields(ValueType type, Object value) + { int n = type.fields.length; - for (int f = 0; f < n; f++) { + for (int f = 0; f < n; f++) + { ValueTypeField field = type.fields[f]; int primitive = field.primitive; - if (primitive != 0) { + if (primitive != 0) + { writePrimitive(primitive, field, value); - } else { + } + else + { writeObject(field.type, field.get(value), false); } } } - protected void writeClassDesc(Class theClass) { + protected void writeClassDesc(Class theClass) + { writeObject(ValueType.STRING_VALUE_TYPE, null); // codebase URL writeObject(ValueType.STRING_VALUE_TYPE, ValueType.getInstance(theClass).id); } - protected void writeArray(ValueType arrayType, Object value) { + protected void writeArray(ValueType arrayType, Object value) + { int primitive = arrayType.primitiveArray; - if (primitive != 0) { + if (primitive != 0) + { arrayType.helper.write(this, value); - } else { - Object[] array = (Object[]) value; + } + else + { + Object[] array = (Object[])value; int n = array.length; _cdrOutput.write_ulong(n); - for (int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) + { writeObject(arrayType.element, array[i], false); } } } - protected void writePrimitive(int primitive, ValueTypeField field, Object value) { - switch (primitive) { + protected void writePrimitive(int primitive, ValueTypeField field, Object value) + { + switch (primitive) + { case PrimitiveType.BOOLEAN: _cdrOutput.write_boolean(field.getBoolean(value)); break; @@ -416,8 +513,10 @@ } } - public void startBlock() { - if (!_isChunked) { + public void startBlock() + { + if (! _isChunked) + { return; } _endLevel--; @@ -426,8 +525,10 @@ _blockSizeIndex = _cdrOutput._offset - 4; } - public void endBlock() { - if (!_inBlock) { + public void endBlock() + { + if (! _inBlock) + { return; } _inBlock = false; @@ -438,18 +539,23 @@ _blockSizeIndex = -1; } - protected void writeEndTag() { - if (_isChunked) { - if (_endTagIndex == _cdrOutput._offset - 8) { + protected void writeEndTag() + { + if (_isChunked) + { + if (_endTagIndex == _cdrOutput._offset - 8) + { _cdrOutput._offset -= 8; } _cdrOutput.write_long(_endLevel); _endTagIndex = _cdrOutput._offset - 4; - if (_endLevel != -1) { + if (_endLevel != -1) + { _cdrOutput.write_long(1); - } else // _endLevel == -1 + } + else // _endLevel == -1 { - _cdrOutput._offset -= 4; + _cdrOutput._offset -=4; _cdrOutput.write_long(-1); _isChunked = false; } @@ -490,26 +596,32 @@ } */ - protected void push(StreamState state) { - if (_stack == null) { + protected void push(StreamState state) + { + if (_stack == null) + { _stack = new ArrayList(); } _stack.add(state); } - protected void pop() { + protected void pop() + { int n = _stack.size(); - if (n == 0) { + if (n == 0) + { throw new SystemException("pop: state stack empty"); } _stack.remove(n - 1); } - private StreamState top() { + private StreamState top() + { int n = _stack.size(); - if (n == 0) { + if (n == 0) + { throw new SystemException("top: state stack empty"); } - return (StreamState) _stack.get(n - 1); + return (StreamState)_stack.get(n - 1); } }