* when the prefix is not known at compile time (vi) calls namespace()
* on the handler (vii) evaluates the contents (viii) calls endElement().
*/
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
LocalVariableGen local = null;
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
// Optimize translation if element name is a literal
if (_isLiteralName) {
translateLiteral(classGen, methodGen);
return;
}
if (!_ignore) {
// if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
LocalVariableGen nameValue =
methodGen.addLocalVariable2("nameValue",
Util.getJCRefType(STRING_SIG),
null);
// store the name into a variable first so _name.translate only needs to be called once
_name.translate(classGen, methodGen);
nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
il.append(new ALOAD(nameValue.getIndex()));
// call checkQName if the name is an AVT
final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkQName",
"("
+STRING_SIG
+")V");
il.append(new INVOKESTATIC(check));
// Push handler for call to endElement()
il.append(methodGen.loadHandler());
// load name value again
nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
if (_namespace != null) {
_namespace.translate(classGen, methodGen);
}
else {
// If name is an AVT and namespace is not specified, need to
// look up any prefix in the stylesheet by calling
// BasisLibrary.lookupStylesheetQNameNamespace(
// name, stylesheetNode, ancestorsArray,
// prefixURIsIndexArray, prefixURIPairsArray,
// !ignoreDefaultNamespace)
String transletClassName = getXSLTC().getClassName();
il.append(DUP);
il.append(new PUSH(cpg, getNodeIDForStylesheetNSLookup()));
il.append(new GETSTATIC(cpg.addFieldref(
transletClassName,
STATIC_NS_ANCESTORS_ARRAY_FIELD,
NS_ANCESTORS_INDEX_SIG)));
il.append(new GETSTATIC(cpg.addFieldref(
transletClassName,
STATIC_PREFIX_URIS_IDX_ARRAY_FIELD,
PREFIX_URIS_IDX_SIG)));
il.append(new GETSTATIC(cpg.addFieldref(
transletClassName,
STATIC_PREFIX_URIS_ARRAY_FIELD,
PREFIX_URIS_ARRAY_SIG)));
// Default namespace is significant
il.append(ICONST_0);
il.append(
new INVOKESTATIC(
cpg.addMethodref(BASIS_LIBRARY_CLASS,
LOOKUP_STYLESHEET_QNAME_NS_REF,
LOOKUP_STYLESHEET_QNAME_NS_SIG)));
}
// Push additional arguments
il.append(methodGen.loadHandler());
il.append(methodGen.loadDOM());
il.append(methodGen.loadCurrentNode());
// Invoke BasisLibrary.startXslElemCheckQName()
il.append(new INVOKESTATIC(
cpg.addMethodref(BASIS_LIBRARY_CLASS, "startXslElement",
"(" + STRING_SIG
+ STRING_SIG
+ TRANSLET_OUTPUT_SIG
+ DOM_INTF_SIG + "I)" + STRING_SIG)));