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=158813&r2=158814 ============================================================================== --- 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 Wed Mar 23 09:56:34 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=158813&r2=158814 ============================================================================== --- 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 Wed Mar 23 09:56:34 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=158813&r2=158814 ============================================================================== --- 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 Wed Mar 23 09:56:34 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); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRef.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRef.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRef.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRef.java Wed Mar 23 09:56:34 2005 @@ -17,21 +17,23 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import java.util.Hashtable; - -import org.apache.geronimo.interop.IIOP.*; +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.rmi.iiop.client.*; import org.apache.geronimo.interop.IOP.*; -import org.apache.geronimo.interop.SystemException; -import org.apache.geronimo.interop.rmi.iiop.client.ClientNamingContext; -import org.apache.geronimo.interop.rmi.iiop.client.Connection; -import org.apache.geronimo.interop.security.SimpleSubject; -import org.apache.geronimo.interop.util.FutureObject; -import org.apache.geronimo.interop.util.ThreadContext; -import org.apache.geronimo.interop.util.UTF8; -import org.apache.geronimo.interop.util.UnsignedShort; - +import org.apache.geronimo.interop.IIOP.*; +import org.apache.geronimo.interop.security.*; +import org.apache.geronimo.interop.util.*; +import java.util.*; + +public class ObjectRef extends CorbaObject +{ + //public static final Component $component = new Component(ObjectRef.class); + + public static ObjectRef _getInstance() + { + return new ObjectRef(); //(ObjectRef)$component.getInstance(); + } -public class ObjectRef implements org.omg.CORBA.Object { // ----------------------------------------------------------------------- // public data // ----------------------------------------------------------------------- @@ -44,19 +46,32 @@ // private data // ----------------------------------------------------------------------- - private static FutureObject _defaultNamingContext = new FutureObject() { - public Object evaluate() { + private static FutureObject _defaultNamingContext = new FutureObject() + { + public Object evaluate() + { Hashtable env = new Hashtable(); return ClientNamingContext.getInstance(env); } }; - private static Version VERSION_1_1 = new Version((byte) 1, (byte) 1); + private static Version VERSION_1_1 = new Version((byte)1, (byte)1); - private static Version VERSION_1_2 = new Version((byte) 1, (byte) 2); + private static Version VERSION_1_2 = new Version((byte)1, (byte)2); private static TaggedComponent[] NO_PROFILE_COMPONENTS = {}; + /* + private static TaggedProfile AUTOMATIC_FAILOVER_PROFILE; + + static + { + AUTOMATIC_FAILOVER_PROFILE = new TaggedProfile(); + AUTOMATIC_FAILOVER_PROFILE.tag = AutomaticFailover.PROFILE_TAG; + AUTOMATIC_FAILOVER_PROFILE.profile_data = ArrayUtil.EMPTY_BYTE_ARRAY; + } + */ + private int _iiopVersion = IIOP_VERSION_1_2; private org.apache.geronimo.interop.IOP.IOR _ior; @@ -73,6 +88,8 @@ private int _port = -1; + //private boolean _automaticFailover; + public byte[] _objectKey; public byte[] _objectState; @@ -80,50 +97,95 @@ public long _objectVersion; // public methods - - public ObjectRef() { + + public ObjectRef() + { + } + + public Connection $connect() + { + try + { + Connection conn = $getNamingContext().getConnectionPool().get(_protocol, $getEndpoint(), this); + conn.beforeInvoke(); + return conn; + } + catch (RuntimeException ex) + { + //if (_automaticFailover) + //{ + // throw new RetryInvokeException(ex); + //} + //else + //{ + throw ex; + //} + } } - public Connection $connect() { - Connection conn = $getNamingContext().getConnectionPool().get(_protocol, $getEndpoint(), this); - conn.beforeInvoke(); - return conn; + /* + public boolean $getAutomaticFailover() + { + return _automaticFailover; + } + */ + + /* + public void $setAutomaticFailover() + { + _automaticFailover = true; } + */ - public int $getIiopVersion() { + public int $getIiopVersion() + { return _iiopVersion; } - public void $setIiopVersion(int version) { + public void $setIiopVersion(int version) + { _iiopVersion = version; } - public String $getID() { - if (_repositoryID == null) { + public String $getID() + { + if (_repositoryID == null) + { return ""; - } else { + } + else + { return _repositoryID; } } - public void $setID(String id) { + public void $setID(String id) + { _repositoryID = id; } - public org.apache.geronimo.interop.IOP.IOR $getIOR() { - if (_ior == null) { + public org.apache.geronimo.interop.IOP.IOR $getIOR() + { + if (_ior == null) + { ProfileBody_1_1 profileBody = new ProfileBody_1_1(); profileBody.iiop_version = _iiopVersion == IIOP_VERSION_1_1 - ? VERSION_1_1 : VERSION_1_2; - if (_host == null || _host.length() == 0) { + ? VERSION_1_1 : VERSION_1_2; + if (_host == null || _host.length() == 0) + { profileBody.host = ThreadContext.getDefaultRmiHost(); - } else { + } + else + { profileBody.host = _host; } - if (_port == -1) { - profileBody.port = (short) ThreadContext.getDefaultRmiPort(); - } else { - profileBody.port = (short) _port; + if (_port == -1) + { + profileBody.port = (short)ThreadContext.getDefaultRmiPort(); + } + else + { + profileBody.port = (short)_port; } profileBody.object_key = _objectKey; // TODO: if protocol using SSL, set port to 0 and set components @@ -137,129 +199,155 @@ IOR ior = new IOR(); ior.type_id = $getID(); - ior.profiles = new TaggedProfile[]{profile}; + ior.profiles = new TaggedProfile[] { profile }; return ior; } return _ior; } - public void $setIOR(org.apache.geronimo.interop.IOP.IOR ior) { + public void $setIOR(org.apache.geronimo.interop.IOP.IOR ior) + { _ior = ior; _endpoint = null; _objectKey = null; $getObjectKey(); // set _protocol, _host, _port, _objectKey } - public ClientNamingContext $getNamingContext() { - if (_namingContext == null) { - _namingContext = (ClientNamingContext) _defaultNamingContext.getValue(); + public ClientNamingContext $getNamingContext() + { + if (_namingContext == null) + { + _namingContext = (ClientNamingContext)_defaultNamingContext.getValue(); } return _namingContext; } - public void $setNamingContext(ClientNamingContext namingContext) { + public void $setNamingContext(ClientNamingContext namingContext) + { _namingContext = namingContext; } - public int $getProtocol() { - if (_objectKey == null) { + public int $getProtocol() + { + if (_objectKey == null) + { $getObjectKey(); // to set _protocol } return _protocol; } - public void $setProtocol(int protocol) { + public void $setProtocol(int protocol) + { _protocol = protocol; _ior = null; } - public String $getHost() { - if (_objectKey == null) { + public String $getHost() + { + if (_objectKey == null) + { $getObjectKey(); // to set _host } return _host; } - public void $setHost(String host) { + public void $setHost(String host) + { _host = host; _endpoint = null; _ior = null; } - public int $getPort() { - if (_objectKey == null) { + public int $getPort() + { + if (_objectKey == null) + { $getObjectKey(); // to set _port } return _port; } - public void $setPort(int port) { + public void $setPort(int port) + { _port = port; _endpoint = null; _ior = null; } - public String $getEndpoint() { - if (_endpoint == null) { + public String $getEndpoint() + { + if (_endpoint == null) + { _endpoint = _host + ":" + _port; } return _endpoint; } - public byte[] $getObjectKey() { - if (_objectKey == null) { - if (_ior == null) { + public byte[] $getObjectKey() + { + if (_objectKey == null) + { + if (_ior == null) + { throw new IllegalStateException("$getObjectKey: _ior == null && _objectKey = null"); } - TaggedProfile profile = _ior.profiles[0]; - if (profile.tag == TAG_INTERNET_IOP.value - && _ior.profiles.length == 1) { - ProfileBody_1_1 profileBody; - CdrInputStream input = CdrInputStream.getInstanceForEncapsulation(); - input.setEncapsulation(profile.profile_data); - profileBody = ProfileBody_1_1Helper.read(input); - input.recycle(); - - _protocol = Protocol.IIOP; // TODO: IIOP/SSL etc. - _iiopVersion = profileBody.iiop_version.minor; - _host = profileBody.host; - _port = UnsignedShort.intValue(profileBody.port); - _objectKey = profileBody.object_key; - } else { - throw new SystemException("TODO"); + int n = _ior.profiles.length; + for (int i = 0; i < n; i++) + { + TaggedProfile profile = _ior.profiles[i]; + if (profile.tag == TAG_INTERNET_IOP.value) + { + ProfileBody_1_1 profileBody; + CdrInputStream input = CdrInputStream.getInstanceForEncapsulation(); + input.setEncapsulation(profile.profile_data); + profileBody = ProfileBody_1_1Helper.read(input); + input.recycle(); + + _protocol = Protocol.IIOP; // TODO: IIOP/SSL etc. + _iiopVersion = profileBody.iiop_version.minor; + _host = profileBody.host; + _port = UnsignedShort.intValue(profileBody.port); + _objectKey = profileBody.object_key; + } } } return _objectKey; } - public String $getObjectKeyString() { + public String $getObjectKeyString() + { return UTF8.toString($getObjectKey()); } - public void $setObjectKey(byte[] objectKey) { + public void $setObjectKey(byte[] objectKey) + { _objectKey = objectKey; _ior = null; } - public void $setObjectKey(String objectKey) { + public void $setObjectKey(String objectKey) + { $setObjectKey(UTF8.fromString(objectKey)); } - public void $setObjectKey(String prefix, byte[] suffixBytes) { + public void $setObjectKey(String prefix, byte[] suffixBytes) + { byte[] prefixBytes = UTF8.fromString(prefix); int p = prefixBytes.length; int s = suffixBytes.length; byte[] objectKey = new byte[p + 1 + s]; System.arraycopy(prefixBytes, 0, objectKey, 0, p); - objectKey[p] = (byte) ':'; + objectKey[p] = (byte)':'; System.arraycopy(suffixBytes, 0, objectKey, p + 1, s); $setObjectKey(objectKey); } - public void $setObjectKey(Class compClass) { + public void $setObjectKey(Class compClass) + { SimpleSubject subject = SimpleSubject.getCurrent(); if (subject != null - && (subject.getFlags() & SimpleSubject.FLAG_SESSION_MANAGER) != 0) { + && (subject.getFlags() & SimpleSubject.FLAG_SESSION_MANAGER) != 0) + { // Initialize for simple IDL interoperability. ObjectKey objectKey = new ObjectKey(); objectKey.component = compClass.getName(); @@ -269,86 +357,16 @@ key[0] = 'I'; _iiopVersion = IIOP_VERSION_1_1; $setObjectKey(key); - } else { + } + else + { // Initialize for RMI-IIOP. $setObjectKey(compClass.getName()); } } - public String[] _ids() { - String[] ids = - { - "" //_type - } - ; - return ids; - } - - public Object $getRequestKey() { - // - //if (_automaticFailover) - //{ - // return $getNamingContext().getRequestKey(); - //} - //else - //{ + public Object $getRequestKey() + { return null; - //} - } - - public boolean _is_a(String id) { - return false; - } - - // ----------------------------------------------------------------------- - // unimplemented public methods (only required for full CORBA ORB) - // ----------------------------------------------------------------------- - - public org.omg.CORBA.Request _create_request(org.omg.CORBA.Context p1, String p2, org.omg.CORBA.NVList p3, org.omg.CORBA.NamedValue p4) { - throw new org.omg.CORBA.BAD_OPERATION("_create_request"); - } - - public org.omg.CORBA.Request _create_request(org.omg.CORBA.Context p1, String p2, org.omg.CORBA.NVList p3, org.omg.CORBA.NamedValue p4, org.omg.CORBA.ExceptionList p5, org.omg.CORBA.ContextList p6) { - throw new org.omg.CORBA.BAD_OPERATION("_create_request"); - } - - public org.omg.CORBA.Object _duplicate() { - throw new org.omg.CORBA.BAD_OPERATION("_duplicate"); - } - - public org.omg.CORBA.DomainManager[] _get_domain_managers() { - throw new org.omg.CORBA.BAD_OPERATION("_get_domain_manager"); - } - - public org.omg.CORBA.Object _get_interface_def() { - throw new org.omg.CORBA.BAD_OPERATION("_get_interface_def"); - } - - public org.omg.CORBA.Policy _get_policy(int p1) { - throw new org.omg.CORBA.BAD_OPERATION("_get_policy"); - } - - public int _hash(int p1) { - throw new org.omg.CORBA.BAD_OPERATION("_hash"); - } - - public boolean _is_equivalent(org.omg.CORBA.Object p1) { - throw new org.omg.CORBA.BAD_OPERATION("_is_equivalent"); - } - - public boolean _non_existent() { - throw new org.omg.CORBA.BAD_OPERATION("_non_existent"); - } - - public void _release() { - throw new org.omg.CORBA.BAD_OPERATION("_release"); - } - - public org.omg.CORBA.Request _request(String p1) { - throw new org.omg.CORBA.BAD_OPERATION("_request"); - } - - public org.omg.CORBA.Object _set_policy_override(org.omg.CORBA.Policy[] p1, org.omg.CORBA.SetOverrideType p2) { - throw new org.omg.CORBA.BAD_OPERATION("_set_policy_override"); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRefHelper.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRefHelper.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRefHelper.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ObjectRefHelper.java Wed Mar 23 09:56:34 2005 @@ -17,25 +17,39 @@ */ package org.apache.geronimo.interop.rmi.iiop; +import org.apache.geronimo.interop.*; +import org.apache.geronimo.interop.IOP.*; - - -public class ObjectRefHelper implements ObjectHelper { - public static ObjectRefHelper getInstance(Class theClass) { +public class ObjectRefHelper implements ObjectHelper +{ + public static ObjectRefHelper getInstance(Class theClass) + { return new ObjectRefHelper(); } - public Object read(ObjectInputStream input) { + public Object read(ObjectInputStream input) + { return input._cdrInput.read_Object(); } - public void write(ObjectOutputStream output, Object value) { - if (value == null || value instanceof ObjectRef) { - output._cdrOutput.write_Object((org.omg.CORBA.Object) value); - } else if (value instanceof RemoteInterface) { - RemoteInterface remote = (RemoteInterface) value; - output._cdrOutput.write_Object((org.omg.CORBA.Object) remote.$getObjectRef()); - } else { + public void write(ObjectOutputStream output, Object value) + { + if (value == null || value instanceof ObjectRef) + { + output._cdrOutput.write_Object((org.omg.CORBA.Object)value); + } + else if (value instanceof RemoteInterface) + { + RemoteInterface remote = (RemoteInterface)value; + ObjectRef objectRef = remote.getObjectRef(); + //if (value instanceof AutomaticFailover) + //{ + // objectRef.$setAutomaticFailover(); + //} + output._cdrOutput.write_Object(objectRef); + } + else + { throw new IllegalArgumentException("class = " + value.getClass()); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PrimitiveType.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PrimitiveType.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PrimitiveType.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/PrimitiveType.java Wed Mar 23 09:56:34 2005 @@ -17,23 +17,26 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import org.apache.geronimo.interop.util.ArrayUtil; +import org.apache.geronimo.interop.util.*; - -public class PrimitiveType { +public class PrimitiveType +{ public static final int BOOLEAN = 1; - public static final int BYTE = 2; - public static final int CHAR = 3; - public static final int DOUBLE = 4; - public static final int FLOAT = 5; - public static final int INT = 6; - public static final int LONG = 7; - public static final int SHORT = 8; - - public static final ObjectHelper BOOLEAN_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final int BYTE = 2; + public static final int CHAR = 3; + public static final int DOUBLE = 4; + public static final int FLOAT = 5; + public static final int INT = 6; + public static final int LONG = 7; + public static final int SHORT = 8; + + public static final ObjectHelper BOOLEAN_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_BOOLEAN_ARRAY; } boolean[] array = new boolean[n]; @@ -41,19 +44,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - boolean[] array = (boolean[]) value; + public void write(ObjectOutputStream output, Object value) + { + boolean[] array = (boolean[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_boolean_array(array, 0, n); } } - ; + ; - public static final ObjectHelper BYTE_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper BYTE_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_BYTE_ARRAY; } byte[] array = new byte[n]; @@ -61,19 +68,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - byte[] array = (byte[]) value; + public void write(ObjectOutputStream output, Object value) + { + byte[] array = (byte[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_octet_array(array, 0, n); } } - ; + ; - public static final ObjectHelper CHAR_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper CHAR_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_CHAR_ARRAY; } char[] array = new char[n]; @@ -81,19 +92,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - char[] array = (char[]) value; + public void write(ObjectOutputStream output, Object value) + { + char[] array = (char[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_char_array(array, 0, n); } } - ; + ; - public static final ObjectHelper DOUBLE_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper DOUBLE_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_DOUBLE_ARRAY; } double[] array = new double[n]; @@ -101,19 +116,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - double[] array = (double[]) value; + public void write(ObjectOutputStream output, Object value) + { + double[] array = (double[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_double_array(array, 0, n); } } - ; + ; - public static final ObjectHelper FLOAT_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper FLOAT_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_FLOAT_ARRAY; } float[] array = new float[n]; @@ -121,19 +140,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - float[] array = (float[]) value; + public void write(ObjectOutputStream output, Object value) + { + float[] array = (float[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_float_array(array, 0, n); } } - ; + ; - public static final ObjectHelper INT_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper INT_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_INT_ARRAY; } int[] array = new int[n]; @@ -141,19 +164,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - int[] array = (int[]) value; + public void write(ObjectOutputStream output, Object value) + { + int[] array = (int[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_long_array(array, 0, n); } } - ; + ; - public static final ObjectHelper LONG_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper LONG_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_LONG_ARRAY; } long[] array = new long[n]; @@ -161,19 +188,23 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - long[] array = (long[]) value; + public void write(ObjectOutputStream output, Object value) + { + long[] array = (long[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_longlong_array(array, 0, n); } } - ; + ; - public static final ObjectHelper SHORT_ARRAY_HELPER = new ObjectHelper() { - public Object read(ObjectInputStream input) { + public static final ObjectHelper SHORT_ARRAY_HELPER = new ObjectHelper() + { + public Object read(ObjectInputStream input) + { int n = input._cdrInput.read_long(); - if (n == 0) { + if (n == 0) + { return ArrayUtil.EMPTY_SHORT_ARRAY; } short[] array = new short[n]; @@ -181,61 +212,100 @@ return array; } - public void write(ObjectOutputStream output, Object value) { - short[] array = (short[]) value; + public void write(ObjectOutputStream output, Object value) + { + short[] array = (short[])value; int n = array.length; output._cdrOutput.write_long(n); output._cdrOutput.write_short_array(array, 0, n); } } - ; + ; - public static int get(Class _class) { - if (_class == boolean.class) { + public static int get(Class _class) + { + if (_class == boolean.class) + { return BOOLEAN; - } else if (_class == byte.class) { + } + else if (_class == byte.class) + { return BYTE; - } else if (_class == char.class) { + } + else if (_class == char.class) + { return CHAR; - } else if (_class == double.class) { + } + else if (_class == double.class) + { return DOUBLE; - } else if (_class == float.class) { + } + else if (_class == float.class) + { return FLOAT; - } else if (_class == int.class) { + } + else if (_class == int.class) + { return INT; - } else if (_class == long.class) { + } + else if (_class == long.class) + { return LONG; - } else if (_class == short.class) { + } + else if (_class == short.class) + { return SHORT; - } else { - throw new IllegalArgumentException("class = " + _class.getName()); + } + else + { + throw new IllegalArgumentException("class = " +_class.getName()); } } - public static ObjectHelper getArrayHelper(Class _class) { - if (_class == boolean.class) { + public static ObjectHelper getArrayHelper(Class _class) + { + if (_class == boolean.class) + { return BOOLEAN_ARRAY_HELPER; - } else if (_class == byte.class) { + } + else if (_class == byte.class) + { return BYTE_ARRAY_HELPER; - } else if (_class == char.class) { + } + else if (_class == char.class) + { return CHAR_ARRAY_HELPER; - } else if (_class == double.class) { + } + else if (_class == double.class) + { return DOUBLE_ARRAY_HELPER; - } else if (_class == float.class) { + } + else if (_class == float.class) + { return FLOAT_ARRAY_HELPER; - } else if (_class == int.class) { + } + else if (_class == int.class) + { return INT_ARRAY_HELPER; - } else if (_class == long.class) { + } + else if (_class == long.class) + { return LONG_ARRAY_HELPER; - } else if (_class == short.class) { + } + else if (_class == short.class) + { return SHORT_ARRAY_HELPER; - } else { - throw new IllegalArgumentException("class = " + _class.getName()); + } + else + { + throw new IllegalArgumentException("class = " +_class.getName()); } } - public static org.omg.CORBA.TypeCode getTypeCode(int p) { - switch (p) { + public static org.omg.CORBA.TypeCode getTypeCode(int p) + { + switch (p) + { case BOOLEAN: return TypeCode.BOOLEAN; case BYTE: // java byte is IDL octet Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/Protocol.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/Protocol.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/Protocol.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/Protocol.java Wed Mar 23 09:56:34 2005 @@ -17,52 +17,57 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public abstract class Protocol { - public static final int IIOP = 1; +public abstract class Protocol +{ + public static final int IIOP = 1; public static final int IIOPS = 2; - public static final int HTTP = 3; + public static final int HTTP = 3; public static final int HTTPS = 4; - public static String getName(int protocol) { - switch (protocol) { - case IIOP: - return "iiop"; - case IIOPS: - return "iiop"; - case HTTP: - return "http"; - case HTTPS: - return "https"; - default: - throw new IllegalArgumentException("protocol = " + protocol); + public static String getName(int protocol) + { + switch (protocol) + { + case IIOP: return "iiop"; + case IIOPS: return "iiop"; + case HTTP: return "http"; + case HTTPS: return "https"; + default: throw new IllegalArgumentException("protocol = " + protocol); } } - public static String getScheme(int protocol) { - switch (protocol) { - case IIOP: - return "iiop:"; - case IIOPS: - return "iiop:"; - case HTTP: - return "http:"; - case HTTPS: - return "https:"; - default: - throw new IllegalArgumentException("protocol = " + protocol); + public static String getScheme(int protocol) + { + switch (protocol) + { + case IIOP: return "iiop:"; + case IIOPS: return "iiop:"; + case HTTP: return "http:"; + case HTTPS: return "https:"; + default: throw new IllegalArgumentException("protocol = " + protocol); } } - public static int getNumber(String protocol) { - if (protocol.equals("iiop")) { + public static int getNumber(String protocol) + { + if (protocol.equals("iiop")) + { return IIOP; - } else if (protocol.equals("iiops")) { + } + else if (protocol.equals("iiops")) + { return IIOPS; - } else if (protocol.equals("http")) { + } + else if (protocol.equals("http")) + { return HTTP; - } else if (protocol.equals("https")) { + } + else if (protocol.equals("https")) + { return HTTPS; - } else { + } + else + { throw new IllegalArgumentException("protocol = " + protocol); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteInterface.java Wed Mar 23 09:56:34 2005 @@ -17,10 +17,11 @@ */ package org.apache.geronimo.interop.rmi.iiop; -public interface RemoteInterface { - public ObjectRef $getObjectRef(); - - public RemoteInterface $getSkeleton(); +import org.apache.geronimo.interop.adapter.Adapter; - public void $invoke(String method, byte[] objectKey, Object instance, ObjectInputStream input, ObjectOutputStream output); +public interface RemoteInterface { + public ObjectRef getObjectRef(); +// public RemoteInterface $getSkeleton(); + public void invoke(String method, byte[] objectKey, Adapter adapter, ObjectInputStream input, ObjectOutputStream output); +// public void $invoke(String method, byte[] objectKey, ObjectInputStream input, ObjectOutputStream output); } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteObject.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteObject.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteObject.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/RemoteObject.java Wed Mar 23 09:56:34 2005 @@ -17,14 +17,32 @@ */ package org.apache.geronimo.interop.rmi.iiop; +import org.apache.geronimo.interop.adapter.Adapter; + +import java.util.HashMap; + public abstract class RemoteObject { - public RemoteObject() { + + protected HashMap methods = new HashMap(10); + + public RemoteObject( ) { + registerMethods(); } protected void registerMethods() { registerMethod("_is_a", -1); } + protected void registerMethod( String methodName, int id ) + { + methods.put( methodName, new Integer(id) ); + } + + protected Integer getMethodId( String methodName ) + { + return (Integer)methods.get( methodName ); + } + public void invoke(int id, byte[] objectKey, Object instance, ObjectInputStream input, ObjectOutputStream output) { switch (id) { case -1: @@ -53,6 +71,4 @@ } public abstract String[] getIds(); - - public abstract void registerMethod(String name, int id); } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SecurityInfo.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SecurityInfo.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SecurityInfo.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/SecurityInfo.java Wed Mar 23 09:56:34 2005 @@ -36,26 +36,20 @@ (byte) 'P', (byte) 'A', (byte) 'S', (byte) 'S' }); - public static Random _seedFactory = new Random(); + public static Random seedFactory = new Random(); + public String username; + public String password; - public String username; - - public String password; - - // private data - - private static ThreadLocal _current = new ThreadLocal(); + private static ThreadLocal current = new ThreadLocal(); public static SecurityInfo getCurrent() { - return (SecurityInfo) _current.get(); + return (SecurityInfo) current.get(); } public static void setCurrent(SecurityInfo info) { - _current.set(info); + current.set(info); } - // TODO: delegate to use DataProtection class - /** * * Encode a username or password to prevent accidental disclosure * * by packet sniffers etc. The intention is not to provide strong @@ -66,7 +60,7 @@ * * similar requirements in Random.java. */ public static byte[] encode(String plainText) { - int seed = _seedFactory.nextInt(); // data race, but we don't care + int seed = seedFactory.nextInt(); // data race, but we don't care Random random = new Random(seed); byte[] utf8 = UTF8.fromString(plainText); int n = utf8.length;