// Generate a static field with the StubStrategy for the method
asm.addField(Modifier.PRIVATE + Modifier.STATIC, strategyField, StubStrategy.class);
// Generate the method code
final CodeAttribute ca = asm.addMethod(m).getCodeAttribute();
// The method code issues a call
// super.invoke*(idlName, strategyField, args)
ca.aload(0);
ca.ldc(idlName);
ca.getstatic(asm.getName(), strategyField, StubStrategy.class);
// Push args
if (paramTypes.length == 0) {
ca.iconst(0);
ca.anewarray(Object.class.getName());
//asm.pushField(Util.class, "NOARGS");
} else {
ca.iconst(paramTypes.length);
ca.anewarray(Object.class.getName());
int index = 1;
for (int j = 0; j < paramTypes.length; j++) {
Class type = paramTypes[j];
ca.dup();
ca.iconst(j);
if (!type.isPrimitive()) {
// object or array
ca.aload(index);
} else if (type.equals(double.class)) {
ca.dload(index);
Boxing.boxDouble(ca);
index++;
} else if (type.equals(long.class)) {
ca.lload(index);
Boxing.boxLong(ca);
index++;
} else if (type.equals(float.class)) {
ca.fload(index);
Boxing.boxFloat(ca);
} else {
ca.iload(index);
Boxing.boxIfNessesary(ca, DescriptorUtils.makeDescriptor(type));
}
index++;
ca.aastore();
}
}
// Generate the call to a invoke* method ot the superclass
String invoke = "invoke";
String ret = "Ljava/lang/Object;";
if (returnType.isPrimitive() && returnType != Void.TYPE) {
String typeName = returnType.getName();
invoke += (Character.toUpperCase(typeName.charAt(0))
+ typeName.substring(1));
ret = DescriptorUtils.makeDescriptor(returnType);
}
ca.invokevirtual(superclass.getName(), invoke, "(Ljava/lang/String;Lorg/jboss/as/jacorb/rmi/marshal/strategy/StubStrategy;[Ljava/lang/Object;)" + ret);
if (!returnType.isPrimitive() && returnType != Object.class) {
ca.checkcast(returnType);
}
ca.returnInstruction();
// Generate a static method that initializes the method's strategy field
final CodeAttribute init = asm.addMethod(Modifier.PRIVATE + Modifier.STATIC,initMethod, "V").getCodeAttribute();
int i;
int len;
// Push first argument for StubStrategy constructor:
// array with abbreviated names of the param marshallers
len = paramTypes.length;
init.iconst(len);
init.anewarray(String.class.getName());
for (i = 0; i < len; i++) {
init.dup();
init.iconst(i);
init.ldc(CDRStream.abbrevFor(paramTypes[i]));
init.aastore();
}
// Push second argument for StubStrategy constructor:
// array with exception repository ids
len = exceptions.length;
int n = 0;
for (i = 0; i < len; i++) {
if (!RemoteException.class.isAssignableFrom(exceptions[i])) {
n++;
}
}
init.iconst(n);
init.anewarray(String.class.getName());
try {
int j = 0;
for (i = 0; i < len; i++) {
if (!RemoteException.class.isAssignableFrom(exceptions[i])) {
init.dup();
init.iconst(j);
init.ldc(
ExceptionAnalysis.getExceptionAnalysis(exceptions[i])
.getExceptionRepositoryId());
init.aastore();
j++;
}
}
} catch (RMIIIOPViolationException e) {
throw new RuntimeException("Cannot obtain "
+ "exception repository id for "
+ exceptions[i].getName() + ":\n" + e);
}
// Push third argument for StubStrategy constructor:
// array with exception class names
init.iconst(n);
init.anewarray(String.class.getName());
int j = 0;
for (i = 0; i < len; i++) {
if (!RemoteException.class.isAssignableFrom(exceptions[i])) {
init.dup();
init.iconst(j);
init.ldc(exceptions[i].getName());
init.aastore();
j++;
}
}
// Push fourth argument for StubStrategy constructor:
// abbreviated name of the return value marshaller
init.ldc(CDRStream.abbrevFor(returnType));
// Push fifth argument for StubStrategy constructor:
// null (no ClassLoader specified)
init.aconstNull();
// Constructs the StubStrategy
init.invokestatic(StubStrategy.class.getName(), "forMethod", "([Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)Lorg/jboss/as/jacorb/rmi/marshal/strategy/StubStrategy;");
// Set the strategy field of this stub class
init.putstatic(asm.getName(), strategyField, StubStrategy.class);
init.returnInstruction();
}