dain 2005/07/13 16:49:29
Modified: modules/core/src/java/org/openejb/corba/util
DynamicStubClassLoader.java
StubMethodInterceptor.java Util.java
Removed: modules/core/src/java/org/openejb/corba/util
ClasspathTieLoader.java OpenORBStubClassLoader.java
TieLoader.java
Log:
Removed openorb/tmporb
Removed tools jar hack
Removed all stub/tie compiler code since is used openorb
Revision Changes Path
1.5 +4 -16
openejb/modules/core/src/java/org/openejb/corba/util/DynamicStubClassLoader.java
Index: DynamicStubClassLoader.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/DynamicStubClassLoader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DynamicStubClassLoader.java 24 Jun 2005 07:54:14 -0000 1.4
+++ DynamicStubClassLoader.java 13 Jul 2005 20:49:28 -0000 1.5
@@ -46,10 +46,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.rmi.Remote;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
import net.sf.cglib.core.NamingPolicy;
import net.sf.cglib.core.Predicate;
@@ -65,7 +61,6 @@
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.openejb.corba.compiler.PortableStubCompiler;
/**
@@ -79,7 +74,7 @@
public synchronized Class loadClass(final String name) throws
ClassNotFoundException {
if (stopped) {
- throw new ClassNotFoundException("OpenORBStubClassLoader is
stopped");
+ throw new ClassNotFoundException("DynamicStubClassLoader is
stopped");
}
if (log.isDebugEnabled()) {
@@ -195,14 +190,7 @@
private final String[] typeIds;
public Ids(Class type) {
- List ids = new LinkedList();
- for (Iterator iterator =
PortableStubCompiler.getAllInterfaces(type).iterator(); iterator.hasNext();) {
- Class superInterface = (Class) iterator.next();
- if (Remote.class.isAssignableFrom(superInterface) &&
superInterface != Remote.class) {
- ids.add("RMI:" + superInterface.getName() +
":0000000000000000");
- }
- }
- typeIds = (String[]) ids.toArray(new String[ids.size()]);
+ typeIds = Util.createCorbaIds(type);
}
public Object loadObject() throws Exception {
1.6 +4 -13
openejb/modules/core/src/java/org/openejb/corba/util/StubMethodInterceptor.java
Index: StubMethodInterceptor.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/StubMethodInterceptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StubMethodInterceptor.java 28 Jun 2005 01:47:50 -0000 1.5
+++ StubMethodInterceptor.java 13 Jul 2005 20:49:28 -0000 1.6
@@ -47,10 +47,9 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
-import javax.rmi.CORBA.Util;
import javax.ejb.EJBObject;
+import javax.rmi.CORBA.Util;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@@ -62,8 +61,6 @@
import org.omg.CORBA_2_3.portable.OutputStream;
import org.openejb.corba.ClientContext;
import org.openejb.corba.ClientContextManager;
-import org.openejb.corba.compiler.IiopOperation;
-import org.openejb.corba.compiler.PortableStubCompiler;
/**
* @version $Revision$ $Date$
@@ -83,13 +80,7 @@
public StubMethodInterceptor(Class type) {
this.type = type;
- IiopOperation[] iiopOperations =
PortableStubCompiler.createIiopOperations(type);
- Map operations = new HashMap(iiopOperations.length);
- for (int i = 0; i < iiopOperations.length; i++) {
- IiopOperation iiopOperation = iiopOperations[i];
- operations.put(iiopOperation.getMethod(),
iiopOperation.getName());
- }
- this.operations = Collections.unmodifiableMap(operations);
+ this.operations =
Collections.unmodifiableMap(org.openejb.corba.util.Util.mapMethodToOperation(type));
}
public Object intercept(Object proxy, Method method, Object[] args,
MethodProxy methodProxy) throws Throwable {
1.19 +494 -2
openejb/modules/core/src/java/org/openejb/corba/util/Util.java
Index: Util.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/Util.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Util.java 1 Jul 2005 19:34:36 -0000 1.18
+++ Util.java 13 Jul 2005 20:49:28 -0000 1.19
@@ -55,6 +55,15 @@
import java.rmi.UnexpectedException;
import java.rmi.RemoteException;
import java.lang.reflect.Method;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.HashMap;
+import java.util.HashSet;
import javax.ejb.spi.HandleDelegate;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -70,6 +79,7 @@
import org.omg.CORBA.UserException;
import org.omg.CORBA.portable.ResponseHandler;
import org.omg.CORBA.portable.UnknownException;
+import org.omg.CORBA.portable.IDLEntity;
import org.omg.GSSUP.GSSUPMechOID;
import org.omg.GSSUP.InitialContextToken;
import org.omg.GSSUP.InitialContextTokenHelper;
@@ -105,7 +115,6 @@
private static Codec codec;
private static HandleDelegate handleDelegate;
private static CorbaApplicationServer corbaApplicationServer = new
CorbaApplicationServer();
-
public static ORB getORB() {
assert orb != null;
return orb;
@@ -558,4 +567,487 @@
String exceptionId = "IDL:" + exceptionName + ":1.0";
return exceptionId;
}
+
+ public static String[] createCorbaIds(Class type) {
+ List ids = new LinkedList();
+ for (Iterator iterator = getAllInterfaces(type).iterator();
iterator.hasNext();) {
+ Class superInterface = (Class) iterator.next();
+ if (Remote.class.isAssignableFrom(superInterface) &&
superInterface != Remote.class) {
+ ids.add("RMI:" + superInterface.getName() +
":0000000000000000");
+ }
+ }
+ return (String[]) ids.toArray(new String[ids.size()]);
+ }
+
+ private static Set getAllInterfaces(Class intfClass) {
+ Set allInterfaces = new LinkedHashSet();
+
+ LinkedList stack = new LinkedList();
+ stack.addFirst(intfClass);
+
+ while (!stack.isEmpty()) {
+ Class intf = (Class) stack.removeFirst();
+ allInterfaces.add(intf);
+ stack.addAll(0, Arrays.asList(intf.getInterfaces()));
+ }
+
+ return allInterfaces;
+ }
+
+ public static Map mapMethodToOperation(Class intfClass) {
+ return iiopMap(intfClass, false);
+ }
+
+ public static Map mapOperationToMethod(Class intfClass) {
+ return iiopMap(intfClass, true);
+ }
+
+ private static Map iiopMap(Class intfClass, boolean operationToMethod) {
+ Method[] methods = getAllMethods(intfClass);
+
+ // find every valid getter
+ HashMap getterByMethod = new HashMap(methods.length);
+ HashMap getterByName = new HashMap(methods.length);
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ String methodName = method.getName();
+
+ // no arguments allowed
+ if (method.getParameterTypes().length != 0) {
+ continue;
+ }
+
+ // must start with get or is
+ String verb;
+ if (methodName.startsWith("get") && methodName.length() > 3 &&
method.getReturnType() != void.class) {
+ verb = "get";
+ } else if (methodName.startsWith("is") && methodName.length() >
2 && method.getReturnType() == boolean.class) {
+ verb = "is";
+ } else {
+ continue;
+ }
+
+ // must only throw Remote or Runtime Exceptions
+ boolean exceptionsValid = true;
+ Class[] exceptionTypes = method.getExceptionTypes();
+ for (int j = 0; j < exceptionTypes.length; j++) {
+ Class exceptionType = exceptionTypes[j];
+ if (!RemoteException.class.isAssignableFrom(exceptionType) &&
+
!RuntimeException.class.isAssignableFrom(exceptionType) &&
+ !Error.class.isAssignableFrom(exceptionType)) {
+ exceptionsValid = false;
+ break;
+ }
+ }
+ if (!exceptionsValid) {
+ continue;
+ }
+
+ String propertyName;
+ if (methodName.length() > verb.length() + 1 &&
Character.isUpperCase(methodName.charAt(verb.length() + 1))) {
+ propertyName = methodName.substring(verb.length());
+ } else {
+ propertyName =
Character.toLowerCase(methodName.charAt(verb.length())) +
methodName.substring(verb.length() + 1);
+ }
+ getterByMethod.put(method, propertyName);
+ getterByName.put(propertyName, method);
+ }
+
+ HashMap setterByMethod = new HashMap(methods.length);
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ String methodName = method.getName();
+
+ // must have exactally one arg
+ if (method.getParameterTypes().length != 1) {
+ continue;
+ }
+
+ // must return non void
+ if (method.getReturnType() != void.class) {
+ continue;
+ }
+
+ // must start with set
+ if (!methodName.startsWith("set") || methodName.length() <= 3) {
+ continue;
+ }
+
+ // must only throw Remote or Runtime Exceptions
+ boolean exceptionsValid = true;
+ Class[] exceptionTypes = method.getExceptionTypes();
+ for (int j = 0; j < exceptionTypes.length; j++) {
+ Class exceptionType = exceptionTypes[j];
+ if (!RemoteException.class.isAssignableFrom(exceptionType) &&
+
!RuntimeException.class.isAssignableFrom(exceptionType) &&
+ !Error.class.isAssignableFrom(exceptionType)) {
+ exceptionsValid = false;
+ break;
+ }
+ }
+ if (!exceptionsValid) {
+ continue;
+ }
+
+ String propertyName;
+ if (methodName.length() > 4 &&
Character.isUpperCase(methodName.charAt(4))) {
+ propertyName = methodName.substring(3);
+ } else {
+ propertyName = Character.toLowerCase(methodName.charAt(3)) +
methodName.substring(4);
+ }
+
+ // must have a matching getter
+ Method getter = (Method) getterByName.get(propertyName);
+ if (getter == null) {
+ continue;
+ }
+
+ // setter property must match gettter return value
+ if
(!method.getParameterTypes()[0].equals(getter.getReturnType())) {
+ continue;
+ }
+ setterByMethod.put(method, propertyName);
+ }
+
+ // index the methods by name... used to determine which methods are
overloaded
+ HashMap overloadedMethods = new HashMap(methods.length);
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ if (getterByMethod.containsKey(method) ||
setterByMethod.containsKey(method)) {
+ continue;
+ }
+ String methodName = method.getName();
+ List methodList = (List) overloadedMethods.get(methodName);
+ if (methodList == null) {
+ methodList = new LinkedList();
+ overloadedMethods.put(methodName, methodList);
+ }
+ methodList.add(method);
+ }
+
+ // index the methods by lower case name... used to determine which
methods differ only by case
+ HashMap caseCollisionMethods = new HashMap(methods.length);
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ if (getterByMethod.containsKey(method) ||
setterByMethod.containsKey(method)) {
+ continue;
+ }
+ String lowerCaseMethodName = method.getName().toLowerCase();
+ Set methodSet = (Set)
caseCollisionMethods.get(lowerCaseMethodName);
+ if (methodSet == null) {
+ methodSet = new HashSet();
+ caseCollisionMethods.put(lowerCaseMethodName, methodSet);
+ }
+ methodSet.add(method.getName());
+ }
+
+ String className = getClassName(intfClass);
+ Map iiopMap = new HashMap(methods.length);
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+
+ String iiopName = (String) getterByMethod.get(method);
+ if (iiopName != null) {
+ // if we have a leading underscore prepend with J
+ if (iiopName.charAt(0) == '_') {
+ iiopName = "J_get_" + iiopName.substring(1);
+ } else {
+ iiopName = "_get_" + iiopName;
+ }
+ } else {
+ iiopName = (String) setterByMethod.get(method);
+ if (iiopName != null) {
+ // if we have a leading underscore prepend with J
+ if (iiopName.charAt(0) == '_') {
+ iiopName = "J_set_" + iiopName.substring(1);
+ } else {
+ iiopName = "_set_" + iiopName;
+ }
+ } else {
+ iiopName = method.getName();
+
+ // if we have a leading underscore prepend with J
+ if (iiopName.charAt(0) == '_') {
+ iiopName = "J" + iiopName;
+ }
+ }
+ }
+
+ // if this name only differs by case add the case index to the
end
+ Set caseCollisions = (Set)
caseCollisionMethods.get(method.getName().toLowerCase());
+ if (caseCollisions != null && caseCollisions.size() > 1) {
+ iiopName += upperCaseIndexString(iiopName);
+ }
+
+ // if this is an overloaded method append the parameter string
+ List overloads = (List) overloadedMethods.get(method.getName());
+ if (overloads != null && overloads.size() > 1) {
+ iiopName +=
buildOverloadParameterString(method.getParameterTypes());
+ }
+
+ // if we have a leading underscore prepend with J
+ iiopName = replace(iiopName, '$', "U0024");
+
+ // if we have matched a keyword prepend with an underscore
+ if (keywords.contains(iiopName.toLowerCase())) {
+ iiopName = "_" + iiopName;
+ }
+
+ // if the name is the same as the class name, append an
underscore
+ if (iiopName.equalsIgnoreCase(className)) {
+ iiopName += "_";
+ }
+
+ if (operationToMethod) {
+ iiopMap.put(iiopName, method);
+ } else {
+ iiopMap.put(method, iiopName);
+ }
+ }
+
+ return iiopMap;
+ }
+
+ private static Method[] getAllMethods(Class intfClass) {
+ LinkedList methods = new LinkedList();
+ for (Iterator iterator = getAllInterfaces(intfClass).iterator();
iterator.hasNext();) {
+ Class intf = (Class) iterator.next();
+ methods.addAll(Arrays.asList(intf.getDeclaredMethods()));
+ }
+
+ return (Method[]) methods.toArray(new Method[methods.size()]);
+ }
+
+ /**
+ * Return the a string containing an underscore '_' index of each
uppercase character in the iiop name.
+ *
+ * This is used for distinction of names that only differ by case, since
corba does not support case sensitive names.
+ */
+ private static String upperCaseIndexString(String iiopName) {
+ StringBuffer stringBuffer = new StringBuffer();
+ for (int i = 0; i < iiopName.length(); i++) {
+ char c = iiopName.charAt(i);
+ if (Character.isUpperCase(c)) {
+ stringBuffer.append('_').append(i);
+ }
+ }
+ return stringBuffer.toString();
+ }
+
+ /**
+ * Replaces any occurnace of the specified "oldChar" with the nes string.
+ *
+ * This is used to replace occurances if '$' in corba names since '$' is
a special character
+ */
+ private static String replace(String source, char oldChar, String
newString) {
+ StringBuffer stringBuffer = new StringBuffer(source.length());
+ for (int i = 0; i < source.length(); i++) {
+ char c = source.charAt(i);
+ if (c == oldChar) {
+ stringBuffer.append(newString);
+ } else {
+ stringBuffer.append(c);
+ }
+ }
+ return stringBuffer.toString();
+ }
+
+ /**
+ * Return the a string containing a double underscore '__' list of
parameter types encoded using the Java to IDL rules.
+ *
+ * This is used for distinction of methods that only differ by parameter
lists.
+ */
+ private static String buildOverloadParameterString(Class[]
parameterTypes) {
+ String name = "";
+ if (parameterTypes.length ==0) {
+ name += "__";
+ } else {
+ for (int i = 0; i < parameterTypes.length; i++) {
+ Class parameterType = parameterTypes[i];
+ name += buildOverloadParameterString(parameterType);
+ }
+ }
+ return name.replace('.', '_');
+ }
+
+ /**
+ * Returns a single parameter type encoded using the Java to IDL rules.
+ */
+ private static String buildOverloadParameterString(Class parameterType) {
+ String name = "_";
+
+ int arrayDimensions = 0;
+ while (parameterType.isArray()) {
+ arrayDimensions++;
+ parameterType = parameterType.getComponentType();
+ }
+
+ // arrays start with org_omg_boxedRMI_
+ if (arrayDimensions > 0) {
+ name += "_org_omg_boxedRMI";
+ }
+
+ // IDLEntity types must be prefixed with org_omg_boxedIDL_
+ if (IDLEntity.class.isAssignableFrom(parameterType)) {
+ name += "_org_omg_boxedIDL";
+ }
+
+ // add package... some types have special mappings in corba
+ String packageName = (String)
specialTypePackages.get(parameterType.getName());
+ if (packageName == null) {
+ packageName = getPackageName(parameterType.getName());
+ }
+ if (packageName.length() > 0) {
+ name += "_" + packageName;
+ }
+
+ // arrays now contain a dimension indicator
+ if (arrayDimensions > 0) {
+ name += "_" + "seq" + arrayDimensions;
+ }
+
+ // add the class name
+ String className = (String)
specialTypeNames.get(parameterType.getName());
+ if (className == null) {
+ className = buildClassName(parameterType);
+ }
+ name += "_" + className;
+
+ return name;
+ }
+
+ /**
+ * Returns a string contianing an encoded class name.
+ */
+ private static String buildClassName(Class type) {
+ if (type.isArray()) {
+ throw new IllegalArgumentException("type is an array: " + type);
+ }
+
+ // get the classname
+ String typeName = type.getName();
+ int endIndex = typeName.lastIndexOf('.');
+ if (endIndex < 0) {
+ return typeName;
+ }
+ StringBuffer className = new
StringBuffer(typeName.substring(endIndex + 1));
+
+ // for innerclasses replace the $ separator with two underscores
+ // we can't just blindly replace all $ characters since class names
can contain the $ character
+ if (type.getDeclaringClass() != null) {
+ String declaringClassName =
getClassName(type.getDeclaringClass());
+ assert className.toString().startsWith(declaringClassName + "$");
+ className.replace(declaringClassName.length(),
declaringClassName.length() + 1, "__");
+ }
+
+ // if we have a leading underscore prepend with J
+ if (className.charAt(0) == '_') {
+ className.insert(0, "J");
+ }
+ return className.toString();
+ }
+
+ private static String getClassName(Class type) {
+ if (type.isArray()) {
+ throw new IllegalArgumentException("type is an array: " + type);
+ }
+
+ // get the classname
+ String typeName = type.getName();
+ int endIndex = typeName.lastIndexOf('.');
+ if (endIndex < 0) {
+ return typeName;
+ }
+ return typeName.substring(endIndex + 1);
+ }
+
+ private static String getPackageName(String interfaceName) {
+ int endIndex = interfaceName.lastIndexOf('.');
+ if (endIndex < 0) {
+ return "";
+ }
+ return interfaceName.substring(0, endIndex);
+ }
+
+ private static final Map specialTypeNames;
+ private static final Map specialTypePackages;
+ private static final Set keywords;
+
+ static {
+ specialTypeNames = new HashMap();
+ specialTypeNames.put("boolean", "boolean");
+ specialTypeNames.put("char", "wchar");
+ specialTypeNames.put("byte", "octet");
+ specialTypeNames.put("short", "short");
+ specialTypeNames.put("int", "long");
+ specialTypeNames.put("long", "long_long");
+ specialTypeNames.put("float", "float");
+ specialTypeNames.put("double", "double");
+ specialTypeNames.put("java.lang.Class", "ClassDesc");
+ specialTypeNames.put("java.lang.String", "WStringValue");
+ specialTypeNames.put("org.omg.CORBA.Object", "Object");
+
+ specialTypePackages = new HashMap();
+ specialTypePackages.put("boolean", "");
+ specialTypePackages.put("char", "");
+ specialTypePackages.put("byte", "");
+ specialTypePackages.put("short", "");
+ specialTypePackages.put("int", "");
+ specialTypePackages.put("long", "");
+ specialTypePackages.put("float", "");
+ specialTypePackages.put("double", "");
+ specialTypePackages.put("java.lang.Class", "javax.rmi.CORBA");
+ specialTypePackages.put("java.lang.String", "CORBA");
+ specialTypePackages.put("org.omg.CORBA.Object", "");
+
+ keywords = new HashSet();
+ keywords.add("abstract");
+ keywords.add("any");
+ keywords.add("attribute");
+ keywords.add("boolean");
+ keywords.add("case");
+ keywords.add("char");
+ keywords.add("const");
+ keywords.add("context");
+ keywords.add("custom");
+ keywords.add("default");
+ keywords.add("double");
+ keywords.add("enum");
+ keywords.add("exception");
+ keywords.add("factory");
+ keywords.add("false");
+ keywords.add("fixed");
+ keywords.add("float");
+ keywords.add("in");
+ keywords.add("inout");
+ keywords.add("interface");
+ keywords.add("long");
+ keywords.add("module");
+ keywords.add("native");
+ keywords.add("object");
+ keywords.add("octet");
+ keywords.add("oneway");
+ keywords.add("out");
+ keywords.add("private");
+ keywords.add("public");
+ keywords.add("raises");
+ keywords.add("readonly");
+ keywords.add("sequence");
+ keywords.add("short");
+ keywords.add("string");
+ keywords.add("struct");
+ keywords.add("supports");
+ keywords.add("switch");
+ keywords.add("true");
+ keywords.add("truncatable");
+ keywords.add("typedef");
+ keywords.add("union");
+ keywords.add("unsigned");
+ keywords.add("valuebase");
+ keywords.add("valuetype");
+ keywords.add("void");
+ keywords.add("wchar");
+ keywords.add("wstring");
+ }
+
}