You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/07/09 20:08:21 UTC

svn commit: r554723 [1/2] - in /incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb: java2idl/ util/

Author: rfeng
Date: Mon Jul  9 11:08:19 2007
New Revision: 554723

URL: http://svn.apache.org/viewvc?view=rev&rev=554723
Log:
Clean up the ejb-binding code

Modified:
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java
    incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java Mon Jul  9 11:08:19 2007
@@ -26,37 +26,34 @@
  * Mode of an IDL attribute
  */
 public final class AttributeMode implements IDLEntity {
-    private static final long serialVersionUID = 4193442157999151834L;
+    public static final int INT_NORMAL = 0;
+    public static final int INT_READONLY = 1;
+    public static final AttributeMode ATTR_NORMAL = new AttributeMode(INT_NORMAL);
+    public static final AttributeMode ATTR_READONLY = new AttributeMode(INT_READONLY);
+    private static final long serialVersionUID = 8549003678215309053L;
 
-    private int value;
+    private final int value;
 
-    public static final int _ATTR_NORMAL = 0;
-
-    public static final AttributeMode ATTR_NORMAL = new AttributeMode(_ATTR_NORMAL);
-
-    public static final int _ATTR_READONLY = 1;
-
-    public static final AttributeMode ATTR_READONLY = new AttributeMode(_ATTR_READONLY);
-
-    public int value() {
-        return value;
+    private AttributeMode(int value) {
+        this.value = value;
     }
 
-    public static AttributeMode from_int(int i) {
-        switch (i) {
-            case _ATTR_NORMAL:
+    public static AttributeMode valueOf(final int value) {
+        switch (value) {
+            case INT_NORMAL:
                 return ATTR_NORMAL;
-            case _ATTR_READONLY:
+            case INT_READONLY:
                 return ATTR_READONLY;
+            default:
+                throw new BAD_PARAM("Invalid Attribute Mode");
         }
-        throw new BAD_PARAM();
     }
 
-    private AttributeMode(int i) {
-        value = i;
+    public int getValue() {
+        return value;
     }
 
     Object readResolve() throws ObjectStreamException {
-        return from_int(value());
+        return valueOf(getValue());
     }
 }

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java Mon Jul  9 11:08:19 2007
@@ -34,19 +34,19 @@
     /**
      * Read Method.
      */
-    private Method readMethod = null;
+    private Method readMethod;
     /**
      * Write Method. This is null for read-only attributes.
      */
-    private Method writeMethod = null;
+    private Method writeMethod;
     /**
      * Read method type.
      */
-    private OperationType readOperationType = null;
+    private OperationType readOperationType;
     /**
      * Write method type. This is null for read-only attributes.
      */
-    private OperationType writeOperationType = null;
+    private OperationType writeOperationType;
 
     /**
      * Create an attribute type.
@@ -61,8 +61,9 @@
         if (readMethod.getDeclaringClass().isInterface() && Remote.class.isAssignableFrom(readMethod
             .getDeclaringClass())) {
             readOperationType = new OperationType(readMethod);
-            if (writeMethod != null)
+            if (writeMethod != null) {
                 writeOperationType = new OperationType(writeMethod);
+            }    
             setIDLName(getIDLName()); // Fixup operation names
         }
     }
@@ -71,14 +72,14 @@
      * Create an attribute type for a read-only attribute.
      */
     AttributeType(String javaName, Method accessor) {
-        this(javaName, AttributeMode.ATTR_READONLY, accessor, null);
+        this(javaName, AttributeMode.ATTR_READONLY, accessor, null); //NOPMD
     }
 
     /**
      * Create an attribute type for a read-write attribute.
      */
     AttributeType(String javaName, Method accessor, Method mutator) {
-        this(javaName, AttributeMode.ATTR_NORMAL, accessor, mutator);
+        this(javaName, AttributeMode.ATTR_NORMAL, accessor, mutator); //NOPMD
     }
 
     /**
@@ -122,15 +123,18 @@
      */
     void setIDLName(String idlName) {
         super.setIDLName(idlName);
+        String name = idlName;
         // If the first char is an uppercase letter and the second char is not
         // an uppercase letter, then convert the first char to lowercase.
-        char ch0 = idlName.charAt(0);
-        if (Character.isUpperCase(ch0) && (idlName.length() <= 1 || (!Character.isUpperCase(idlName.charAt(1))))) {
-            idlName = Character.toLowerCase(ch0) + idlName.substring(1);
+        char ch0 = name.charAt(0);
+        if (Character.isUpperCase(ch0) && (name.length() <= 1 || (!Character.isUpperCase(name.charAt(1))))) {
+            name = Character.toLowerCase(ch0) + name.substring(1);
         }
-        if (readOperationType != null)
-            readOperationType.setIDLName("_get_" + idlName);
-        if (writeOperationType != null)
-            writeOperationType.setIDLName("_set_" + idlName);
+        if (readOperationType != null) {
+            readOperationType.setIDLName("_get_" + name);
+        }    
+        if (writeOperationType != null) {
+            writeOperationType.setIDLName("_set_" + name);
+        }    
     }
 }

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java Mon Jul  9 11:08:19 2007
@@ -19,7 +19,7 @@
 package org.apache.tuscany.sca.binding.ejb.java2idl;
 
 /**
- * IDL types.
+ * IDL types for java classes
  */
 public class ClassType extends IDLType {
 
@@ -28,17 +28,6 @@
      */
     protected Class javaClass;
 
-    private static String getJavaName(Class cls) {
-        if (cls == null)
-            throw new IllegalArgumentException("Class cannot be null.");
-        String s = cls.getName();
-        int index = s.lastIndexOf('.');
-        if (index == -1)
-            return s;
-        else
-            return s.substring(index + 1);
-    }
-
     public ClassType(Class cls, String idlName, String javaName) {
         super(idlName, javaName);
         this.javaClass = cls;
@@ -50,6 +39,19 @@
 
     public ClassType(Class cls) {
         this(cls, getJavaName(cls));
+    }
+
+    private static String getJavaName(Class cls) {
+        if (cls == null) {
+            throw new IllegalArgumentException("Class cannot be null.");
+        }
+        String s = cls.getName();
+        int index = s.lastIndexOf('.');
+        if (index == -1) {
+            return s;
+        } else {
+            return s.substring(index + 1);
+        }
     }
 
     /**

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java Mon Jul  9 11:08:19 2007
@@ -28,16 +28,17 @@
     /**
      * Java type of constant.
      */
-    private Class type;
+    private final Class type;
     /**
      * The value of the constant.
      */
-    private Object value;
+    private final Object value;
 
     ConstantType(String javaName, Class type, Object value) {
         super(javaName);
-        if (type == void.class || (!type.isPrimitive()) && type != java.lang.String.class)
+        if (type == void.class || (!type.isPrimitive()) && type != java.lang.String.class) {
             throw new IllegalArgumentException("Illegal type for constant: " + type.getName());
+        }
         this.type = type;
         this.value = value;
     }
@@ -60,9 +61,10 @@
      * Insert the constant value into the argument Any.
      */
     public void insertValue(Any any) {
-        if (type == String.class)
+        if (type == String.class) {
             any.insert_wstring((String)value); // 1.3.5.10 Map to wstring
-        else
+        } else {
             IDLUtil.insertAnyPrimitive(any, value);
+        }
     }
 }

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java Mon Jul  9 11:08:19 2007
@@ -18,47 +18,48 @@
  */
 package org.apache.tuscany.sca.binding.ejb.java2idl;
 
+import static org.apache.tuscany.sca.binding.ejb.java2idl.IDLUtil.toHexString;
+
 import java.io.Externalizable;
 import java.io.ObjectStreamClass;
 import java.io.Serializable;
-import java.lang.ref.SoftReference;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.rmi.Remote;
 import java.rmi.RemoteException;
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
-import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Common base class of ValueType and InterfaceType.
  */
 public abstract class ContainerType extends ClassType {
-
+    protected static final Map<Class, ContainerType> PARSED_TYPES = new ConcurrentHashMap<Class, ContainerType>();
     /** Flags a method as overloaded. */
-    protected final byte M_OVERLOADED = 1;
+    protected static final byte M_OVERLOADED = 1;
     /** Flags a method as the accessor of a read-write property. */
-    protected final byte M_READ = 2;
+    protected static final byte M_READ = 2;
     /** Flags a method as the mutator of a read-write property. */
-    protected final byte M_WRITE = 4;
+    protected static final byte M_WRITE = 4;
     /** Flags a method as the accessor of a read-only property. */
-    protected final byte M_READONLY = 8;
+    protected static final byte M_READONLY = 8;
     /** Flags a method as being inherited. */
-    protected final byte M_INHERITED = 16;
+    protected static final byte M_INHERITED = 16;
     /**
      * Flags a method as being the writeObject() method used for serialization.
      */
-    protected final byte M_WRITEOBJECT = 32;
+    protected static final byte M_WRITEOBJECT = 32;
     /** Flags a field as being a constant (public final static). */
-    protected final byte F_CONSTANT = 1;
+    protected static final byte F_CONSTANT = 1;
     /**
      * Flags a field as being the special <code> public final static
      *  java.io.ObjectStreamField[] serialPersistentFields</code>
      * field.
      */
-    protected final byte F_SPFFIELD = 2;
+    protected static final byte F_SPFFIELD = 2;
 
     /**
      * Array of all java methods.
@@ -67,7 +68,7 @@
     /**
      * Array with flags for all java methods.
      */
-    protected byte[] m_flags;
+    protected byte[] mutatorFlags;
     /**
      * Index of the mutator for read-write attributes. Only entries
      * <code>i</code> where <code>(m_flags[i]&M_READ) != 0</code> are used.
@@ -82,23 +83,22 @@
     /**
      * Array with flags for all java fields.
      */
-    protected byte[] f_flags;
+    protected byte[] fieldFlags;
     /**
      * The class hash code, as specified in "The Common Object Request Broker:
      * Architecture and Specification" (01-02-33), section 10.6.2.
      */
-    protected long classHashCode = 0;
+    protected long classHashCode;
     /**
-     * The repository ID. This is in the RMI hashed format, like
-     * "RMI:java.util.Hashtable:C03324C0EA357270:13BB0F25214AE4B8".
+     * The repository ID. This is in the RMI hashed format.
      */
     protected String repositoryId;
     /**
      * The prefix and postfix of members repository ID. These are used to
-     * calculate member repository IDs and are like "RMI:java.util.Hashtable."
-     * and ":C03324C0EA357270:13BB0F25214AE4B8".
+     * calculate member repository IDs.
      */
-    protected String memberPrefix, memberPostfix;
+    protected String memberPrefix;
+    protected String memberPostfix;
     /**
      * Array of type of the interfaces implemented/extended here.
      */
@@ -123,12 +123,13 @@
     /**
      * A cache for the fully qualified IDL name of the IDL module we belong to.
      */
-    private String idlModuleName = null;
+    private String idlModuleName;
 
     protected ContainerType(Class cls) {
         super(cls);
-        if (cls == java.lang.Object.class || cls == java.io.Serializable.class || cls == java.io.Externalizable.class)
+        if (cls == Object.class || cls == Serializable.class || cls == Externalizable.class) {
             throw new IllegalArgumentException("Cannot parse special class: " + cls.getName());
+        }
         this.javaClass = cls;
     }
 
@@ -214,29 +215,6 @@
         return idlModuleName;
     }
 
-    // Protected -----------------------------------------------------
-    /**
-     * Convert an integer to a 16-digit hex string.
-     */
-    protected String toHexString(int i) {
-        String s = Integer.toHexString(i).toUpperCase();
-        if (s.length() < 8)
-            return "00000000".substring(0, 8 - s.length()) + s;
-        else
-            return s;
-    }
-
-    /**
-     * Convert a long to a 16-digit hex string.
-     */
-    protected String toHexString(long l) {
-        String s = Long.toHexString(l).toUpperCase();
-        if (s.length() < 16)
-            return "0000000000000000".substring(0, 16 - s.length()) + s;
-        else
-            return s;
-    }
-
     /**
      * Check if a method is an accessor.
      */
@@ -269,14 +247,17 @@
         /*
          * Is a checked exception
          */
-        if (!Throwable.class.isAssignableFrom(type))
+        if (!Throwable.class.isAssignableFrom(type)) {
             return false;
+        }
 
-        if (Error.class.isAssignableFrom(type))
+        if (Error.class.isAssignableFrom(type)) {
             return false;
+        }
 
-        if (RuntimeException.class.isAssignableFrom(type))
+        if (RuntimeException.class.isAssignableFrom(type)) {
             return false;
+        }
         return true;
     }
 
@@ -287,10 +268,12 @@
     protected boolean hasNonAppExceptions(Method m) {
         Class[] ex = m.getExceptionTypes();
         for (int i = 0; i < ex.length; ++i) {
-            if (!isCheckedException(ex[i]))
+            if (!isCheckedException(ex[i])) {
                 continue;
-            if (!RemoteException.class.isAssignableFrom(ex[i]))
+            }
+            if (!RemoteException.class.isAssignableFrom(ex[i])) {
                 return false;
+            }
         }
         return true;
     }
@@ -301,11 +284,12 @@
      */
     protected void parseFields() {
         fields = javaClass.getDeclaredFields();
-        f_flags = new byte[fields.length];
+        fieldFlags = new byte[fields.length];
         for (int i = 0; i < fields.length; ++i) {
             int mods = fields[i].getModifiers();
-            if (Modifier.isFinal(mods) && Modifier.isStatic(mods) && Modifier.isPublic(mods))
-                f_flags[i] |= F_CONSTANT;
+            if (Modifier.isFinal(mods) && Modifier.isStatic(mods) && Modifier.isPublic(mods)) {
+                fieldFlags[i] |= F_CONSTANT;
+            }
         }
     }
 
@@ -315,28 +299,23 @@
      */
     protected void parseInterfaces() {
         Class[] intfs = javaClass.getInterfaces();
-        ArrayList a = new ArrayList();
-        ArrayList b = new ArrayList();
+        List<InterfaceType> iTypes = new ArrayList<InterfaceType>();
+        List<ValueType> vTypes = new ArrayList<ValueType>();
         for (int i = 0; i < intfs.length; ++i) {
             // Ignore java.rmi.Remote
-            if (intfs[i] == java.rmi.Remote.class)
-                continue;
-            // Ignore java.io.Serializable
-            if (intfs[i] == java.io.Serializable.class)
-                continue;
-            // Ignore java.io.Externalizable
-            if (intfs[i] == java.io.Externalizable.class)
+            if (intfs[i] == Remote.class || intfs[i] == Serializable.class || intfs[i] == Externalizable.class) {
                 continue;
+            }
             if (!Java2IDLUtil.isAbstractValueType(intfs[i])) {
-                a.add(InterfaceType.getInterfaceType(intfs[i]));
+                iTypes.add(InterfaceType.getInterfaceType(intfs[i]));
             } else {
-                b.add(ValueType.getValueType(intfs[i]));
+                vTypes.add(ValueType.getValueType(intfs[i]));
             }
         }
-        interfaces = new InterfaceType[a.size()];
-        interfaces = (InterfaceType[])a.toArray(interfaces);
-        abstractBaseValuetypes = new ValueType[b.size()];
-        abstractBaseValuetypes = (ValueType[])b.toArray(abstractBaseValuetypes);
+        interfaces = new InterfaceType[iTypes.size()];
+        interfaces = (InterfaceType[])iTypes.toArray(interfaces);
+        abstractBaseValuetypes = new ValueType[vTypes.size()];
+        abstractBaseValuetypes = (ValueType[])vTypes.toArray(abstractBaseValuetypes);
     }
 
     /**
@@ -348,41 +327,43 @@
         // requires the inclusion of inherited methods in the type of
         // remote interfaces. To speed things up, inherited methods are
         // not considered in the type of a class or non-remote interface.
-        if (javaClass.isInterface() && java.rmi.Remote.class.isAssignableFrom(javaClass))
+        if (javaClass.isInterface() && Remote.class.isAssignableFrom(javaClass)) {
             methods = javaClass.getMethods();
-        else
+        } else {
             methods = javaClass.getDeclaredMethods();
-        m_flags = new byte[methods.length];
+        }
+        mutatorFlags = new byte[methods.length];
         setters = new int[methods.length];
         // Find read-write properties
-        for (int i = 0; i < methods.length; ++i)
+        for (int i = 0; i < methods.length; ++i) {
             setters[i] = -1; // no mutator here
+        }
         for (int i = 0; i < methods.length; ++i) {
-            if (isReadMethod(methods[i]) && (m_flags[i] & M_READ) == 0) {
-                String attrName = attributeReadName(methods[i].getName());
+            if (isReadMethod(methods[i]) && (mutatorFlags[i] & M_READ) == 0) {
+                String attrName = getAttributeNameFromGetter(methods[i].getName());
                 Class iReturn = methods[i].getReturnType();
                 for (int j = i + 1; j < methods.length; ++j) {
-                    if (isWriteMethod(methods[j]) && (m_flags[j] & M_WRITE) == 0
-                        && attrName.equals(attributeWriteName(methods[j].getName()))) {
+                    if (isWriteMethod(methods[j]) && (mutatorFlags[j] & M_WRITE) == 0
+                        && attrName.equals(getAttributeNameFromSetter(methods[j].getName()))) {
                         Class[] jParams = methods[j].getParameterTypes();
                         if (jParams.length == 1 && jParams[0] == iReturn) {
-                            m_flags[i] |= M_READ;
-                            m_flags[j] |= M_WRITE;
+                            mutatorFlags[i] |= M_READ;
+                            mutatorFlags[j] |= M_WRITE;
                             setters[i] = j;
                             break;
                         }
                     }
                 }
-            } else if (isWriteMethod(methods[i]) && (m_flags[i] & M_WRITE) == 0) {
-                String attrName = attributeWriteName(methods[i].getName());
+            } else if (isWriteMethod(methods[i]) && (mutatorFlags[i] & M_WRITE) == 0) {
+                String attrName = getAttributeNameFromSetter(methods[i].getName());
                 Class[] iParams = methods[i].getParameterTypes();
                 for (int j = i + 1; j < methods.length; ++j) {
-                    if (isReadMethod(methods[j]) && (m_flags[j] & M_READ) == 0
-                        && attrName.equals(attributeReadName(methods[j].getName()))) {
+                    if (isReadMethod(methods[j]) && (mutatorFlags[j] & M_READ) == 0
+                        && attrName.equals(getAttributeNameFromGetter(methods[j].getName()))) {
                         Class jReturn = methods[j].getReturnType();
                         if (iParams.length == 1 && iParams[0] == jReturn) {
-                            m_flags[i] |= M_WRITE;
-                            m_flags[j] |= M_READ;
+                            mutatorFlags[i] |= M_WRITE;
+                            mutatorFlags[j] |= M_READ;
                             setters[j] = i;
                             break;
                         }
@@ -391,22 +372,25 @@
             }
         }
         // Find read-only properties
-        for (int i = 0; i < methods.length; ++i)
-            if ((m_flags[i] & (M_READ | M_WRITE)) == 0 && isReadMethod(methods[i]))
-                m_flags[i] |= M_READONLY;
+        for (int i = 0; i < methods.length; ++i) {
+            if ((mutatorFlags[i] & (M_READ | M_WRITE)) == 0 && isReadMethod(methods[i])) {
+                mutatorFlags[i] |= M_READONLY;
+            }
+        }
         // Check for overloaded and inherited methods
         for (int i = 0; i < methods.length; ++i) {
-            if ((m_flags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) {
+            if ((mutatorFlags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) {
                 String iName = methods[i].getName();
                 for (int j = i + 1; j < methods.length; ++j) {
                     if (iName.equals(methods[j].getName())) {
-                        m_flags[i] |= M_OVERLOADED;
-                        m_flags[j] |= M_OVERLOADED;
+                        mutatorFlags[i] |= M_OVERLOADED;
+                        mutatorFlags[j] |= M_OVERLOADED;
                     }
                 }
             }
-            if (methods[i].getDeclaringClass() != javaClass)
-                m_flags[i] |= M_INHERITED;
+            if (methods[i].getDeclaringClass() != javaClass) {
+                mutatorFlags[i] |= M_INHERITED;
+            }
         }
     }
 
@@ -414,13 +398,15 @@
      * Convert an attribute read method name in Java format to an attribute name
      * in Java format.
      */
-    protected String attributeReadName(String name) {
-        if (name.startsWith("get"))
+    protected String getAttributeNameFromGetter(String attrName) {
+        String name = attrName;
+        if (name.startsWith("get")) {
             name = name.substring(3);
-        else if (name.startsWith("is"))
+        } else if (name.startsWith("is")) {
             name = name.substring(2);
-        else
-            throw new IllegalArgumentException("Not an accessor: " + name);
+        } else {
+            throw new IllegalArgumentException("Invalid accessor: " + name);
+        }
         return name;
     }
 
@@ -428,32 +414,34 @@
      * Convert an attribute write method name in Java format to an attribute
      * name in Java format.
      */
-    protected String attributeWriteName(String name) {
-        if (name.startsWith("set"))
-            name = name.substring(3);
-        else
-            throw new IllegalArgumentException("Not an accessor: " + name);
-        return name;
+    protected String getAttributeNameFromSetter(String name) {
+        if (name.startsWith("set")) {
+            return name.substring(3);
+        } else {
+            throw new IllegalArgumentException("Invalid accessor: " + name);
+        }
     }
 
     /**
      * Analyse constants. This will fill in the <code>constants</code> array.
      */
     protected void parseConstants() {
-        ArrayList a = new ArrayList();
+        List<ConstantType> types = new ArrayList<ConstantType>();
         for (int i = 0; i < fields.length; ++i) {
-            if ((f_flags[i] & F_CONSTANT) == 0)
+            if ((fieldFlags[i] & F_CONSTANT) == 0) {
                 continue;
+            }
             Class type = fields[i].getType();
             // Only map primitives and java.lang.String
             if (!type.isPrimitive() && type != java.lang.String.class) {
                 // It is an RMI/IIOP violation for interfaces.
-                if (javaClass.isInterface())
+                if (javaClass.isInterface()) {
                     throw new IDLViolationException("Field \"" + fields[i].getName()
                         + "\" of interface \""
                         + javaClass.getName()
                         + "\" is a constant, but not of one "
                         + "of the primitive types, or String.", "1.2.3");
+                }
                 continue;
             }
             String name = fields[i].getName();
@@ -461,12 +449,12 @@
             try {
                 value = fields[i].get(null);
             } catch (Exception ex) {
-                throw new RuntimeException(ex.toString());
+                throw new IllegalArgumentException(ex.toString());
             }
-            a.add(new ConstantType(name, type, value));
+            types.add(new ConstantType(name, type, value));
         }
-        constants = new ConstantType[a.size()];
-        constants = (ConstantType[])a.toArray(constants);
+        constants = new ConstantType[types.size()];
+        constants = (ConstantType[])types.toArray(constants);
     }
 
     /**
@@ -474,22 +462,23 @@
      * array.
      */
     protected void parseAttributes() {
-        ArrayList a = new ArrayList();
+        List<AttributeType> types = new ArrayList<AttributeType>();
         for (int i = 0; i < methods.length; ++i) {
             // if ((m_flags[i]&M_INHERITED) != 0)
             // continue;
-            if ((m_flags[i] & (M_READ | M_READONLY)) != 0) {
+            if ((mutatorFlags[i] & (M_READ | M_READONLY)) != 0) {
                 // Read method of an attribute.
-                String name = attributeReadName(methods[i].getName());
-                if ((m_flags[i] & M_READONLY) != 0)
-                    a.add(new AttributeType(name, methods[i]));
-                else
-                    a.add(new AttributeType(name, methods[i], methods[setters[i]]));
+                String name = getAttributeNameFromGetter(methods[i].getName());
+                if ((mutatorFlags[i] & M_READONLY) != 0) {
+                    types.add(new AttributeType(name, methods[i]));
+                } else {
+                    types.add(new AttributeType(name, methods[i], methods[setters[i]]));
+                }
             }
         }
 
-        attributes = new AttributeType[a.size()];
-        attributes = (AttributeType[])a.toArray(attributes);
+        attributes = new AttributeType[types.size()];
+        attributes = (AttributeType[])types.toArray(attributes);
     }
 
     /**
@@ -506,24 +495,30 @@
      */
     protected void fixupOverloadedOperationNames() {
         for (int i = 0; i < methods.length; ++i) {
-            if ((m_flags[i] & M_OVERLOADED) == 0)
+            if ((mutatorFlags[i] & M_OVERLOADED) == 0) {
                 continue;
+            }
             // Find the operation
             OperationType oa = null;
-            for (int opIdx = 0; oa == null && opIdx < operations.length; ++opIdx)
-                if (operations[opIdx].getMethod().equals(methods[i]))
+            for (int opIdx = 0; oa == null && opIdx < operations.length; ++opIdx) {
+                if (operations[opIdx].getMethod().equals(methods[i])) {
                     oa = operations[opIdx];
-            if (oa == null)
+                }
+            }
+            if (oa == null) {
                 continue; // This method is not mapped.
-            // Calculate new IDL name
+                // Calculate new IDL name
+            }
             ParameterType[] parms = oa.getParameters();
             StringBuffer b = new StringBuffer(oa.getIDLName());
-            if (parms.length == 0)
+            if (parms.length == 0) {
                 b.append("__");
+            }
             for (int j = 0; j < parms.length; ++j) {
                 String s = parms[j].getTypeIDLName();
-                if (s.startsWith("::"))
+                if (s.startsWith("::")) {
                     s = s.substring(2);
+                }
                 b.append('_');
                 while (!"".equals(s)) {
                     int idx = s.indexOf("::");
@@ -546,7 +541,7 @@
      * Fixup names differing only in case. As specified in section 1.3.2.7.
      */
     protected void fixupCaseNames() {
-        ArrayList entries = getContainedEntries();
+        List<IDLType> entries = getContainedEntries();
         boolean[] clash = new boolean[entries.size()];
         String[] upperNames = new String[entries.size()];
         for (int i = 0; i < entries.size(); ++i) {
@@ -561,20 +556,23 @@
             }
         }
         for (int i = 0; i < entries.size(); ++i) {
-            if (!clash[i])
+            if (!clash[i]) {
                 continue;
+            }
             IDLType aa = (IDLType)entries.get(i);
             boolean noUpper = true;
             String name = aa.getIDLName();
             StringBuffer b = new StringBuffer(name);
             b.append('_');
             for (int j = 0; j < name.length(); ++j) {
-                if (!Character.isUpperCase(name.charAt(j)))
+                if (!Character.isUpperCase(name.charAt(j))) {
                     continue;
-                if (noUpper)
+                }
+                if (noUpper) {
                     noUpper = false;
-                else
+                } else {
                     b.append('_');
+                }
                 b.append(j);
             }
             aa.setIDLName(b.toString());
@@ -585,9 +583,9 @@
      * Return a list of all the entries contained here.
      * 
      * @param entries The list of entries contained here. Entries in this list
-     *            must be subclasses of <code>AbstractType</code>.
+     *            must be subclasses of <code>IDLType</code>.
      */
-    abstract protected ArrayList getContainedEntries();
+    protected abstract List<IDLType> getContainedEntries();
 
     /**
      * Return the class hash code, as specified in "The Common Object Request
@@ -595,15 +593,16 @@
      */
     protected void calculateClassHashCode() {
         // The simple cases
-        if (javaClass.isInterface())
+        if (javaClass.isInterface()) {
             classHashCode = 0;
-        else if (!Serializable.class.isAssignableFrom(javaClass))
+        } else if (!Serializable.class.isAssignableFrom(javaClass)) {
             classHashCode = 0;
-        else if (Externalizable.class.isAssignableFrom(javaClass))
+        } else if (Externalizable.class.isAssignableFrom(javaClass)) {
             classHashCode = 1;
-        else
+        } else {
             // Go ask Util class for the hash code
             classHashCode = IDLUtil.getClassHashCode(javaClass);
+        }
     }
 
     /**
@@ -613,10 +612,11 @@
         StringBuffer b = new StringBuffer();
         for (int i = 0; i < name.length(); ++i) {
             char c = name.charAt(i);
-            if (c < 256)
+            if (c < 256) {
                 b.append(c);
-            else
-                b.append("\\U").append(toHexString((int)c));
+            } else {
+                b.append("\\U").append(IDLUtil.toHexString((int)c));
+            }
         }
         return b.toString();
     }
@@ -627,8 +627,9 @@
      * format, like "RMI:java.util.Hashtable:C03324C0EA357270:13BB0F25214AE4B8".
      */
     protected void calculateRepositoryId() {
-        if (javaClass.isArray() || javaClass.isPrimitive())
+        if (javaClass.isArray() || javaClass.isPrimitive()) {
             throw new IllegalArgumentException("Not a class or interface.");
+        }
         if (javaClass.isInterface() && org.omg.CORBA.Object.class.isAssignableFrom(javaClass)
             && org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(javaClass)) {
             StringBuffer b = new StringBuffer("IDL:");
@@ -647,145 +648,16 @@
             ObjectStreamClass osClass = ObjectStreamClass.lookup(javaClass);
             if (osClass != null) {
                 long serialVersionUID = osClass.getSerialVersionUID();
-                String SVUID = toHexString(serialVersionUID);
-                if (classHashCode != serialVersionUID)
-                    b.append(':').append(SVUID);
-                memberPostfix = ":" + hashStr + ":" + SVUID;
-            } else
-                memberPostfix = ":" + hashStr;
-            repositoryId = b.toString();
-        }
-    }
-
-    /**
-     * A simple aggregate of work-in-progress, and the thread doing the work.
-     */
-    private static class Task {
-        ContainerType type;
-        Thread thread;
-
-        Task(ContainerType type, Thread thread) {
-            this.type = type;
-            this.thread = thread;
-        }
-    }
-
-    /**
-     * Instances of this class cache the most complex types. The types cached
-     * are:
-     * <ul>
-     * <li><code>InterfaceType</code> for interfaces.</li>
-     * <li><code>ValueType</code> for value types.</li>
-     * <li><code>ExceptionType</code> for exceptions.</li>
-     * </ul>
-     * Besides caching work already done, this caches work in progress, as we
-     * need to know about this to handle cyclic graphs of parses. When a thread
-     * re-enters the <code>getType()</code> metohd, an unfinished type will be
-     * returned if the same thread is already working on this type.
-     */
-    protected static class WorkCache {
-        /**
-         * The type constructor of our type class. This constructor takes a
-         * single argument of type <code>Class</code>.
-         */
-        private Constructor constructor;
-
-        /**
-         * This maps the classes of completely done parses to soft references of
-         * their type.
-         */
-        private Map workDone;
-
-        /**
-         * This maps the classes of parses in progress to their type.
-         */
-        private Map workInProgress;
-
-        /**
-         * Create a new work cache manager.
-         * 
-         * @param containerType The class of the type type we cache here.
-         */
-        WorkCache(Class containerType) {
-            // Find the constructor and initializer.
-            try {
-                constructor = containerType.getDeclaredConstructor(new Class[] {Class.class});
-            } catch (NoSuchMethodException ex) {
-                throw new IllegalArgumentException("Bad Class: " + ex.toString());
-            }
-            workDone = new WeakHashMap();
-            workInProgress = new HashMap();
-        }
-
-        /**
-         * Returns an type. If the calling thread is currently doing an type of
-         * this class, an unfinished type is returned.
-         */
-        ContainerType getType(Class cls) {
-            ContainerType ret;
-            synchronized (this) {
-                ret = lookupDone(cls);
-                if (ret != null)
-                    return ret;
-                // is it work-in-progress?
-                Task inProgress = (Task)workInProgress.get(cls);
-                if (inProgress != null) {
-                    if (inProgress.thread == Thread.currentThread())
-                        return inProgress.type; // return unfinished
-                    // Do not wait for the other thread: We may deadlock
-                    // Double work is better than deadlock...
-                }
-                ret = createTask(cls);
-            }
-            // Do the work
-            parse(cls, ret);
-            // We did it
-            synchronized (this) {
-                workInProgress.remove(cls);
-                workDone.put(cls, new SoftReference(ret));
-                notifyAll();
-            }
-            return ret;
-        }
-
-        /**
-         * Lookup an type in the fully done map.
-         */
-        private ContainerType lookupDone(Class cls) {
-            SoftReference ref = (SoftReference)workDone.get(cls);
-            if (ref == null)
-                return null;
-            ContainerType ret = (ContainerType)ref.get();
-            if (ret == null)
-                workDone.remove(cls); // clear map entry if soft ref. was
-            // cleared.
-            return ret;
-        }
-
-        /**
-         * Create new work-in-progress.
-         */
-        private ContainerType createTask(Class cls) {
-            try {
-                ContainerType type = (ContainerType)constructor.newInstance(new Object[] {cls});
-                workInProgress.put(cls, new Task(type, Thread.currentThread()));
-                return type;
-            } catch (Exception ex) {
-                // Ignore it
-                return null;
-            }
-        }
-
-        private void parse(Class cls, ContainerType ret) {
-            try {
-                ret.parse();
-            } finally {
-                synchronized (this) {
-                    workInProgress.remove(cls);
+                String uid = toHexString(serialVersionUID);
+                if (classHashCode != serialVersionUID) {
+                    b.append(':').append(uid);
                 }
+                memberPostfix = ":" + hashStr + ":" + uid;
+            } else {
+                memberPostfix = ":" + hashStr;
             }
+            repositoryId = b.toString();
         }
-
     }
-
+    
 }

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java Mon Jul  9 11:08:19 2007
@@ -24,29 +24,34 @@
  * IDL Exception
  */
 public class ExceptionType extends ValueType {
-
-    private static WorkCache cache = new WorkCache(ExceptionType.class);
-
     private String repositoryId;
 
-    public static ExceptionType getExceptionType(Class cls) {
-        return (ExceptionType)cache.getType(cls);
-    }
-
     protected ExceptionType(Class cls) {
         super(cls);
     }
 
+    public static ExceptionType getExceptionType(Class cls) {
+        ExceptionType type = (ExceptionType)PARSED_TYPES.get(cls);
+        if (type != null) {
+            return type;
+        }
+        type = new ExceptionType(cls);
+        type.parse();
+        return type;
+    }
+
     protected void parse() {
         super.parse();
-        if (!Exception.class.isAssignableFrom(javaClass) || RuntimeException.class.isAssignableFrom(javaClass))
+        if (!Exception.class.isAssignableFrom(javaClass) || RuntimeException.class.isAssignableFrom(javaClass)) {
             throw new IDLViolationException("Exception type " + javaClass.getName() + " must be a checked exception.",
                                             "1.2.6");
+        }
         // calculate exceptionRepositoryId
         StringBuffer b = new StringBuffer("IDL:");
         String base = javaClass.getName();
-        if (base.endsWith("Exception"))
+        if (base.endsWith("Exception")) {
             base = base.substring(0, base.length() - 9);
+        }
         StringTokenizer tokenizer = new StringTokenizer(base, ".");
         while (tokenizer.hasMoreTokens()) {
             String token = tokenizer.nextToken();

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java Mon Jul  9 11:08:19 2007
@@ -19,9 +19,9 @@
 package org.apache.tuscany.sca.binding.ejb.java2idl;
 
 /**
- * Abstract base class for all IDL types.
+ * Base class for all IDL types.
  */
-abstract class IDLType {
+public abstract class IDLType {
 
     /**
      * Unqualified IDL name.
@@ -30,14 +30,14 @@
     /**
      * Unqualified java name.
      */
-    protected String javaName;
+    protected final String javaName;
 
-    IDLType(String idlName, String javaName) {
+    public IDLType(String idlName, String javaName) {
         this.idlName = idlName;
         this.javaName = javaName;
     }
 
-    IDLType(String javaName) {
+    public IDLType(String javaName) {
         this(IDLUtil.javaToIDLName(javaName), javaName);
     }
 

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java Mon Jul  9 11:08:19 2007
@@ -46,15 +46,46 @@
 /**
  * This is a RMI/IIOP metadata conversion utility class.
  */
-public class IDLUtil {
+public final class IDLUtil {
+    /**
+     * A cache for calculated class hash codes.
+     */
+    private static Map<Class, Long> classHashCodeCache = Collections.synchronizedMap(new WeakHashMap<Class, Long>());
+    /**
+     * A cache for class IR identifiers.
+     */
+    private static Map<Class, String> classIRIdentifierCache =
+        Collections.synchronizedMap(new WeakHashMap<Class, String>());
+    /**
+     * Reserved IDL keywords. Section 1.3.2.2 says that Java identifiers with
+     * these names should have prepended an underscore.
+     */
+
+    private static final Set<String> KEYWORDS = new HashSet<String>();
+    static {
+        String[] reservedIDLKeywords =
+            new String[] {"abstract", "any", "attribute", "boolean", "case", "char", "const", "context", "custom",
+                          "default", "double", "exception", "enum", "factory", "FALSE", "fixed", "float", "in",
+                          "inout", "interface", "local", "long", "module", "native", "Object", "octet", "oneway",
+                          "out", "private", "public", "raises", "readonly", "sequence", "short", "string", "struct",
+                          "supports", "switch", "TRUE", "truncatable", "typedef", "unsigned", "union", "ValueBase",
+                          "valuetype", "void", "wchar", "wstring"};
+        for (int i = 0; i < reservedIDLKeywords.length; i++) {
+            KEYWORDS.add(reservedIDLKeywords[i]);
+        }
+    }
+
+    private IDLUtil() {
+    }
 
     /**
      * Return the IDL type name for the given class. Here we use the mapping for
      * parameter types and return values.
      */
     public static String getTypeIDLName(Class cls) {
-        if (cls.isPrimitive())
+        if (cls.isPrimitive()) {
             return PrimitiveType.getPrimitiveType(cls).getIDLName();
+        }
         if (cls.isArray()) {
             int dimension = 0;
             Class type = cls;
@@ -75,20 +106,27 @@
         }
 
         // special classes
-        if (cls == java.lang.String.class)
+        if (cls == String.class) {
             return "::CORBA::WStringValue";
-        if (cls == java.lang.Object.class)
+        }
+        if (cls == Object.class) {
             return "::java::lang::_Object";
-        if (cls == java.lang.Class.class)
+        }
+        if (cls == Class.class) {
             return "::javax::rmi::CORBA::ClassDesc";
-        if (cls == java.io.Serializable.class)
+        }
+        if (cls == java.io.Serializable.class) {
             return "::java::io::Serializable";
-        if (cls == java.io.Externalizable.class)
+        }
+        if (cls == java.io.Externalizable.class) {
             return "::java::io::Externalizable";
-        if (cls == java.rmi.Remote.class)
+        }
+        if (cls == java.rmi.Remote.class) {
             return "::java::rmi::Remote";
-        if (cls == org.omg.CORBA.Object.class)
+        }
+        if (cls == org.omg.CORBA.Object.class) {
             return "::CORBA::Object";
+        }
         // remote interface?
         if (cls.isInterface() && java.rmi.Remote.class.isAssignableFrom(cls)) {
             InterfaceType ia = InterfaceType.getInterfaceType(cls);
@@ -102,7 +140,7 @@
         }
         // exception?
         if (Throwable.class.isAssignableFrom(cls)) {
-            if (Exception.class.isAssignableFrom(cls) && !RuntimeException.class.isAssignableFrom(cls)) {
+            if (Exception.class.isAssignableFrom(cls) && !AssertionError.class.isAssignableFrom(cls)) {
                 ExceptionType ea = ExceptionType.getExceptionType(cls);
                 return ea.getIDLModuleName() + "::" + ea.getIDLName();
             }
@@ -117,13 +155,16 @@
      * either throw an exception or return true.
      */
     public static boolean isValidRMIIIOP(Class cls) {
-        if (cls.isPrimitive())
+        if (cls.isPrimitive()) {
             return true;
-        if (cls.isArray())
+        }
+        if (cls.isArray()) {
             return isValidRMIIIOP(cls.getComponentType());
+        }
         // special interfaces
-        if (cls == Serializable.class || cls == Externalizable.class)
+        if (cls == Serializable.class || cls == Externalizable.class) {
             return true;
+        }
         // interface?
         if (cls.isInterface() && Remote.class.isAssignableFrom(cls)) {
             InterfaceType.getInterfaceType(cls);
@@ -131,14 +172,15 @@
         }
         // exception?
         if (Throwable.class.isAssignableFrom(cls)) {
-            if (Exception.class.isAssignableFrom(cls) && (!RuntimeException.class.isAssignableFrom(cls))) {
+            if (Exception.class.isAssignableFrom(cls) && (!AssertionError.class.isAssignableFrom(cls))) {
                 ExceptionType.getExceptionType(cls);
             }
             return true;
         }
         // special values
-        if (cls == Object.class || cls == String.class || cls == Class.class)
+        if (cls == Object.class || cls == String.class || cls == Class.class) {
             return true;
+        }
         // got to be value
         ValueType.getValueType(cls);
         return true;
@@ -150,24 +192,25 @@
      */
     public static void insertAnyPrimitive(Any any, Object primitive) {
         Class type = primitive.getClass();
-        if (type == Boolean.class)
+        if (type == Boolean.class) {
             any.insert_boolean(((Boolean)primitive).booleanValue());
-        else if (type == Character.class)
+        } else if (type == Character.class) {
             any.insert_wchar(((Character)primitive).charValue());
-        else if (type == Byte.class)
+        } else if (type == Byte.class) {
             any.insert_octet(((Byte)primitive).byteValue());
-        else if (type == Short.class)
+        } else if (type == Short.class) {
             any.insert_short(((Short)primitive).shortValue());
-        else if (type == Integer.class)
+        } else if (type == Integer.class) {
             any.insert_long(((Integer)primitive).intValue());
-        else if (type == Long.class)
+        } else if (type == Long.class) {
             any.insert_longlong(((Long)primitive).longValue());
-        else if (type == Float.class)
+        } else if (type == Float.class) {
             any.insert_float(((Float)primitive).floatValue());
-        else if (type == Double.class)
+        } else if (type == Double.class) {
             any.insert_double(((Double)primitive).doubleValue());
-        else
+        } else {
             throw new IllegalArgumentException(type.getName() + "is not a primitive type");
+        }
     }
 
     /**
@@ -175,26 +218,31 @@
      * This only works for a single name component, without a qualifying dot.
      */
     public static String javaToIDLName(String name) {
-        if (name == null || "".equals(name))
+        if (name == null || "".equals(name)) {
             throw new IllegalArgumentException("Illegal name: " + name);
-        if (name.indexOf('.') != -1)
+        }
+        if (name.indexOf('.') != -1) {
             throw new IllegalArgumentException("Qualified name is not supported: " + name);
+        }
         StringBuffer res = new StringBuffer(name.length());
-        if (name.charAt(0) == '_')
+        if (name.charAt(0) == '_') {
             res.append('J'); // 1.3.2.3
+        }
         for (int i = 0; i < name.length(); ++i) {
             char c = name.charAt(i);
-            if (isLegalIDLIdentifierChar(c))
+            if (isLegalIDLIdentifierChar(c)) {
                 res.append(c);
-            else
+            } else {
                 // 1.3.2.4
                 res.append('U').append(toHexString((int)c));
+            }
         }
         String s = res.toString();
-        if (isReservedIDLKeyword(s))
+        if (isReservedIDLKeyword(s)) {
             return "_" + s;
-        else
+        } else {
             return s;
+        }
     }
 
     /**
@@ -202,27 +250,31 @@
      * described in section 1.3.5.7.
      */
     public static String getIRIdentifier(Class cls) {
-        if (cls.isPrimitive())
+        if (cls.isPrimitive()) {
             throw new IllegalArgumentException("Primitive type doesn't have IR IDs.");
+        }
         String result = (String)classIRIdentifierCache.get(cls);
-        if (result != null)
+        if (result != null) {
             return result;
+        }
         String name = cls.getName();
         StringBuffer b = new StringBuffer("RMI:");
         for (int i = 0; i < name.length(); ++i) {
             char c = name.charAt(i);
-            if (c < 256)
+            if (c < 256) {
                 b.append(c);
-            else
+            } else {
                 b.append("\\U").append(toHexString((int)c));
+            }
         }
         long clsHash = getClassHashCode(cls);
         b.append(':').append(toHexString(clsHash));
         ObjectStreamClass osClass = ObjectStreamClass.lookup(cls);
         if (osClass != null) {
             long serialVersionUID = osClass.getSerialVersionUID();
-            if (clsHash != serialVersionUID)
+            if (clsHash != serialVersionUID) {
                 b.append(':').append(toHexString(serialVersionUID));
+            }
         }
         result = b.toString();
         classIRIdentifierCache.put(cls, result);
@@ -230,78 +282,52 @@
     }
 
     /**
-     * A cache for calculated class hash codes.
-     */
-    private static Map classHashCodeCache = Collections.synchronizedMap(new WeakHashMap());
-    /**
-     * A cache for class IR identifiers.
-     */
-    private static Map classIRIdentifierCache = Collections.synchronizedMap(new WeakHashMap());
-    /**
-     * Reserved IDL keywords. Section 1.3.2.2 says that Java identifiers with
-     * these names should have prepended an underscore.
-     */
-
-    private static final Set reservedIDLKeywordSet = new HashSet();
-    static {
-        String[] reservedIDLKeywords = new String[] {"abstract", "any", "attribute", "boolean", "case", "char",
-                                                     "const", "context", "custom", "default", "double", "exception",
-                                                     "enum", "factory", "FALSE", "fixed", "float", "in", "inout",
-                                                     "interface", "local", "long", "module", "native", "Object",
-                                                     "octet", "oneway", "out", "private", "public", "raises",
-                                                     "readonly", "sequence", "short", "string", "struct", "supports",
-                                                     "switch", "TRUE", "truncatable", "typedef", "unsigned", "union",
-                                                     "ValueBase", "valuetype", "void", "wchar", "wstring"};
-        for (int i = 0; i < reservedIDLKeywords.length; i++)
-            reservedIDLKeywordSet.add(reservedIDLKeywords[i]);
-    }
-
-    /**
      * Convert an integer to a 16-digit hex string.
      */
-    private static String toHexString(int i) {
+    public static String toHexString(int i) {
         String s = Integer.toHexString(i).toUpperCase();
-        if (s.length() < 8)
+        if (s.length() < 8) {
             return "00000000".substring(8 - s.length()) + s;
-        else
+        } else {
             return s;
+        }
     }
 
     /**
      * Convert a long to a 16-digit hex string.
      */
-    private static String toHexString(long l) {
+    public static String toHexString(long l) {
         String s = Long.toHexString(l).toUpperCase();
-        if (s.length() < 16)
+        if (s.length() < 16) {
             return "0000000000000000".substring(16 - s.length()) + s;
-        else
+        } else {
             return s;
+        }
     }
 
     /**
      * Determine if the argument is a reserved IDL keyword.
      */
-    private static boolean isReservedIDLKeyword(String s) {
-        return reservedIDLKeywordSet.contains(s);
-        /*
-         * // TODO: faster lookup for (int i = 0; i <
-         * reservedIDLKeywords.length; ++i) if
-         * (reservedIDLKeywords[i].equals(s)) return true; return false;
-         */
+    public static boolean isReservedIDLKeyword(String s) {
+        return KEYWORDS.contains(s);
     }
 
     /**
      * Determine if a <code>char</code> is a legal IDL identifier character.
      */
     private static boolean isLegalIDLIdentifierChar(char c) {
-        if (c >= 0x61 && c <= 0x7a)
+        if (c >= 'a' && c <= 'z') {
             return true; // lower case letter
-        if (c >= 0x30 && c <= 0x39)
+        }
+        if (c >= '0' && c <= '9') {
             return true; // digit
-        if (c >= 0x41 && c <= 0x5a)
+        }
+        if (c >= 'A' && c <= 'Z') {
             return true; // upper case letter
-        if (c == '_')
+        }
+        if (c == '_') {
             return true; // underscore
+        }
         return false;
     }
 
@@ -311,16 +337,20 @@
      */
     static long getClassHashCode(Class cls) {
         // The simple cases
-        if (cls.isInterface())
+        if (cls.isInterface()) {
             return 0;
-        if (!Serializable.class.isAssignableFrom(cls))
+        }
+        if (!Serializable.class.isAssignableFrom(cls)) {
             return 0;
-        if (Externalizable.class.isAssignableFrom(cls))
+        }
+        if (Externalizable.class.isAssignableFrom(cls)) {
             return 1;
+        }
         // Try cache
         Long l = (Long)classHashCodeCache.get(cls);
-        if (l != null)
+        if (l != null) {
             return l.longValue();
+        }
         // Has to calculate the hash.
         ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
         DataOutputStream dos = new DataOutputStream(baos);
@@ -330,7 +360,7 @@
             try {
                 dos.writeLong(getClassHashCode(superClass));
             } catch (IOException ex) {
-                throw new RuntimeException("Unexpected IOException: " + ex);
+                throw new AssertionError(ex);
             }
         }
         // Step 2
@@ -340,23 +370,25 @@
             int mods;
             m = cls.getDeclaredMethod("writeObject", new Class[] {ObjectOutputStream.class});
             mods = m.getModifiers();
-            if (!Modifier.isPrivate(mods) && !Modifier.isStatic(mods))
+            if (!Modifier.isPrivate(mods) && !Modifier.isStatic(mods)) {
                 hasWriteObject = true;
+            }
         } catch (NoSuchMethodException ex) {
             // ignore
         }
         try {
             dos.writeInt(hasWriteObject ? 2 : 1);
         } catch (IOException ex) {
-            throw new RuntimeException("Unexpected IOException: " + ex);
+            throw new AssertionError(ex);
         }
         // Step 3
         Field[] fields = cls.getDeclaredFields();
-        SortedSet set = new TreeSet(new FieldComparator());
+        SortedSet<Field> set = new TreeSet<Field>(new FieldComparator());
         for (int i = 0; i < fields.length; ++i) {
             int mods = fields[i].getModifiers();
-            if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods))
+            if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods)) {
                 set.add(fields[i]);
+            }
         }
         Iterator iter = set.iterator();
         try {
@@ -366,13 +398,13 @@
                 dos.writeUTF(getSignature(f.getType()));
             }
         } catch (IOException ex) {
-            throw new RuntimeException("Unexpected IOException: " + ex);
+            throw new AssertionError(ex);
         }
         // Convert to byte[]
         try {
             dos.flush();
         } catch (IOException ex) {
-            throw new RuntimeException("Unexpected IOException: " + ex);
+            throw new AssertionError(ex);
         }
         byte[] bytes = baos.toByteArray();
         // Calculate SHA digest
@@ -380,7 +412,7 @@
         try {
             digest = MessageDigest.getInstance("SHA");
         } catch (NoSuchAlgorithmException ex) {
-            throw new RuntimeException("No SHA MEssageDigest: " + ex);
+            throw new AssertionError(ex);
         }
         digest.update(bytes);
         byte[] sha = digest.digest();
@@ -399,26 +431,35 @@
      * specification, section 4.3.2.
      */
     private static String getSignature(Class cls) {
-        if (cls.isArray())
+        if (cls.isArray()) {
             return "[" + cls.getComponentType();
+        }
         if (cls.isPrimitive()) {
-            if (cls == Byte.TYPE)
+            if (cls == Byte.TYPE) {
                 return "B";
-            if (cls == Character.TYPE)
+            }
+            if (cls == Character.TYPE) {
                 return "C";
-            if (cls == Double.TYPE)
+            }
+            if (cls == Double.TYPE) {
                 return "D";
-            if (cls == Float.TYPE)
+            }
+            if (cls == Float.TYPE) {
                 return "F";
-            if (cls == Integer.TYPE)
+            }
+            if (cls == Integer.TYPE) {
                 return "I";
-            if (cls == Long.TYPE)
+            }
+            if (cls == Long.TYPE) {
                 return "J";
-            if (cls == Short.TYPE)
+            }
+            if (cls == Short.TYPE) {
                 return "S";
-            if (cls == Boolean.TYPE)
+            }
+            if (cls == Boolean.TYPE) {
                 return "Z";
-            throw new RuntimeException("Unknown primitive class.");
+            }
+            throw new IllegalArgumentException("Unknown primitive class.");
         }
         return "L" + cls.getName().replace('.', '/') + ";";
     }
@@ -426,36 +467,42 @@
     /**
      * Handle mappings for primitive types, as per section 1.3.3.
      */
-    static String primitiveTypeIDLName(Class type) {
-        if (type == Void.TYPE)
+    static String getIDLNameForPrimitives(Class type) {
+        if (type == Void.TYPE) {
             return "void";
-        if (type == Boolean.TYPE)
+        }
+        if (type == Boolean.TYPE) {
             return "boolean";
-        if (type == Character.TYPE)
+        }
+        if (type == Character.TYPE) {
             return "wchar";
-        if (type == Byte.TYPE)
+        }
+        if (type == Byte.TYPE) {
             return "octet";
-        if (type == Short.TYPE)
+        }
+        if (type == Short.TYPE) {
             return "short";
-        if (type == Integer.TYPE)
+        }
+        if (type == Integer.TYPE) {
             return "long";
-        if (type == Long.TYPE)
+        }
+        if (type == Long.TYPE) {
             return "long long";
-        if (type == Float.TYPE)
+        }
+        if (type == Float.TYPE) {
             return "float";
-        if (type == Double.TYPE)
+        }
+        if (type == Double.TYPE) {
             return "double";
+        }
         throw new IllegalArgumentException(type + "is not a primitive type.");
     }
 
-    /**
-     * A <code>Comparator</code> for <code>Field</code>s, ordering the
-     * fields according to the lexicographic ordering of their Java names.
-     */
     private static class FieldComparator implements Comparator {
         public int compare(Object o1, Object o2) {
-            if (o1 == o2)
+            if (o1 == o2) {
                 return 0;
+            }
             String n1 = ((Field)o1).getName();
             String n2 = ((Field)o2).getName();
             return n1.compareTo(n2);

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java Mon Jul  9 11:08:19 2007
@@ -20,6 +20,7 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -27,29 +28,34 @@
  * Mapping Specification", version 1.1 (01-06-07).
  */
 public class InterfaceType extends ContainerType {
-
     private boolean abstractInterface;
     private String[] typeIDs;
 
     /**
      * Map of IDL operation names to operation parses.
      */
-    private Map operationTypeMap;
-
-    private static WorkCache cache = new WorkCache(InterfaceType.class);
-
-    public static InterfaceType getInterfaceType(Class cls) {
-        return (InterfaceType)cache.getType(cls);
-    }
+    private Map<String, OperationType> operationTypeMap;
 
     protected InterfaceType(Class cls) {
         super(cls);
     }
 
+    public static InterfaceType getInterfaceType(Class cls) {
+        InterfaceType type = (InterfaceType)PARSED_TYPES.get(cls);
+        if (type != null) {
+            return type;
+        }
+        type = new InterfaceType(cls);
+        type.parse();
+        PARSED_TYPES.put(cls, type);
+        return type;
+    }
+
     protected void parse() {
         super.parse();
-        if (!javaClass.isInterface())
+        if (!javaClass.isInterface()) {
             throw new IllegalArgumentException("Class [" + javaClass.getName() + "] is not an interface.");
+        }
         abstractInterface = Java2IDLUtil.isAbstractInterface(javaClass);
         calculateOperationTypeMap();
         calculateAllTypeIds();
@@ -61,7 +67,7 @@
     }
 
     private boolean isRemoteInterface() {
-        return (!abstractInterface);
+        return !abstractInterface;
     }
 
     public String[] getTypeIDs() {
@@ -74,14 +80,17 @@
      * @param entries The list of entries contained here. Entries in this list
      *            are subclasses of <code>AbstractType</code>.
      */
-    protected ArrayList getContainedEntries() {
-        ArrayList ret = new ArrayList(constants.length + attributes.length + operations.length);
-        for (int i = 0; i < constants.length; ++i)
+    protected List<IDLType> getContainedEntries() {
+        List<IDLType> ret = new ArrayList<IDLType>(constants.length + attributes.length + operations.length);
+        for (int i = 0; i < constants.length; ++i) {
             ret.add(constants[i]);
-        for (int i = 0; i < attributes.length; ++i)
+        }
+        for (int i = 0; i < attributes.length; ++i) {
             ret.add(attributes[i]);
-        for (int i = 0; i < operations.length; ++i)
+        }
+        for (int i = 0; i < operations.length; ++i) {
             ret.add(operations[i]);
+        }
         return ret;
     }
 
@@ -91,13 +100,15 @@
      */
     protected void parseOperations() {
         int operationCount = 0;
-        for (int i = 0; i < methods.length; ++i)
-            if ((m_flags[i] & (M_READ | M_WRITE | M_READONLY)) == 0)
+        for (int i = 0; i < methods.length; ++i) {
+            if ((mutatorFlags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) {
                 ++operationCount;
+            }
+        }
         operations = new OperationType[operationCount];
         operationCount = 0;
         for (int i = 0; i < methods.length; ++i) {
-            if ((m_flags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) {
+            if ((mutatorFlags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) {
                 operations[operationCount] = new OperationType(methods[i]);
                 ++operationCount;
             }
@@ -110,7 +121,7 @@
      * and mutator operations.
      */
     protected void calculateOperationTypeMap() {
-        operationTypeMap = new HashMap();
+        operationTypeMap = new HashMap<String, OperationType>();
         OperationType oa;
         // Map the operations
         for (int i = 0; i < operations.length; ++i) {

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java Mon Jul  9 11:08:19 2007
@@ -24,29 +24,29 @@
 /**
  * Type class for primitive types.
  */
-public class PrimitiveType extends ClassType {
+public final class PrimitiveType extends ClassType {
 
-    public final static PrimitiveType voidType = new PrimitiveType(void.class, "void", "void");
-    public final static PrimitiveType booleanType = new PrimitiveType(boolean.class, "boolean", "boolean");
-    public final static PrimitiveType charType = new PrimitiveType(char.class, "wchar", "char");
-    public final static PrimitiveType byteType = new PrimitiveType(byte.class, "octet", "byte");
-    public final static PrimitiveType shortType = new PrimitiveType(short.class, "short", "short");
-    public final static PrimitiveType intType = new PrimitiveType(int.class, "long", "int");
-    public final static PrimitiveType longType = new PrimitiveType(long.class, "long_long", "long");
-    public final static PrimitiveType floatType = new PrimitiveType(float.class, "float", "float");
-    public final static PrimitiveType doubleType = new PrimitiveType(double.class, "double", "double");
+    public static final PrimitiveType VOID_TYPE = new PrimitiveType(void.class, "void", "void");
+    public static final PrimitiveType BOOLEAN_TYPE = new PrimitiveType(boolean.class, "boolean", "boolean");
+    public static final PrimitiveType CHAR_TYPE = new PrimitiveType(char.class, "wchar", "char");
+    public static final PrimitiveType BYTE_TYPE = new PrimitiveType(byte.class, "octet", "byte");
+    public static final PrimitiveType SHORT_TYPE = new PrimitiveType(short.class, "short", "short");
+    public static final PrimitiveType INT_TYPE = new PrimitiveType(int.class, "long", "int");
+    public static final PrimitiveType LONG_TYPE = new PrimitiveType(long.class, "long_long", "long");
+    public static final PrimitiveType FLOAT_TYPE = new PrimitiveType(float.class, "float", "float");
+    public static final PrimitiveType DOUBLE_TYPE = new PrimitiveType(double.class, "double", "double");
 
-    private final static Map types = new HashMap();
+    private static final Map<Class, PrimitiveType> TYPES = new HashMap<Class, PrimitiveType>();
     static {
-        types.put(void.class, voidType);
-        types.put(boolean.class, booleanType);
-        types.put(byte.class, byteType);
-        types.put(char.class, charType);
-        types.put(short.class, shortType);
-        types.put(int.class, intType);
-        types.put(long.class, longType);
-        types.put(float.class, floatType);
-        types.put(double.class, doubleType);
+        TYPES.put(void.class, VOID_TYPE);
+        TYPES.put(boolean.class, BOOLEAN_TYPE);
+        TYPES.put(byte.class, BYTE_TYPE);
+        TYPES.put(char.class, CHAR_TYPE);
+        TYPES.put(short.class, SHORT_TYPE);
+        TYPES.put(int.class, INT_TYPE);
+        TYPES.put(long.class, LONG_TYPE);
+        TYPES.put(float.class, FLOAT_TYPE);
+        TYPES.put(double.class, DOUBLE_TYPE);
     }
 
     private PrimitiveType(Class cls, String idlName, String javaName) {
@@ -56,10 +56,11 @@
     /**
      * Get a singleton instance representing one of the peimitive types.
      */
-    public final static PrimitiveType getPrimitiveType(Class cls) {
-        PrimitiveType type = (PrimitiveType)types.get(cls);
-        if (type == null)
+    public static PrimitiveType getPrimitiveType(final Class cls) {
+        final PrimitiveType type = TYPES.get(cls);
+        if (type == null) {
             throw new IllegalArgumentException(cls + " is not a primitive type");
+        }    
         return type;
     }
 

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java Mon Jul  9 11:08:19 2007
@@ -26,11 +26,11 @@
     /**
      * Java type.
      */
-    private Class javaClass;
+    private final Class javaClass;
     /**
      * Flags that this member is public.
      */
-    private boolean isPublic;
+    private final boolean isPublic;
 
     ValueMemberType(String javaName, Class cls, boolean isPublic) {
         super(javaName);

Modified: incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java?view=diff&rev=554723&r1=554722&r2=554723
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java Mon Jul  9 11:08:19 2007
@@ -27,6 +27,7 @@
 import java.rmi.Remote;
 import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -36,54 +37,139 @@
  * Value Type.
  */
 public class ValueType extends ContainerType {
-
-    private static WorkCache cache = new WorkCache(ValueType.class);
-
-    /**
-     * Type of our superclass, of null if our superclass is java.lang.Object.
-     */
-    ValueType superType;
+    private ValueType superType;
     /**
      * Flags that this is an abstract value.
      */
-    private boolean abstractValue = false;
+    private boolean abstractValue;
     /**
      * Flags that this implements <code>java.io.Externalizable</code>.
      */
-    private boolean externalizable = false;
+    private boolean externalizable;
     /**
      * Flags that this has a <code>writeObject()</code> method.
      */
-    private boolean hasWriteObjectMethod = false;
+    private boolean hasWriteObjectMethod;
+    /**
+     * The value members of this value class.
+     */
+    private ValueMemberType[] members;
+
     /**
      * The <code>serialPersistentFields of the value, or <code>null</code>
      *  if the value does not have this field.
      */
     private ObjectStreamField[] serialPersistentFields;
+
     /**
-     * The value members of this value class.
+     * Type of our superclass, of null if our superclass is java.lang.Object.
      */
-    private ValueMemberType[] members;
+    protected ValueType(Class cls) {
+        super(cls);
+    }
+
+    /**
+     * A <code>Comparator</code> for the field ordering specified at the end
+     * of section 1.3.5.6.
+     */
+    private static class ValueMemberComparator implements Comparator<ValueMemberType> {
+        public int compare(ValueMemberType m1, ValueMemberType m2) {
+            if (m1 == m2) {
+                return 0;
+            }
+            boolean p1 = m1.getJavaClass().isPrimitive();
+            boolean p2 = m2.getJavaClass().isPrimitive();
+            if (p1 && !p2) {
+                return -1;
+            }
+            if (!p1 && p2) {
+                return 1;
+            }
+            return m1.getJavaName().compareTo(m2.getJavaName());
+        }
+    }
 
     public static ValueType getValueType(Class cls) {
-        return (ValueType)cache.getType(cls);
+        ValueType type = (ValueType)PARSED_TYPES.get(cls);
+        if (type != null) {
+            return type;
+        }
+        type = new ValueType(cls);
+        type.parse();
+        return type;
     }
 
-    protected ValueType(Class cls) {
-        super(cls);
+    /**
+     * Return a list of all the entries contained here.
+     * 
+     * @param entries The list of entries contained here. Entries in this list
+     *            are subclasses of <code>IDLType</code>.
+     */
+    protected List<IDLType> getContainedEntries() {
+        List<IDLType> ret = new ArrayList<IDLType>(constants.length + attributes.length + members.length);
+        for (int i = 0; i < constants.length; ++i) {
+            ret.add(constants[i]);
+        }
+        for (int i = 0; i < attributes.length; ++i) {
+            ret.add(attributes[i]);
+        }
+        for (int i = 0; i < members.length; ++i) {
+            ret.add(members[i]);
+        }
+        return ret;
+    }
+
+    /**
+     * Return the value members of this value class.
+     */
+    public ValueMemberType[] getMembers() {
+        return (ValueMemberType[])members.clone();
+    }
+
+    /**
+     * Returns the superclass analysis, or null if this inherits from
+     * java.lang.Object.
+     */
+    public ValueType getSuperType() {
+        return superType;
+    }
+
+    /**
+     * Returns true if this value is abstract.
+     */
+    public boolean isAbstractValue() {
+        return abstractValue;
+    }
+
+    /**
+     * Returns true if this value is custom.
+     */
+    public boolean isCustom() {
+        return externalizable || hasWriteObjectMethod;
+    }
+
+    /**
+     * Returns true if this value implements java.io.Externalizable.
+     */
+    public boolean isExternalizable() {
+        return externalizable;
     }
 
     protected void parse() {
         super.parse();
-        if (javaClass == String.class)
+        if (javaClass == String.class) {
             throw new IllegalArgumentException("Cannot parse java.lang.String here: It is a " + "special case."); // 1.3.5.11
-        if (javaClass == Class.class)
+        }
+        if (javaClass == Class.class) {
             throw new IllegalArgumentException("Cannot parse java.lang.Class here: It is a " + "special case."); // 1.3.5.10
-        if (Remote.class.isAssignableFrom(javaClass))
+        }
+        if (Remote.class.isAssignableFrom(javaClass)) {
             throw new IDLViolationException("Value type " + javaClass.getName() + " cannot implement java.rmi.Remote.",
                                             "1.2.4");
-        if (javaClass.getName().indexOf('$') != -1)
+        }
+        if (javaClass.getName().indexOf('$') != -1) {
             throw new ServiceRuntimeException(javaClass.getName() + " is not supported (proxy or inner classes).");
+        }
         externalizable = Externalizable.class.isAssignableFrom(javaClass);
         if (!externalizable) {
             // Look for serialPersistentFields field.
@@ -95,17 +181,20 @@
             }
             if (spf != null) { // Right modifiers?
                 int mods = spf.getModifiers();
-                if (!Modifier.isFinal(mods) || !Modifier.isStatic(mods) || !Modifier.isPrivate(mods))
+                if (!Modifier.isFinal(mods) || !Modifier.isStatic(mods) || !Modifier.isPrivate(mods)) {
                     spf = null; // wrong modifiers
+                }
             }
             if (spf != null) { // Right type?
                 Class type = spf.getType();
                 if (type.isArray()) {
                     type = type.getComponentType();
-                    if (type != ObjectStreamField.class)
+                    if (type != ObjectStreamField.class) {
                         spf = null; // Array of wrong type
-                } else
+                    }
+                } else {
                     spf = null; // Wrong type: Not an array
+                }
             }
             if (spf != null) {
                 // We have the serialPersistentFields field
@@ -113,12 +202,12 @@
                 try {
                     serialPersistentFields = (ObjectStreamField[])spf.get(null);
                 } catch (IllegalAccessException ex) {
-                    throw new RuntimeException("Unexpected IllegalException: " + ex.toString());
+                    throw new AssertionError("Unexpected IllegalException: " + ex.toString());
                 }
                 // Mark this in the fields array
                 for (int i = 0; i < fields.length; ++i) {
                     if (fields[i] == spf) {
-                        f_flags[i] |= F_SPFFIELD;
+                        fieldFlags[i] |= F_SPFFIELD;
                         break;
                     }
                 }
@@ -131,20 +220,23 @@
                 // ignore
             }
             if (wo != null) { // Right return type?
-                if (wo.getReturnType() != Void.TYPE)
+                if (wo.getReturnType() != Void.TYPE) {
                     wo = null; // Wrong return type
+                }
             }
             if (wo != null) { // Right modifiers?
                 int mods = spf.getModifiers();
-                if (!Modifier.isPrivate(mods))
+                if (!Modifier.isPrivate(mods)) {
                     wo = null; // wrong modifiers
+                }
             }
             if (wo != null) { // Right arguments?
                 Class[] paramTypes = wo.getParameterTypes();
-                if (paramTypes.length != 1)
+                if (paramTypes.length != 1) {
                     wo = null; // Bad number of parameters
-                else if (paramTypes[0] != java.io.OutputStream.class)
+                } else if (paramTypes[0] != java.io.OutputStream.class) {
                     wo = null; // Bad parameter type
+                }
             }
             if (wo != null) {
                 // We have the writeObject() method.
@@ -152,77 +244,45 @@
                 // Mark this in the methods array
                 for (int i = 0; i < methods.length; ++i) {
                     if (methods[i] == wo) {
-                        m_flags[i] |= M_WRITEOBJECT;
+                        mutatorFlags[i] |= M_WRITEOBJECT;
                         break;
                     }
                 }
             }
         }
         // Map all fields not flagged constant or serialPersistentField.
-        SortedSet m = new TreeSet(new ValueMemberComparator());
+        SortedSet<ValueMemberType> m = new TreeSet<ValueMemberType>(new ValueMemberComparator());
         for (int i = 0; i < fields.length; ++i) {
-            if (f_flags[i] != 0)
+            if (fieldFlags[i] != 0) {
                 continue; // flagged
+            }
             int mods = fields[i].getModifiers();
-            if (Modifier.isStatic(mods) || Modifier.isTransient(mods))
+            if (Modifier.isStatic(mods) || Modifier.isTransient(mods)) {
                 continue; // don't map this
+            }
             ValueMemberType vma =
                 new ValueMemberType(fields[i].getName(), fields[i].getType(), Modifier.isPublic(mods));
             m.add(vma);
         }
         members = new ValueMemberType[m.size()];
-        members = (ValueMemberType[])m.toArray(members);
+        members = m.toArray(members);
         // Get superclass analysis
         Class superClass = javaClass.getSuperclass();
-        if (superClass == java.lang.Object.class)
+        if (superClass == java.lang.Object.class) {
             superClass = null;
-        if (superClass == null)
+        }
+        if (superClass == null) {
             superType = null;
-        else {
+        } else {
             superType = getValueType(superClass);
         }
-        if (!Serializable.class.isAssignableFrom(javaClass))
+        if (!Serializable.class.isAssignableFrom(javaClass)) {
             abstractValue = true;
+        }
         fixupCaseNames();
     }
 
     /**
-     * Returns the superclass analysis, or null if this inherits from
-     * java.lang.Object.
-     */
-    public ValueType getSuperType() {
-        return superType;
-    }
-
-    /**
-     * Returns true if this value is abstract.
-     */
-    public boolean isAbstractValue() {
-        return abstractValue;
-    }
-
-    /**
-     * Returns true if this value is custom.
-     */
-    public boolean isCustom() {
-        return externalizable || hasWriteObjectMethod;
-    }
-
-    /**
-     * Returns true if this value implements java.io.Externalizable.
-     */
-    public boolean isExternalizable() {
-        return externalizable;
-    }
-
-    /**
-     * Return the value members of this value class.
-     */
-    public ValueMemberType[] getMembers() {
-        return (ValueMemberType[])members.clone();
-    }
-
-    /**
      * Analyse attributes. This will fill in the <code>attributes</code>
      * array. Here we override the implementation in ContainerType and create an
      * empty array, because for valuetypes we don't want to parse IDL attributes
@@ -230,42 +290,5 @@
      */
     protected void parseAttributes() {
         attributes = new AttributeType[0];
-    }
-
-    /**
-     * Return a list of all the entries contained here.
-     * 
-     * @param entries The list of entries contained here. Entries in this list
-     *            are subclasses of <code>AbstractType</code>.
-     */
-    protected ArrayList getContainedEntries() {
-        ArrayList ret = new ArrayList(constants.length + attributes.length + members.length);
-        for (int i = 0; i < constants.length; ++i)
-            ret.add(constants[i]);
-        for (int i = 0; i < attributes.length; ++i)
-            ret.add(attributes[i]);
-        for (int i = 0; i < members.length; ++i)
-            ret.add(members[i]);
-        return ret;
-    }
-
-    /**
-     * A <code>Comparator</code> for the field ordering specified at the end
-     * of section 1.3.5.6.
-     */
-    private static class ValueMemberComparator implements Comparator {
-        public int compare(Object o1, Object o2) {
-            if (o1 == o2)
-                return 0;
-            ValueMemberType m1 = (ValueMemberType)o1;
-            ValueMemberType m2 = (ValueMemberType)o2;
-            boolean p1 = m1.getJavaClass().isPrimitive();
-            boolean p2 = m2.getJavaClass().isPrimitive();
-            if (p1 && !p2)
-                return -1;
-            if (!p1 && p2)
-                return 1;
-            return m1.getJavaName().compareTo(m2.getJavaName());
-        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org