*/
private static void compilePredicate(Vector rules,
int defaultAction,
ClassGenerator classGen) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = new InstructionList();
final XSLTC xsltc = classGen.getParser().getXSLTC();
// private boolean Translet.stripSpace(int type) - cannot be static
final MethodGenerator stripSpace =
new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN,
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
},
new String[] { "dom","node","type" },
"stripSpace",classGen.getClassName(),il,cpg);
classGen.addInterface("com/sun/org/apache/xalan/internal/xsltc/StripFilter");
final int paramDom = stripSpace.getLocalIndex("dom");
final int paramCurrent = stripSpace.getLocalIndex("node");
final int paramType = stripSpace.getLocalIndex("type");
BranchHandle strip[] = new BranchHandle[rules.size()];
BranchHandle preserve[] = new BranchHandle[rules.size()];
int sCount = 0;
int pCount = 0;
// Traverse all strip/preserve rules
for (int i = 0; i<rules.size(); i++) {
// Get the next rule in the prioritised list
WhitespaceRule rule = (WhitespaceRule)rules.elementAt(i);
// Returns the namespace for a node in the DOM
final int gns = cpg.addInterfaceMethodref(DOM_INTF,
"getNamespaceName",
"(I)Ljava/lang/String;");
final int strcmp = cpg.addMethodref("java/lang/String",
"compareTo",
"(Ljava/lang/String;)I");
// Handle elements="ns:*" type rule
if (rule.getStrength() == RULE_NAMESPACE) {
il.append(new ALOAD(paramDom));
il.append(new ILOAD(paramCurrent));
il.append(new INVOKEINTERFACE(gns,2));
il.append(new PUSH(cpg, rule.getNamespace()));
il.append(new INVOKEVIRTUAL(strcmp));
il.append(ICONST_0);
if (rule.getAction() == STRIP_SPACE) {
strip[sCount++] = il.append(new IF_ICMPEQ(null));
}
else {
preserve[pCount++] = il.append(new IF_ICMPEQ(null));
}
}
// Handle elements="ns:el" type rule
else if (rule.getStrength() == RULE_ELEMENT) {
// Create the QName for the element
final Parser parser = classGen.getParser();
QName qname;
if (rule.getNamespace() != Constants.EMPTYSTRING )
qname = parser.getQName(rule.getNamespace(), null,
rule.getElement());
else
qname = parser.getQName(rule.getElement());
// Register the element.
final int elementType = xsltc.registerElement(qname);
il.append(new ILOAD(paramType));
il.append(new PUSH(cpg, elementType));
// Compare current node type with wanted element type
if (rule.getAction() == STRIP_SPACE)
strip[sCount++] = il.append(new IF_ICMPEQ(null));
else
preserve[pCount++] = il.append(new IF_ICMPEQ(null));
}
}
if (defaultAction == STRIP_SPACE) {
compileStripSpace(strip, sCount, il);