ConstantPoolGen cpg,
String className) {
final InstructionList il = new InstructionList();
// String NodeSortRecord.extractValueFromDOM(dom,node,level);
final CompareGenerator extractMethod =
new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
com.sun.org.apache.bcel.internal.generic.Type.STRING,
new com.sun.org.apache.bcel.internal.generic.Type[] {
Util.getJCRefType(DOM_INTF_SIG),
com.sun.org.apache.bcel.internal.generic.Type.INT,
com.sun.org.apache.bcel.internal.generic.Type.INT,
Util.getJCRefType(TRANSLET_SIG),
com.sun.org.apache.bcel.internal.generic.Type.INT
},
new String[] { "dom",
"current",
"level",
"translet",
"last"
},
"extractValueFromDOM", className, il, cpg);
// Values needed for the switch statement
final int levels = sortObjects.size();
final int match[] = new int[levels];
final InstructionHandle target[] = new InstructionHandle[levels];
InstructionHandle tblswitch = null;
// Compile switch statement only if the key has multiple levels
if (levels > 1) {
// Put the parameter to the swtich statement on the stack
il.append(new ILOAD(extractMethod.getLocalIndex("level")));
// Append the switch statement here later on
tblswitch = il.append(new NOP());
}
// Append all the cases for the switch statment
for (int level = 0; level < levels; level++) {
match[level] = level;
final Sort sort = (Sort)sortObjects.elementAt(level);
target[level] = il.append(NOP);
sort.translateSelect(sortRecord, extractMethod);
il.append(ARETURN);
}
// Compile def. target for switch statement if key has multiple levels
if (levels > 1) {
// Append the default target - it will _NEVER_ be reached
InstructionHandle defaultTarget =
il.append(new PUSH(cpg, EMPTYSTRING));
il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
il.append(ARETURN);
}
extractMethod.stripAttributes(true);
extractMethod.setMaxLocals();
extractMethod.setMaxStack();
extractMethod.removeNOPs();
return extractMethod.getMethod();
}