Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java Fri Mar 25 03:54:30 2005
@@ -17,60 +17,50 @@
*/
package org.apache.geronimo.interop.rmi.iiop;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamClass;
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.security.DigestOutputStream;
-import java.security.MessageDigest;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
+import org.apache.geronimo.interop.*;
+import org.apache.geronimo.interop.rmi.*;
+import org.apache.geronimo.interop.util.*;
+import java.io.*;
+import java.lang.reflect.*;
+import java.security.*;
+import java.util.*;
import org.omg.CORBA.TCKind;
-import org.apache.geronimo.interop.SystemException;
-import org.apache.geronimo.interop.util.ArrayUtil;
-import org.apache.geronimo.interop.util.ExceptionUtil;
-import org.apache.geronimo.interop.util.JavaClass;
-import org.apache.geronimo.interop.util.JavaType;
-import org.apache.geronimo.interop.util.SystemUtil;
-
-
-/**
- * * A wrapper over java.lang.Class to help improve performance of using
- * * the Java reflection API for valuetype marshalling. We keep as much
- * * derived information as possible for optimal performance.
- */
-public class ValueType {
- public static ValueType getInstance(Class forClass) {
- ValueType vt = (ValueType) _valueTypeMap.get(forClass);
- if (vt == null) {
- synchronized (_valueTypeMap) {
- vt = (ValueType) _valueTypeMap.get(forClass);
- if (vt == null) {
+public class ValueType
+{
+ //public static final Component component = new Component(ValueType.class);
+
+ public static ValueType getInstance(Class forClass)
+ {
+ ValueType vt = (ValueType)_valueTypeMap.get(forClass);
+ if (vt == null)
+ {
+ synchronized (_valueTypeMap)
+ {
+ vt = (ValueType)_valueTypeMap.get(forClass);
+ if (vt == null)
+ {
+ //vt = (ValueType)component.getInstance();
vt = new ValueType();
- vt.init(forClass);
_valueTypeMap.put(forClass, vt);
+ vt.init(forClass);
}
}
}
return vt;
}
- public static ValueType getInstanceByID(String id) {
+ public static ValueType getInstanceByID(String id)
+ {
// TODO: handle multiple class loaders???
- ValueType vt = (ValueType) _idTypeMap.get(id);
- if (vt == null) {
- synchronized (_idTypeMap) {
- vt = (ValueType) _idTypeMap.get(id);
- if (vt == null) {
+ ValueType vt = (ValueType)_idTypeMap.get(id);
+ if (vt == null)
+ {
+ synchronized (_idTypeMap)
+ {
+ vt = (ValueType)_idTypeMap.get(id);
+ if (vt == null)
+ {
Class theClass = getClass(id);
vt = getInstance(theClass);
_idTypeMap.put(id, vt);
@@ -119,13 +109,13 @@
// package-private data
// -----------------------------------------------------------------------
- static final int NULL_VALUE_TAG = 0;
- static final int NO_TYPE_VALUE_TAG = 0x7fffff00;
- static final int SINGLE_TYPE_VALUE_TAG = 0x7fffff02;
- static final int TRUNCATABLE_NO_TYPE_VALUE_TAG = 0x7fffff08;
+ static final int NULL_VALUE_TAG = 0;
+ static final int NO_TYPE_VALUE_TAG = 0x7fffff00;
+ static final int SINGLE_TYPE_VALUE_TAG = 0x7fffff02;
+ static final int TRUNCATABLE_NO_TYPE_VALUE_TAG = 0x7fffff08;
static final int TRUNCATABLE_SINGLE_TYPE_VALUE_TAG = 0x7fffff0a;
- static final int TYPE_LIST_VALUE_TAG = 0x7fffff06;
- static final int INDIRECTION_TAG = 0xffffffff;
+ static final int TYPE_LIST_VALUE_TAG = 0x7fffff06;
+ static final int INDIRECTION_TAG = 0xffffffff;
static final int CASE_ARRAY = 1;
static final int CASE_CLASS = 2;
@@ -178,20 +168,27 @@
// static initializer
// -----------------------------------------------------------------------
- static {
+ static
+ {
TC_ABSTRACT_BASE = new TypeCode(TCKind.tk_abstract_interface);
TC_ABSTRACT_BASE.id("IDL:omg.org/CORBA/AbstractBase:1.0");
TC_ABSTRACT_BASE.name("");
- try {
- if (JDK14) {
- _newInstance = java.io.ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[]{});
+ try
+ {
+ if (JDK14)
+ {
+ _newInstance = java.io.ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[] {});
_newInstance.setAccessible(true);
- } else {
- _allocateNewObject = java.io.ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[]{Class.class, Class.class});
+ }
+ else
+ {
+ _allocateNewObject = java.io.ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[] { Class.class, Class.class });
_allocateNewObject.setAccessible(true);
}
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
@@ -200,70 +197,105 @@
// public methods
// -----------------------------------------------------------------------
- public Object newInstance() {
- try {
- if (JDK14) {
- if (_class == Object.class) {
+ public Object newInstance()
+ {
+ try
+ {
+ if (JDK14)
+ {
+ if (_class == Object.class)
+ {
return new Object();
- } else {
+ }
+ else
+ {
return _newInstance.invoke(_objectStreamClass, ArrayUtil.EMPTY_OBJECT_ARRAY);
}
- } else {
+ }
+ else
+ {
return _allocateNewObject.invoke(null, _allocateNewObjectArgs);
}
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
- public String toString() {
+ public String toString()
+ {
return "ValueType:" + JavaType.getName(_class);
}
- public void readObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) {
- try {
+ public void readObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input)
+ {
+ try
+ {
_readObject.invoke(_this, input.thisAsObjectArray);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
- public void writeObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) {
- try {
+ public void writeObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output)
+ {
+ try
+ {
_writeObject.invoke(_this, output.thisAsObjectArray);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
- public Object readResolve(Object _this) {
- try {
+ public Object readResolve(Object _this)
+ {
+ try
+ {
return _readResolve.invoke(_this, ArrayUtil.EMPTY_OBJECT_ARRAY);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
- public Object writeReplace(Object _this) {
- try {
+ public Object writeReplace(Object _this)
+ {
+ try
+ {
return _writeReplace.invoke(_this, ArrayUtil.EMPTY_OBJECT_ARRAY);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
- public void readExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) {
- try {
+ public void readExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input)
+ {
+ try
+ {
_readExternal.invoke(_this, input.thisAsObjectArray);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
- public void writeExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) {
- try {
+ public void writeExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output)
+ {
+ try
+ {
_writeExternal.invoke(_this, output.thisAsObjectArray);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
}
}
@@ -272,50 +304,67 @@
// protected methods
// -----------------------------------------------------------------------
- protected void init(Class theClass) {
+ protected void init(Class theClass)
+ {
boolean recursive = false;
- if (_initMap.get(theClass) != null) {
+ if (_initMap.get(theClass) != null)
+ {
// recursive = true;
return; // Already initializing (recursive 'init' call).
}
_initMap.put(theClass, Boolean.TRUE);
- try {
+ try
+ {
_class = theClass;
_objectStreamClass = ObjectStreamClass.lookup(_class);
if (org.omg.CORBA.Object.class.isAssignableFrom(theClass)
|| javax.ejb.EJBHome.class.isAssignableFrom(theClass)
|| javax.ejb.EJBObject.class.isAssignableFrom(theClass)
- || java.rmi.Remote.class.isAssignableFrom(theClass)) {
+ || java.rmi.Remote.class.isAssignableFrom(theClass))
+ {
helper = ObjectRefHelper.getInstance(theClass);
isObjectRef = true;
readWriteCase = CASE_IDL_OBJECT;
- } else if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(theClass)) {
+ }
+ else if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(theClass))
+ {
helper = IDLEntityHelper.getInstance(theClass);
isIDLEntity = true;
readWriteCase = CASE_IDL_ENTITY;
- } else if (theClass == String.class) {
+ }
+ else if (theClass == String.class)
+ {
helper = StringHelper.SINGLETON;
readWriteCase = CASE_STRING;
- } else if (theClass.isArray()) {
+ }
+ else if (theClass.isArray())
+ {
Class elementClass = theClass.getComponentType();
element = getInstance(elementClass);
isArray = true;
- if (elementClass.isPrimitive()) {
+ if (elementClass.isPrimitive())
+ {
primitiveArray = PrimitiveType.get(elementClass);
helper = PrimitiveType.getArrayHelper(elementClass);
- } else {
+ }
+ else
+ {
helper = new ArrayHelper(elementClass);
}
readWriteCase = CASE_ARRAY;
- } else if (theClass == Class.class) {
+ }
+ else if (theClass == Class.class)
+ {
readWriteCase = CASE_CLASS;
}
- if (_allocateNewObject != null) {
+ if (_allocateNewObject != null)
+ {
Class bc = _class;
- while (Serializable.class.isAssignableFrom(bc) && (bc.getSuperclass() != null)) {
+ while (Serializable.class.isAssignableFrom(bc) && (bc.getSuperclass() != null))
+ {
bc = bc.getSuperclass();
}
- _allocateNewObjectArgs = new Object[]{_class, bc};
+ _allocateNewObjectArgs = new Object[] { _class, bc };
}
isAny = _class == java.lang.Object.class
@@ -323,13 +372,15 @@
|| _class == java.io.Serializable.class;
isExternalizable = java.io.Externalizable.class.isAssignableFrom(_class);
- if (isExternalizable) {
- _readExternal = _class.getDeclaredMethod("readExternal", new Class[]{ObjectInput.class});
- _writeExternal = _class.getDeclaredMethod("writeExternal", new Class[]{ObjectOutput.class});
+ if (isExternalizable)
+ {
+ _readExternal = _class.getDeclaredMethod("readExternal", new Class[] { ObjectInput.class } );
+ _writeExternal = _class.getDeclaredMethod("writeExternal", new Class[] { ObjectOutput.class } );
}
// SG: Hopefully we got all the info that is needed
- if (recursive) {
+ if(recursive)
+ {
return;
}
@@ -337,75 +388,89 @@
java.lang.Class tmpClass = _class;
ArrayList fieldList = new ArrayList();
Field[] javaFields = tmpClass.getDeclaredFields();
-
+
// TODO: suppress sort for IDL-generated valuetypes
Arrays.sort(javaFields, FieldComparator.SINGLETON);
-
+
// Create vector of non-static, non-transient fields.
// Ensure that all fields are readable/writable using reflection.
int nf = javaFields.length;
- for (int f = 0; f < nf; f++) {
+ for (int f = 0; f < nf; f++)
+ {
Field javaField = javaFields[f];
int modifiers = javaField.getModifiers();
- if ((modifiers & (Modifier.STATIC | Modifier.TRANSIENT)) != 0) {
+ if ((modifiers & (Modifier.STATIC | Modifier.TRANSIENT)) != 0)
+ {
continue;
}
- if (!javaField.isAccessible()) {
+ if (! javaField.isAccessible())
+ {
javaField.setAccessible(true);
}
ValueTypeField field = new ValueTypeField(javaField);
fieldList.add(field);
}
- fields = (ValueTypeField[]) fieldList.toArray(new ValueTypeField[fieldList.size()]);
+ fields = (ValueTypeField[])fieldList.toArray(new ValueTypeField[fieldList.size()]);
// Check methods for readObject/writeObject. Also check for
// abstract interfaces.
Method[] methods = _class.getDeclaredMethods();
int countThrowsRemoteException = 0;
int nm = methods.length;
- for (int m = 0; m < nm; m++) {
+ for (int m = 0; m < nm; m++)
+ {
Method method = methods[m];
Class[] types = method.getParameterTypes();
if (types.length == 1
&& types[0] == java.io.ObjectInputStream.class
&& (method.getModifiers() & Modifier.PRIVATE) != 0
- && method.getName().equals("readObject")) {
+ && method.getName().equals("readObject"))
+ {
_readObject = method;
- if (!_readObject.isAccessible()) {
+ if (! _readObject.isAccessible())
+ {
_readObject.setAccessible(true);
}
}
if (types.length == 1
&& types[0] == java.io.ObjectOutputStream.class
&& (method.getModifiers() & Modifier.PRIVATE) != 0
- && method.getName().equals("writeObject")) {
+ && method.getName().equals("writeObject"))
+ {
_writeObject = method;
- if (!_writeObject.isAccessible()) {
+ if (! _writeObject.isAccessible())
+ {
_writeObject.setAccessible(true);
}
}
if (types.length == 0
&& method.getReturnType() == java.lang.Object.class
- && method.getName().equals("writeReplace")) {
+ && method.getName().equals("writeReplace"))
+ {
_writeReplace = method;
- if (!_writeReplace.isAccessible()) {
+ if (! _writeReplace.isAccessible())
+ {
_writeReplace.setAccessible(true);
}
}
if (types.length == 0
- && method.getReturnType() == java.lang.Object.class
- && method.getName().equals("readResolve")) {
+ && method.getReturnType() == java.lang.Object.class
+ && method.getName().equals("readResolve"))
+ {
_readResolve = method;
- if (!_readResolve.isAccessible()) {
+ if (! _readResolve.isAccessible())
+ {
_readResolve.setAccessible(true);
}
}
Class[] exceptions = method.getExceptionTypes();
- for (int i = 0; i < exceptions.length; i++) {
+ for (int i = 0; i < exceptions.length; i++)
+ {
Class exception = exceptions[i];
- if (exception.isAssignableFrom(java.rmi.RemoteException.class)) {
+ if (exception.isAssignableFrom(java.rmi.RemoteException.class))
+ {
// TODO: check Java to IDL wording for this
countThrowsRemoteException++;
break;
@@ -419,20 +484,21 @@
hasWriteReplace = _writeReplace != null;
hasReadResolve = _readResolve != null;
- isAbstractInterface = !isObjectRef
- && _class.isInterface()
- && countThrowsRemoteException == methods.length;
+ isAbstractInterface = ! isObjectRef
+ && _class.isInterface()
+ && countThrowsRemoteException == methods.length;
Class superclass = _class.getSuperclass();
- if ((superclass != null) && (superclass != java.lang.Object.class) && (!isIDLEntity)) {
+ if((superclass != null) && (superclass != java.lang.Object.class) && (!isIDLEntity ))
+ {
parent = getInstance(superclass);
}
hasParentState = parent != null
- && (parent.fields.length > 0
- || parent.isExternalizable
- || parent.hasReadOrWriteObject
- || parent.hasParentState);
+ && (parent.fields.length > 0
+ || parent.isExternalizable
+ || parent.hasReadOrWriteObject
+ || parent.hasParentState);
requiresCustomSerialization = hasWriteObject || isExternalizable;
@@ -440,44 +506,57 @@
initTypeCode();
isAnyOrObjectRefOrAbstractInterface = isAny || isObjectRef || isAbstractInterface;
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw ExceptionUtil.getRuntimeException(ex);
- } finally {
- if (!recursive) {
- _initMap.remove(theClass);
- }
+ }
+ finally
+ {
+ if(!recursive)
+ {
+ _initMap.remove(theClass);
}
}
+ }
- protected void initRepositoryID() {
+ protected void initRepositoryID()
+ {
final String sixteenZeros = "0000000000000000";
final int requiredLength = 16;
- if (isAny) {
+ if (isAny)
+ {
id = "#ANY-TODO#";
return;
}
- if (isArray && primitiveArray != 0) {
+ if (isArray && primitiveArray != 0)
+ {
id = "#ARRAY-TODO#";
return;
}
- if (_class == String.class) {
+ if (_class == String.class)
+ {
id = "IDL:omg.org/CORBA/WStringValue:1.0";
return;
}
- if (isObjectRef) {
+ if (isObjectRef)
+ {
id = "RMI:" + _class.getName() + ":" + sixteenZeros;
return;
}
- if (_class == java.lang.Class.class) {
+ if (_class == java.lang.Class.class)
+ {
id = "RMI:javax.rmi.CORBA.ClassDesc:2BABDA04587ADCCC:CFBF02CF5294176B";
return;
}
- if (_class == java.math.BigInteger.class) {
+ if (_class == java.math.BigInteger.class)
+ {
id = "RMI:java.math.BigInteger:8CAD1A3C6C0A9DF0:8CFC9F1FA93BFB1D";
skipCustomFlags = true; // TODO: move this and check usage
return;
}
- if (_objectStreamClass == null) {
+ if (_objectStreamClass == null)
+ {
id = "???";
return;
}
@@ -488,56 +567,80 @@
int currentLength;
int lengthNeeded;
currentLength = structuralUIDString.length();
- if (currentLength < requiredLength) {
+ if (currentLength < requiredLength)
+ {
lengthNeeded = requiredLength - currentLength;
structuralUIDString = sixteenZeros.substring(0, lengthNeeded) + structuralUIDString;
}
currentLength = serialVersionUIDString.length();
- if (currentLength < requiredLength) {
+ if (currentLength < requiredLength)
+ {
lengthNeeded = requiredLength - currentLength;
serialVersionUIDString = sixteenZeros.substring(0, lengthNeeded) + serialVersionUIDString;
}
id = "RMI:" + _class.getName() + ":" + structuralUIDString + ":" + serialVersionUIDString;
}
- protected void initTypeCode() {
- if (isObjectRef) {
+ protected void initTypeCode()
+ {
+ if (isObjectRef)
+ {
tc = new TypeCode(TCKind.tk_objref);
tc.id(id);
tc.name("");
- } else if (isArray || isIDLEntity || _class == String.class) {
+ }
+ else if (isArray || isIDLEntity || _class == String.class)
+ {
tc = new TypeCode(TCKind.tk_value_box);
tc.id(id);
tc.name("");
- if (_class == String.class) {
+ if (_class == String.class)
+ {
tc.content_type(new TypeCode(TCKind.tk_wstring));
- } else if (isArray) {
+ }
+ else if (isArray)
+ {
TypeCode seqTC = new TypeCode(TCKind.tk_sequence);
- if (primitiveArray != 0) {
+ if (primitiveArray != 0)
+ {
seqTC.content_type(PrimitiveType.getTypeCode(primitiveArray));
- } else {
+ }
+ else
+ {
seqTC.content_type(element.tc);
}
tc.content_type(seqTC);
- } else if (isIDLEntity) {
+ }
+ else if (isIDLEntity)
+ {
// TODO tc.content_type(helper.type());
}
- } else {
+ }
+ else
+ {
tc = new TypeCode(TCKind.tk_value);
tc.id(id);
tc.name("");
// TODO: value modifier
- if (requiresCustomSerialization) {
- tc.type_modifier((short) 1);
- } else if (isAbstractInterface) {
- tc.type_modifier((short) 2);
- } else {
- tc.type_modifier((short) 0);
+ if (requiresCustomSerialization)
+ {
+ tc.type_modifier((short)1);
+ }
+ else if (isAbstractInterface)
+ {
+ tc.type_modifier((short)2);
+ }
+ else
+ {
+ tc.type_modifier((short)0);
}
- if (parent == null) {
+ if (parent == null)
+ {
tc.concrete_base_type(TC_NULL);
- } else {
+ }
+ else
+ {
// TODO: check validity of this
tc.concrete_base_type(TC_NULL);
// tc.concrete_base_type(getTypeCode(parent));
@@ -547,128 +650,119 @@
}
}
- static long computeStructuralUID(ValueType vt) {
+ static long computeStructuralUID(ValueType vt)
+ {
Class c = vt._class;
ObjectStreamClass osc = vt._objectStreamClass;
ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);
long h = 0;
- try {
- if (!java.io.Serializable.class.isAssignableFrom(c)
- || c.isInterface()) {
+ try
+ {
+ if (! java.io.Serializable.class.isAssignableFrom(c)
+ || c.isInterface())
+ {
return 0;
}
- if (java.io.Externalizable.class.isAssignableFrom(c)) {
+ if (java.io.Externalizable.class.isAssignableFrom(c))
+ {
return 1;
}
MessageDigest md = MessageDigest.getInstance("SHA");
DigestOutputStream mdo = new DigestOutputStream(devnull, md);
DataOutputStream data = new DataOutputStream(mdo);
- if (vt.parent != null) {
+ if (vt.parent != null)
+ {
data.writeLong(computeStructuralUID(vt.parent));
}
- if (vt.hasWriteObject) {
+ if (vt.hasWriteObject)
+ {
data.writeInt(2);
- } else {
+ }
+ else
+ {
data.writeInt(1);
}
List fieldList = new ArrayList(vt.fields.length);
- for (int i = 0; i < vt.fields.length; i++) {
+ for (int i = 0; i < vt.fields.length; i++)
+ {
fieldList.add(vt.fields[i].javaField);
}
- Field[] fields = (Field[]) fieldList.toArray(new Field[fieldList.size()]);
+ Field[] fields = (Field[])fieldList.toArray(new Field[fieldList.size()]);
Arrays.sort(fields, FieldByNameComparator.SINGLETON);
- for (int i = 0; i < vt.fields.length; i++) {
+ for (int i = 0; i < vt.fields.length; i++)
+ {
Field f = fields[i];
data.writeUTF(f.getName());
data.writeUTF(JavaClass.getSignature(f.getType()));
}
data.flush();
byte[] hasharray = md.digest();
- for (int i = 0; i < Math.min(8, hasharray.length); i++) {
- h += (long) (hasharray[i] & 255) << (i * 8);
+ for (int i = 0; i < Math.min(8, hasharray.length); i++)
+ {
+ h += (long)(hasharray[i] & 255) << (i * 8);
}
return h;
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
/**
- * * Map an RMI/IDL Repository ID to a java.lang.Class.
- */
- static Class getClass(String id) {
- if (id.startsWith("RMI:")) {
+ ** Map an RMI/IDL Repository ID to a java.lang.Class.
+ **/
+ static Class getClass(String id)
+ {
+ if (id.startsWith("RMI:"))
+ {
int endClass = id.indexOf(':', 4);
- if (endClass == -1) {
+ if (endClass == -1)
+ {
throw new org.omg.CORBA.INV_IDENT(id);
}
String className = id.substring(4, endClass);
- if (className.equals("javax.rmi.CORBA.ClassDesc")) {
+ if (className.equals("javax.rmi.CORBA.ClassDesc"))
+ {
return Class.class;
- } else {
+ }
+ else
+ {
return loadClass(className);
}
- } else if (id.equals("IDL:omg.org/CORBA/WStringValue:1.0")) {
+ }
+ else if (id.equals("IDL:omg.org/CORBA/WStringValue:1.0"))
+ {
return java.lang.String.class;
- } else if (id.startsWith("IDL:omg.org/")) {
+ }
+ else if (id.startsWith("IDL:omg.org/"))
+ {
int endClass = id.indexOf(':', 12);
- if (endClass == -1) {
+ if (endClass == -1)
+ {
throw new org.omg.CORBA.INV_IDENT(id);
}
- String className = "org.omg" + id.substring("IDL:omg.org".length(), endClass).replace('/', '.');
+ String className = "org.omg" + id.substring( "IDL:omg.org".length(), endClass).replace('/', '.');
return loadClass(className);
- } else if (id.startsWith("IDL:")) {
+ }
+ else if (id.startsWith("IDL:"))
+ {
int endClass = id.indexOf(':', 4);
- if (endClass == -1) {
+ if (endClass == -1)
+ {
throw new org.omg.CORBA.INV_IDENT(id);
}
String className = id.substring(4, endClass).replace('/', '.');
return loadClass(className);
- } else {
- throw new org.omg.CORBA.INV_IDENT(id);
}
- }
-
- static Class loadClass(String className) {
- Class c = null;
-
- System.out.println("loadClass(): " + className);
-
- try {
- //c = Class.forName( className );
- c = ClassLoader.getSystemClassLoader().loadClass(className);
- } catch (Exception e) {
- e.printStackTrace();
+ else
+ {
+ throw new org.omg.CORBA.INV_IDENT(id);
}
-
- //return ThreadContext.loadClass(className);
- return c;
}
- public static void main(String args[])
- throws Exception {
- Class c = Class.forName(args[0]);
- ValueType vt = ValueType.getInstance(c);
- System.out.println("vt = " + vt.toString());
- System.out.println("vt.id = " + vt.id);
- System.out.println("vt.tc = " + vt.tc.id());
-
- c = Class.forName("org.omg.CosNaming.NameComponent");
- vt = ValueType.getInstance(c);
- System.out.println("vt = " + vt.toString());
- System.out.println("vt.id = " + vt.id);
- System.out.println("vt.tc = " + vt.tc.id());
-
- c = ValueType.getClass("RMI:mark.comps.Add:0000000000000000");
- System.out.println("c.getName() = " + c.getName());
-
- c = ValueType.getClass("RMI:org.omg.CosNaming.NameComponent:7FD3FB2290230F5E:F164A2194A66282A");
- System.out.println("c.getName() = " + c.getName());
-
- c = ValueType.getClass("IDL:omg.org/CosNaming/NameComponent:1.0");
- System.out.println("c.getName() = " + c.getName());
-
- c = ValueType.getClass("RMI:mark.AddData:4165959D0B2418DD:747FE23938318E95");
- System.out.println("c.getName() = " + c.getName());
+ static Class loadClass(String className)
+ {
+ return ThreadContext.loadClass(className);
}
}
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java Fri Mar 25 03:54:30 2005
@@ -17,169 +17,320 @@
*/
package org.apache.geronimo.interop.rmi.iiop;
-import java.lang.reflect.Field;
+import org.apache.geronimo.interop.*;
+import java.lang.reflect.*;
-import org.apache.geronimo.interop.SystemException;
-
-
-public class ValueTypeField {
+public class ValueTypeField
+{
public final Field javaField;
public final int primitive;
public final ValueType type;
- public ValueTypeField(Field field) {
+ private final boolean isFinal;
+
+ private FinalFieldSetter finalFieldSetter;
+
+ public ValueTypeField(Field field)
+ {
javaField = field;
- if (field.getType().isPrimitive()) {
+ if (field.getType().isPrimitive())
+ {
primitive = PrimitiveType.get(field.getType());
type = null;
- } else {
+ }
+ else
+ {
primitive = 0;
type = ValueType.getInstance(field.getType());
}
+ if(Modifier.isFinal(field.getModifiers()))
+ {
+ isFinal = true;
+ finalFieldSetter = FinalFieldSetter.getInstance(field);
+ }
+ else
+ {
+ isFinal = false;
+ }
}
- public boolean getBoolean(Object that) {
- try {
+ public boolean getBoolean(Object that)
+ {
+ try
+ {
return javaField.getBoolean(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public byte getByte(Object that) {
- try {
+ public byte getByte(Object that)
+ {
+ try
+ {
return javaField.getByte(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public char getChar(Object that) {
- try {
+ public char getChar(Object that)
+ {
+ try
+ {
return javaField.getChar(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public double getDouble(Object that) {
- try {
+ public double getDouble(Object that)
+ {
+ try
+ {
return javaField.getDouble(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public float getFloat(Object that) {
- try {
+ public float getFloat(Object that)
+ {
+ try
+ {
return javaField.getFloat(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public int getInt(Object that) {
- try {
+ public int getInt(Object that)
+ {
+ try
+ {
return javaField.getInt(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public long getLong(Object that) {
- try {
+ public long getLong(Object that)
+ {
+ try
+ {
return javaField.getLong(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public short getShort(Object that) {
- try {
+ public short getShort(Object that)
+ {
+ try
+ {
return javaField.getShort(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public Object get(Object that) {
- try {
+ public Object get(Object that)
+ {
+ try
+ {
return javaField.get(that);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setBoolean(Object that, boolean value) {
- try {
- javaField.setBoolean(that, value);
- } catch (Exception ex) {
+ public void setBoolean(Object that, boolean value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setBoolean(that, value);
+ }
+ else
+ {
+ javaField.setBoolean(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setByte(Object that, byte value) {
- try {
- javaField.setByte(that, value);
- } catch (Exception ex) {
+ public void setByte(Object that, byte value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setByte(that, value);
+ }
+ else
+ {
+ javaField.setByte(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setChar(Object that, char value) {
- try {
- javaField.setChar(that, value);
- } catch (Exception ex) {
+ public void setChar(Object that, char value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setChar(that, value);
+ }
+ else
+ {
+ javaField.setChar(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setDouble(Object that, double value) {
- try {
- javaField.setDouble(that, value);
- } catch (Exception ex) {
+ public void setDouble(Object that, double value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setDouble(that, value);
+ }
+ else
+ {
+ javaField.setDouble(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setFloat(Object that, float value) {
- try {
- javaField.setFloat(that, value);
- } catch (Exception ex) {
+ public void setFloat(Object that, float value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setFloat(that, value);
+ }
+ else
+ {
+ javaField.setFloat(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setInt(Object that, int value) {
- try {
- javaField.setInt(that, value);
- } catch (Exception ex) {
+ public void setInt(Object that, int value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setInt(that, value);
+ }
+ else
+ {
+ javaField.setInt(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setLong(Object that, long value) {
- try {
- javaField.setLong(that, value);
- } catch (Exception ex) {
+ public void setLong(Object that, long value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setLong(that, value);
+ }
+ else
+ {
+ javaField.setLong(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void setShort(Object that, short value) {
- try {
- javaField.setShort(that, value);
- } catch (Exception ex) {
+ public void setShort(Object that, short value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.setShort(that, value);
+ }
+ else
+ {
+ javaField.setShort(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
- public void set(Object that, Object value) {
- try {
- javaField.set(that, value);
- } catch (Exception ex) {
+ public void set(Object that, Object value)
+ {
+ try
+ {
+ if(isFinal)
+ {
+ finalFieldSetter.set(that, value);
+ }
+ else
+ {
+ javaField.set(that, value);
+ }
+ }
+ catch (Exception ex)
+ {
throw new SystemException(ex);
}
}
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java Fri Mar 25 03:54:30 2005
@@ -36,27 +36,23 @@
import org.apache.geronimo.interop.rmi.iiop.compiler.StubFactory;
import org.apache.geronimo.interop.util.ExceptionUtil;
-
public class ClientNamingContext implements Context, java.io.Serializable {
+
public static ClientNamingContext getInstance(Hashtable env) {
- ClientNamingContext nc = (ClientNamingContext) _contextMap.get(env);
+ ClientNamingContext nc = (ClientNamingContext) contextMap.get(env);
if (nc == null) {
- synchronized (_contextMap) {
- nc = (ClientNamingContext) _contextMap.get(env);
+ synchronized (contextMap) {
+ nc = (ClientNamingContext) contextMap.get(env);
if (nc == null) {
nc = new ClientNamingContext();
nc.init(env);
- _contextMap.put(env, nc);
+ contextMap.put(env, nc);
}
}
}
return nc;
}
- // -----------------------------------------------------------------------
- // properties
- // -----------------------------------------------------------------------
-
public static final StringProperty usernameProperty =
new StringProperty(SystemProperties.class, "java.naming.security.principal");
@@ -67,64 +63,45 @@
new IntProperty(SystemProperties.class, "org.apache.geronimo.interop.rmi.idleConnectionTimeout")
.defaultValue(60); // seconds
- // -----------------------------------------------------------------------
- // private data
- // -----------------------------------------------------------------------
-
- private static int _idleConnectionTimeout =
+ private static int idleConnectionTimeout =
idleConnectionTimeoutProperty.getInt();
- private static int _namingContextCacheTimeout =
+ private static int namingContextCacheTimeout =
SystemProperties.rmiNamingContextCacheTimeoutProperty.getInt();
- private static HashMap _contextMap = new HashMap();
-
- private static HashMap _hostListCache = new HashMap();
-
- private static HashMap _multiHostMap = new HashMap();
-
- private static Random _random = new Random();
-
- private HashMap _cache = new HashMap();
-
- private Hashtable _env;
-
- private ConnectionPool _connectionPool;
+ private static HashMap contextMap = new HashMap();
+ private static HashMap hostListCache = new HashMap();
+ private static HashMap multiHostMap = new HashMap();
+ private static Random random = new Random();
+ private HashMap cache = new HashMap();
+ private Hashtable env;
+ private ConnectionPool connectionPool;
+ private PropertyMap connectionProperties;
+ static private HashMap nameMap = new HashMap();
+ private String prefix;
+ private String username;
+ private String password;
- private PropertyMap _connectionProperties;
-
- private org.apache.geronimo.interop.CosNaming.NamingContext _serverNamingContext;
- static private HashMap _nameMap = new HashMap();
-
-
- private String _prefix;
-
- private String _username;
-
- private String _password;
-
- // -----------------------------------------------------------------------
- // public methods
- // -----------------------------------------------------------------------
+ private org.apache.geronimo.interop.CosNaming.NamingContext serverNamingContext;
public ConnectionPool getConnectionPool() {
- return _connectionPool;
+ return connectionPool;
}
public PropertyMap getConnectionProperties() {
- return _connectionProperties;
+ return connectionProperties;
}
public int getIdleConnectionTimeout() {
- return _idleConnectionTimeout;
+ return idleConnectionTimeout;
}
public String getUsername() {
- return _username;
+ return username;
}
public String getPassword() {
- return _password;
+ return password;
}
// -----------------------------------------------------------------------
@@ -140,22 +117,22 @@
name = name.substring(14);
}
- String newName = (String) _nameMap.get(name);
+ String newName = (String) nameMap.get(name);
if (newName != null) {
name = newName;
}
- NameBinding nb = (NameBinding) _cache.get(name);
+ NameBinding nb = (NameBinding) cache.get(name);
if (nb == null) {
- synchronized (_cache) {
- nb = (NameBinding) _cache.get(name);
+ synchronized (cache) {
+ nb = (NameBinding) cache.get(name);
if (nb != null && nb.hasExpired()) {
- _cache.remove(name);
+ cache.remove(name);
nb = null;
}
if (nb == null) {
nb = resolve(name);
- _cache.put(name, nb);
+ cache.put(name, nb);
}
}
}
@@ -163,17 +140,16 @@
}
public HostList lookupHost(String name) {
- NameBinding nb = (NameBinding) _hostListCache.get(name);
+ NameBinding nb = (NameBinding) hostListCache.get(name);
if (nb == null) {
- synchronized (_hostListCache) {
- nb = (NameBinding) _hostListCache.get(name);
+ synchronized (hostListCache) {
+ nb = (NameBinding) hostListCache.get(name);
if (nb != null && nb.hasExpired()) {
- _hostListCache.remove(name);
+ hostListCache.remove(name);
nb = null;
}
- if (nb == null) {
- nb = resolve_host(name);
- _hostListCache.put(name, nb);
+ if (nb == null) {
+ hostListCache.put(name, nb);
}
}
}
@@ -181,7 +157,7 @@
}
public static void bind(String bindName, String name) throws NamingException {
- _nameMap.put(bindName, name);
+ nameMap.put(bindName, name);
}
public void bind(Name name, Object obj) throws NamingException {
@@ -217,22 +193,18 @@
}
public NamingEnumeration list(Name name) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
public NamingEnumeration list(String name) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
public NamingEnumeration listBindings(Name name) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
public NamingEnumeration listBindings(String name) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
@@ -253,12 +225,10 @@
}
public Object lookupLink(Name name) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
public Object lookupLink(String name) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
@@ -271,12 +241,10 @@
}
public Name composeName(Name name, Name prefix) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
public String composeName(String name, String prefix) throws NamingException {
- // TODO: support this
throw new OperationNotSupportedException();
}
@@ -300,12 +268,8 @@
throw new OperationNotSupportedException();
}
- // -----------------------------------------------------------------------
- // protected methods
- // -----------------------------------------------------------------------
-
protected void init(Hashtable env) {
- _env = env;
+ env = env;
Object urlObject = env.get(Context.PROVIDER_URL);
if (urlObject == null) {
System.out.println("ClientNamingContext.init(): TODO: urlObject was null, create one based on the current hostname.");
@@ -314,16 +278,16 @@
}
String url = urlObject.toString();
UrlInfo urlInfo = UrlInfo.getInstance(url);
- _serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext)
+ serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext)
StubFactory.getInstance().getStub(org.apache.geronimo.interop.CosNaming.NamingContext.class);
- ObjectRef ncRef = (ObjectRef) _serverNamingContext;
+ ObjectRef ncRef = (ObjectRef) serverNamingContext;
ncRef.$setNamingContext(this);
ncRef.$setProtocol(urlInfo.getProtocol());
ncRef.$setHost("ns~" + urlInfo.getHost());
ncRef.$setPort(urlInfo.getPort());
ncRef.$setObjectKey(urlInfo.getObjectKey());
- _connectionProperties = urlInfo.getProperties();
- _connectionPool = ConnectionPool.getInstance(this);
+ connectionProperties = urlInfo.getProperties();
+ connectionPool = ConnectionPool.getInstance(this);
Object u = env.get(Context.SECURITY_PRINCIPAL);
Object p = env.get(Context.SECURITY_CREDENTIALS);
if (u == null) {
@@ -332,8 +296,8 @@
if (p == null) {
p = passwordProperty.getString();
}
- _username = u != null ? u.toString() : null;
- _password = p != null ? p.toString() : null;
+ username = u != null ? u.toString() : null;
+ password = p != null ? p.toString() : null;
/*
if (_serverNamingContext._is_a("IDL:org.apache.geronimo.interop/rmi/iiop/NameService:1.0"))
@@ -355,34 +319,21 @@
if (value != null) {
NameBinding nb = new NameBinding();
nb.object = value;
- nb.cacheTimeout = System.currentTimeMillis() + _namingContextCacheTimeout;
+ nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout;
return nb;
}
try {
org.apache.geronimo.interop.CosNaming.NameComponent[] resolveName =
{new org.apache.geronimo.interop.CosNaming.NameComponent(name, "")};
- org.omg.CORBA.Object object = _serverNamingContext.resolve(resolveName);
+ org.omg.CORBA.Object object = serverNamingContext.resolve(resolveName);
NameBinding nb = new NameBinding();
nb.object = object;
- nb.cacheTimeout = System.currentTimeMillis() + _namingContextCacheTimeout;
+ nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout;
return nb;
} catch (org.apache.geronimo.interop.CosNaming.NamingContextPackage.NotFound notFound) {
throw new NameNotFoundException(name);
} catch (Exception ex) {
throw new javax.naming.NamingException(ExceptionUtil.getStackTrace(ex));
}
- }
-
- protected NameBinding resolve_host(String host) {
- HostList list = null;
- if (_serverNamingContext instanceof org.apache.geronimo.interop.rmi.iiop.NameService) {
- org.apache.geronimo.interop.rmi.iiop.NameService nameService = (org.apache.geronimo.interop.rmi.iiop.NameService) _serverNamingContext;
- list = new HostList(nameService.resolve_host(host));
- }
- NameBinding nb = new NameBinding();
- nb.object = list;
- //nb.cacheTimeout = System.currentTimeMillis()
- // + (list != null ? list.getCacheTimeout() : _namingContextCacheTimeout);
- return nb;
}
}
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java Fri Mar 25 03:54:30 2005
@@ -39,8 +39,8 @@
import org.apache.geronimo.interop.util.ThreadContext;
import org.apache.geronimo.interop.util.UTF8;
-
public class Connection {
+
public Connection() {
}
@@ -50,10 +50,6 @@
return conn;
}
- // -----------------------------------------------------------------------
- // properties
- // -----------------------------------------------------------------------
-
public static final BooleanProperty simpleIDLProperty =
new BooleanProperty(SystemProperties.class, "org.apache.geronimo.interop.simpleIDL");
@@ -61,104 +57,56 @@
new IntProperty(Connection.class, "socketTimeout")
.defaultValue(SystemProperties.rmiSocketTimeoutProperty.getInt());
- // -----------------------------------------------------------------------
- // private data
- // -----------------------------------------------------------------------
-
- private static final boolean SIMPLE_IDL = simpleIDLProperty.getBoolean();
-
- private ServiceContext[] EMPTY_SERVICE_CONTEXT = {};
-
- private String _url;
-
- private boolean _ok;
-
- private InstancePool _pool;
-
- private String _serverHost;
-
- private Socket _socket;
-
- private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream _input;
-
- private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream _output;
-
- private CdrOutputStream _parameters;
+ private static final boolean SIMPLE_IDL = false; // simpleIDLProperty.getBoolean();
+ private ServiceContext[] EMPTY_SERVICE_CONTEXT = {};
+ private String url;
+ private boolean ok;
+ private InstancePool pool;
+ private String serverHost;
+ private Socket socket;
+ private CdrOutputStream parameters;
+ private CdrOutputStream requestOut;
+ private CdrInputStream results;
+ private String exceptionType;
+ private Exception exception;
+ private RequestHeader_1_2 requestHeader;
+ private int callForget;
- private CdrOutputStream _requestOut;
+ private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input;
+ private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output;
- private CdrInputStream _results;
-
- private String _exceptionType;
-
- private Exception _exception;
-
- private RequestHeader_1_2 _requestHeader;
-
- private int _callForget;
-
- // -----------------------------------------------------------------------
- // protected data
- // -----------------------------------------------------------------------
-
- protected java.io.InputStream _socketIn;
-
- protected java.io.OutputStream _socketOut;
-
- // -----------------------------------------------------------------------
- // public methods
- // -----------------------------------------------------------------------
+ protected java.io.InputStream socketIn;
+ protected java.io.OutputStream socketOut;
public String getInstanceName() {
- return _url;
+ return url;
}
public void close() {
- _parameters = null;
-// _results.recycle();
-// _results = null;
- _input = null;
- _output = null;
- if (_ok) {
- _pool.put(this);
+ parameters = null;
+ input = null;
+ output = null;
+ if (ok) {
+ pool.put(this);
} else {
shutdown();
}
}
public void beforeInvoke() {
- _ok = false;
- _parameters = CdrOutputStream.getInstance();
+ ok = false;
+ parameters = CdrOutputStream.getInstance();
}
public void forget(Object requestKey) {
- if (_callForget != 0) {
- /*
- String key = (String)requestKey;
- try
- {
- ClusterService cs = _results.getNamingContext().getClusterService();
- if (_callForget == 0xCFCFCFCF)
- {
- cs.forgetRequest(key);
- }
- else if (_callForget == 0xDFDFDFDF)
- {
- cs.forgetResponse(key);
- }
- }
- catch (Exception ignore)
- {
- // TODO: log in debug mode?
- }
- */
- }
}
public void invoke(ObjectRef object, String method, Object requestKey, int retryCount) {
- _callForget = 0; // see 'forget' and 'processReplyServiceContext'
+ RequestHeader_1_2 request = requestHeader;
- RequestHeader_1_2 request = _requestHeader;
+ System.out.println( "object = " + object );
+ System.out.println( "method = " + method );
+ System.out.println( "requestKey = " + requestKey );
request.request_id = 0;
request.response_flags = 3;
@@ -169,13 +117,15 @@
request.reserved = new byte[3]; // Sun's generated org.omg.GIOP.RequestHeader_1_2Helper wants this....
- if (_requestOut == null) {
- _requestOut = CdrOutputStream.getInstance();
+ if (requestOut == null) {
+ System.out.println( "requestOut == null" );
+ requestOut = CdrOutputStream.getInstance();
}
- _requestOut.write_request(request, _parameters);
+ System.out.println( "write_request" );
+ requestOut.write_request(request, parameters);
try {
- _requestOut.send_message(_socketOut, _url);//_serverHost);
+ requestOut.send_message(socketOut, url);//_serverHost);
} catch (RuntimeException ex) {
//if (object.$getAutomaticFailover())
//{
@@ -184,18 +134,18 @@
throw ex;
}
- _requestOut.reset();
+ requestOut.reset();
- if (_results == null) {
- _results = CdrInputStream.getInstance();
+ if (results == null) {
+ results = CdrInputStream.getInstance();
} else {
- _results.reset();
+ results.reset();
}
- _results.setNamingContext(object.$getNamingContext());
+ results.setNamingContext(object.$getNamingContext());
GiopMessage message;
try {
- message = _results.receive_message(_socketIn, _url);//_serverHost);
+ message = results.receive_message(socketIn, url);//_serverHost);
} catch (BadMagicException ex) {
throw new SystemException(ex);
} catch (UnsupportedProtocolVersionException ex) {
@@ -213,88 +163,84 @@
throw new SystemException("TODO: message type = " + message.type);
}
- _ok = true;
+ ok = true;
}
public InstancePool getInstancePool() {
- return _pool;
+ return pool;
}
public void setInstancePool(InstancePool pool) {
- _pool = pool;
+ this.pool = pool;
}
public org.apache.geronimo.interop.rmi.iiop.ObjectInputStream getInputStream() {
if (SIMPLE_IDL) {
return getSimpleInputStream();
}
- if (_input == null) {
- _input = org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.getInstance(_results);
+ if (input == null) {
+ input = org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.getInstance(results);
}
- return _input;
+ return input;
}
public org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream getOutputStream() {
if (SIMPLE_IDL) {
return getSimpleOutputStream();
}
- if (_output == null) {
- _output = org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.getInstance(_parameters);
+ if (output == null) {
+ output = org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.getInstance(parameters);
}
- return _output;
+ return output;
}
public org.apache.geronimo.interop.rmi.iiop.ObjectInputStream getSimpleInputStream() {
- if (_input == null) {
- _input = org.apache.geronimo.interop.rmi.iiop.SimpleObjectInputStream.getInstance(_results);
+ if (input == null) {
+ input = org.apache.geronimo.interop.rmi.iiop.SimpleObjectInputStream.getInstance(results);
}
- return _input;
+ return input;
}
public org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream getSimpleOutputStream() {
- if (_output == null) {
- _output = org.apache.geronimo.interop.rmi.iiop.SimpleObjectOutputStream.getInstance(_parameters);
+ if (output == null) {
+ output = org.apache.geronimo.interop.rmi.iiop.SimpleObjectOutputStream.getInstance(parameters);
}
- return _output;
+ return output;
}
public String getExceptionType() {
- return _exceptionType;
+ return exceptionType;
}
public Exception getException() {
- if (_exception == null) {
- if (_exceptionType != null) {
- return new SystemException(_exceptionType, new org.omg.CORBA.UNKNOWN());
+ if (exception == null) {
+ if (exceptionType != null) {
+ return new SystemException(exceptionType, new org.omg.CORBA.UNKNOWN());
} else {
throw new IllegalStateException("no exception");
}
} else {
- return _exception;
+ return exception;
}
}
- // -----------------------------------------------------------------------
- // protected methods
- // -----------------------------------------------------------------------
-
// TODO: check why we have 'objectRef' parameter???
protected void init(String endpoint, ObjectRef objectRef, PropertyMap connProps) {
- _url = "iiop://" + endpoint;
- UrlInfo urlInfo = UrlInfo.getInstance(_url);
+ url = "iiop://" + endpoint;
+ UrlInfo urlInfo = UrlInfo.getInstance(url);
String host = urlInfo.getHost();
int port = urlInfo.getPort();
int socketTimeout = socketTimeoutProperty.getInt(endpoint, connProps);
try {
- _socket = new Socket(host, port);
- _socketIn = _socket.getInputStream();
- _socketOut = _socket.getOutputStream();
- _socket.setSoTimeout(1000 * socketTimeout);
- _serverHost = host;
+ socket = new Socket(host, port);
+ socketIn = socket.getInputStream();
+ socketOut = socket.getOutputStream();
+ socket.setSoTimeout(1000 * socketTimeout);
+ serverHost = host;
} catch (Exception ex) {
throw new SystemException(errorConnectFailed(host, port, ex));
}
- _requestHeader = new RequestHeader_1_2();
+ requestHeader = new RequestHeader_1_2();
}
public ServiceContext[] getServiceContext(ObjectRef object, Object requestKey, int retryCount) {
@@ -386,7 +332,7 @@
|| sc.context_id == 0xDFDFDFDF) {
// "CF..." indicates "Call Forget Request"
// "DF..." indicates "Call Forget Response"
- _callForget = sc.context_id;
+ callForget = sc.context_id;
}
}
}
@@ -396,31 +342,31 @@
}
protected void processUserException(ReplyHeader_1_2 reply) {
- _exception = null;
- _exceptionType = _results.read_string();
- _ok = true;
+ exception = null;
+ exceptionType = results.read_string();
+ ok = true;
}
protected void processSystemException(ReplyHeader_1_2 reply) {
- _exceptionType = "???";
- SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(_results);
+ exceptionType = "???";
+ SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(results);
String id = replyBody.exception_id;
id = StringUtil.removePrefix(id, "IDL:omg.org/CORBA/");
id = StringUtil.removeSuffix(id, ":1.0");
String stackTrace = null;
- if (_results.hasMoreData()) {
- stackTrace = _results.read_string() + ExceptionUtil.getDivider();
+ if (results.hasMoreData()) {
+ stackTrace = results.read_string() + ExceptionUtil.getDivider();
}
- _ok = true;
+ ok = true;
String exceptionClassName = "org.omg.CORBA." + id;
try {
Class exceptionClass = ThreadContext.loadClass(exceptionClassName);
org.omg.CORBA.SystemException corbaException = (org.omg.CORBA.SystemException) exceptionClass.newInstance();
corbaException.minor = replyBody.minor_code_value;
corbaException.completed = org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status);
- _exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException);
+ exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException);
} catch (Exception ex) {
- _exception = new org.apache.geronimo.interop.SystemException(stackTrace,
+ exception = new org.apache.geronimo.interop.SystemException(stackTrace,
new org.omg.CORBA.UNKNOWN(replyBody.exception_id,
replyBody.minor_code_value,
org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status)));
@@ -428,30 +374,28 @@
}
public void shutdown() {
- if (_socketOut != null) {
+ if (socketOut != null) {
try {
- _socketOut.close();
+ socketOut.close();
} catch (Exception ignore) {
}
- _socketOut = null;
+ socketOut = null;
}
- if (_socketIn != null) {
+ if (socketIn != null) {
try {
- _socketIn.close();
+ socketIn.close();
} catch (Exception ignore) {
}
- _socketIn = null;
+ socketIn = null;
}
- if (_socket != null) {
+ if (socket != null) {
try {
- _socket.close();
+ socket.close();
} catch (Exception ignore) {
}
- _socket = null;
+ socket = null;
}
}
-
- // log methods
protected String errorConnectFailed(String host, int port, Exception ex) {
String msg;
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java Fri Mar 25 03:54:30 2005
@@ -27,7 +27,6 @@
import org.apache.geronimo.interop.util.InstancePool;
import org.apache.geronimo.interop.util.StringUtil;
-
public class ConnectionPool {
public static ConnectionPool getInstance(ClientNamingContext namingContext) {
ConnectionPool object = new ConnectionPool();
@@ -35,17 +34,21 @@
return object;
}
- // private data
-
- private ClientNamingContext _namingContext;
-
- private HashMap _poolMap;
-
- // public methods
+ private ClientNamingContext namingContext;
+ private HashMap poolMap;
public Connection get(int protocol, String endpoint, ObjectRef objectRef) {
- System.out.println("ConnectionPool.get(): protocol: " + protocol + ", endpoint: " + endpoint + ", objectRef: " + objectRef);
+ //System.out.println("ConnectionPool.get(): protocol: " + protocol + ", endpoint: " + endpoint + ", objectRef: " + objectRef);
+
+ InstancePool pool = getInstancePool(protocol, endpoint);
+ System.out.println("ConnectionPool.get(): pool: " + pool);
+ Connection conn = (Connection) pool.get();
+ if (conn == null) {
+ conn = newConnection(protocol, endpoint, objectRef, pool);
+ }
+ return conn;
+ /*
HostList hostList = resolve(endpoint, objectRef);
System.out.println("ConnectionPool.get(): hostlist: " + hostList);
if (hostList == null) {
@@ -87,17 +90,16 @@
// TODO: I18N
throw new SystemException("CONNECT FAILED: host list = " + hostList);
}
+ */
}
public void put(Connection conn) {
conn.getInstancePool().put(conn);
}
- // protected methods
-
protected void init(ClientNamingContext namingContext) {
- _namingContext = namingContext;
- _poolMap = new HashMap();
+ this.namingContext = namingContext;
+ poolMap = new HashMap();
}
/**
@@ -154,40 +156,14 @@
protected InstancePool getInstancePool(final int protocol, final String endpoint) {
System.out.println("ConnectionPool.getInstancePool(): protocol: " + protocol + ", endpoint: " + endpoint);
- InstancePool pool = (InstancePool) _poolMap.get(endpoint);
+ InstancePool pool = (InstancePool) poolMap.get(endpoint);
if (pool == null) {
- synchronized (_poolMap) {
- pool = (InstancePool) _poolMap.get(endpoint);
+ synchronized (poolMap) {
+ pool = (InstancePool) poolMap.get(endpoint);
if (pool == null) {
String poolName = Protocol.getName(protocol) + "://" + endpoint;
- //long idleTimeout = 1000 * _namingContext.getIdleConnectionTimeout();
- //if (idleTimeout > 0)
- //{
-/*
- pool = new InstancePool
- (
- poolName,
- idleTimeout,
- new TimeoutObject()
- {
- public void onTimeout(Object object)
- {
- Connection conn = (Connection)object;
- if (RmiTrace.CONNECT)
- {
- RmiTrace.getInstance().traceDisconnect(Protocol.getName(protocol) + "://" + endpoint);
- }
- conn.shutdown();
- }
- }
- );
- */
- //}
- //else
- //{
pool = new InstancePool(poolName);
- //}
- _poolMap.put(endpoint, pool);
+ poolMap.put(endpoint, pool);
}
}
}
@@ -231,7 +207,10 @@
}
protected Connection iiopConnection(String endpoint, ObjectRef objectRef) {
- return Connection.getInstance(endpoint, objectRef, _namingContext.getConnectionProperties());
+ System.out.println( "endpoint : " + endpoint );
+ System.out.println( "objectRef : " + objectRef );
+ System.out.println( "namingContext : " + namingContext );
+ return Connection.getInstance(endpoint, objectRef, namingContext.getConnectionProperties());
}
protected Connection iiopsConnection(String endpoint, ObjectRef objectRef) {
@@ -246,14 +225,15 @@
throw new SystemException("TODO");
}
+ /*
protected HostList resolve(String endpoint, ObjectRef objectRef) {
-/*
- if (objectRef instanceof org.apache.geronimo.interop.rmi.iiop.NameService
- && ! endpoint.startsWith("ns~mh~"))
- {
- return null; // Avoid unbounded recursion
- }
- */
+
+ //if (objectRef instanceof org.apache.geronimo.interop.rmi.iiop.NameService
+ // && ! endpoint.startsWith("ns~mh~"))
+ //{
+ // return null; // Avoid unbounded recursion
+ //}
+
HostList hostList = _namingContext.lookupHost(objectRef.$getHost()); // this uses a cache for good performance
if (hostList != null
&& hostList.getPreferredServers().size() == 0
@@ -264,4 +244,5 @@
}
return hostList;
}
+ */
}
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java Fri Mar 25 03:54:30 2005
@@ -18,9 +18,8 @@
package org.apache.geronimo.interop.rmi.iiop.client;
public class NameBinding {
- public Object object;
-
- public long cacheTimeout;
+ public Object object;
+ public long cacheTimeout;
public boolean hasExpired() {
long timeout = cacheTimeout;
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java Fri Mar 25 03:54:30 2005
@@ -29,7 +29,6 @@
import org.apache.geronimo.interop.util.NamedValueList;
import org.apache.geronimo.interop.util.StringUtil;
-
public class UrlInfo {
public static UrlInfo getInstance(String url) {
UrlInfo object = new UrlInfo();
@@ -46,94 +45,84 @@
return list;
}
- // private data
-
- private int _protocol;
-
- private String _host;
-
- private int _port;
-
- private String _objectKey;
-
- private PropertyMap _properties;
-
- // internal methods
+ private int protocol;
+ private String host;
+ private int port;
+ private String objectKey;
+ private PropertyMap properties;
protected void init(String urlString) {
int cssPos = urlString.indexOf("://");
if (cssPos == -1) {
throw new IllegalArgumentException(urlString);
}
- _protocol = Protocol.getNumber(urlString.substring(0, cssPos));
+ protocol = Protocol.getNumber(urlString.substring(0, cssPos));
try {
URL url = new URL("http" + urlString.substring(cssPos));
- _host = url.getHost();
- _port = url.getPort();
- if (_port == -1) {
- switch (_protocol) {
+ host = url.getHost();
+ port = url.getPort();
+ if (port == -1) {
+ switch (protocol) {
case Protocol.HTTP:
- _port = 80; // see http://www.iana.org/assignments/port-numbers
+ port = 80; // see http://www.iana.org/assignments/port-numbers
break;
case Protocol.HTTPS:
- _port = 443; // see http://www.iana.org/assignments/port-numbers
+ port = 443; // see http://www.iana.org/assignments/port-numbers
break;
case Protocol.IIOP:
- _port = 683; // see http://www.iana.org/assignments/port-numbers
+ port = 683; // see http://www.iana.org/assignments/port-numbers
break;
case Protocol.IIOPS:
- _port = 684; // see http://www.iana.org/assignments/port-numbers
+ port = 684; // see http://www.iana.org/assignments/port-numbers
break;
default:
throw new IllegalStateException("url = " + urlString);
}
}
- _objectKey = url.getFile();
- if (_objectKey == null) {
- _objectKey = "";
+ objectKey = url.getFile();
+ if (objectKey == null) {
+ objectKey = "";
}
- int queryPos = _objectKey.indexOf('?');
+ int queryPos = objectKey.indexOf('?');
if (queryPos != -1) {
- _objectKey = _objectKey.substring(0, queryPos);
+ objectKey = objectKey.substring(0, queryPos);
}
- _objectKey = StringUtil.removePrefix(_objectKey, "/");
- if (_objectKey.length() == 0) {
- _objectKey = "NameService";
+ objectKey = StringUtil.removePrefix(objectKey, "/");
+ if (objectKey.length() == 0) {
+ objectKey = "NameService";
}
String query = url.getQuery();
if (query == null) {
query = "";
}
String props = StringUtil.removePrefix(query, "?").replace('&', ',');
- _properties = new NamedValueList(props).getProperties();
+ properties = new NamedValueList(props).getProperties();
} catch (Exception ex) {
throw new SystemException(ex);
}
}
- // public methods
-
public int getProtocol() {
- return _protocol;
+ return protocol;
}
public String getHost() {
- return _host;
+ return host;
}
public int getPort() {
- return _port;
+ return port;
}
public String getObjectKey() {
- return _objectKey;
+ return objectKey;
}
public PropertyMap getProperties() {
- return _properties;
+ return properties;
}
public String toString() {
- return Protocol.getName(_protocol) + "://" + _host + ":" + _port + "/" + _objectKey;
+ return Protocol.getName(protocol) + "://" + host + ":" + port + "/" + objectKey;
}
}
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java?view=diff&r1=159004&r2=159005
==============================================================================
--- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java (original)
+++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java Fri Mar 25 03:54:30 2005
@@ -18,30 +18,30 @@
package org.apache.geronimo.interop.rmi.iiop.client;
public class ValueInfo {
- public String _nameToBeResolved = null;
- public Object _objectToBeBound = null;
+ public String nameToBeResolved = null;
+ public Object objectToBeBound = null;
public ValueInfo(String nameToBeResolved) {
- _nameToBeResolved = nameToBeResolved;
+ this.nameToBeResolved = nameToBeResolved;
}
public ValueInfo(Object objectToBeBound) {
- _objectToBeBound = objectToBeBound;
+ this.objectToBeBound = objectToBeBound;
}
public void setNameToBeResolved(String name) {
- _nameToBeResolved = name;
+ nameToBeResolved = name;
}
public String getNameToBeResolved() {
- return _nameToBeResolved;
+ return nameToBeResolved;
}
public void setObjectToBeBound(Object object) {
- _objectToBeBound = object;
+ objectToBeBound = object;
}
public Object getObjectToBeBound() {
- return _objectToBeBound;
+ return objectToBeBound;
}
}
|