1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.GOTO; 24 import org.apache.bcel.generic.IFNE; 25 import org.apache.bcel.generic.INVOKEINTERFACE; 26 import org.apache.bcel.generic.INVOKEVIRTUAL; 27 import org.apache.bcel.generic.InstructionList; 28 import org.apache.bcel.generic.PUSH; 29 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 30 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 31 import org.apache.xalan.xsltc.compiler.util.Type; 32 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 33 34 38 abstract class IdKeyPattern extends LocationPathPattern { 39 40 protected RelativePathPattern _left = null;; 41 private String _index = null; 42 private String _value = null;; 43 44 public IdKeyPattern(String index, String value) { 45 _index = index; 46 _value = value; 47 } 48 49 public String getIndexName() { 50 return(_index); 51 } 52 53 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 54 return Type.NodeSet; 55 } 56 57 public boolean isWildcard() { 58 return false; 59 } 60 61 public void setLeft(RelativePathPattern left) { 62 _left = left; 63 } 64 65 public StepPattern getKernelPattern() { 66 return(null); 67 } 68 69 public void reduceKernelPattern() { } 70 71 public String toString() { 72 return "id/keyPattern(" + _index + ", " + _value + ')'; 73 } 74 75 79 public void translate(ClassGenerator classGen, 80 MethodGenerator methodGen) { 81 82 final ConstantPoolGen cpg = classGen.getConstantPool(); 83 final InstructionList il = methodGen.getInstructionList(); 84 85 final int getKeyIndex = cpg.addMethodref(TRANSLET_CLASS, 87 "getKeyIndex", 88 "(Ljava/lang/String;)"+ 89 KEY_INDEX_SIG); 90 91 final int lookupId = cpg.addMethodref(KEY_INDEX_CLASS, 93 "containsID", 94 "(ILjava/lang/Object;)I"); 95 final int lookupKey = cpg.addMethodref(KEY_INDEX_CLASS, 96 "containsKey", 97 "(ILjava/lang/Object;)I"); 98 final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, 99 "getNodeIdent", 100 "(I)"+NODE_SIG); 101 102 il.append(classGen.loadTranslet()); 105 il.append(new PUSH(cpg,_index)); 106 il.append(new INVOKEVIRTUAL(getKeyIndex)); 107 108 il.append(SWAP); 111 il.append(new PUSH(cpg,_value)); 112 if (this instanceof IdPattern) 113 { 114 il.append(SWAP); 115 il.append(methodGen.loadDOM()); 116 il.append(SWAP); 117 il.append(new INVOKEINTERFACE(getNodeIdent, 2)); 118 il.append(SWAP); 119 il.append(new INVOKEVIRTUAL(lookupId)); 120 } 121 else 122 { 123 il.append(SWAP); 124 il.append(methodGen.loadDOM()); 125 il.append(SWAP); 126 il.append(new INVOKEINTERFACE(getNodeIdent, 2)); 127 il.append(SWAP); 128 il.append(new INVOKEVIRTUAL(lookupKey)); 129 } 130 131 _trueList.add(il.append(new IFNE(null))); 132 _falseList.add(il.append(new GOTO(null))); 133 } 134 135 } 136 137 | Popular Tags |