FileDocCategorySizeDatePackage
WithParam.javaAPI DocJava SE 6 API6751Tue Jun 10 00:22:30 BST 2008com.sun.org.apache.xalan.internal.xsltc.compiler

WithParam

public final class WithParam extends Instruction
author
Jacek Ambroziak
author
Santiago Pericas-Geertsen
author
Morten Jorgensen
author
John Howard

Fields Summary
private QName
_name
Parameter's name.
protected String
_escapedName
The escaped qname of the with-param.
private Expression
_select
Parameter's default value.
private boolean
_doParameterOptimization
%OPT% This is set to true when the WithParam is used in a CallTemplate for a simple named template. If this is true, the parameters are passed to the named template through method arguments rather than using the expensive Translet.addParameter() call.
Constructors Summary
Methods Summary
public voiddisplay(int indent)
Displays the contents of this element


               
        
	indent(indent);
	Util.println("with-param " + _name);
	if (_select != null) {
	    indent(indent + IndentIncrement);
	    Util.println("select " + _select.toString());
	}
	displayContents(indent + IndentIncrement);
    
public java.lang.StringgetEscapedName()
Returns the escaped qname of the parameter

	return _escapedName;
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.QNamegetName()
Return the name of this WithParam.

        return _name;	
    
public voidparseContents(com.sun.org.apache.xalan.internal.xsltc.compiler.Parser parser)
The contents of a elements are either in the element's 'select' attribute (this has precedence) or in the element body.

	final String name = getAttribute("name");
	if (name.length() > 0) {
            if (!XML11Char.isXML11ValidQName(name)) {
                ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name,
                                            this);
                parser.reportError(Constants.ERROR, err);
            }
	    setName(parser.getQNameIgnoreDefaultNs(name));
	}
        else {
	    reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
        }
	
	final String select = getAttribute("select");
	if (select.length() > 0) {
	    _select = parser.parseExpression(this, "select", null);
	}
	
	parseChildren(parser);
    
public voidsetDoParameterOptimization(boolean flag)
Set the do parameter optimization flag

    	_doParameterOptimization = flag;
    
public voidsetName(com.sun.org.apache.xalan.internal.xsltc.compiler.QName name)
Set the name of the variable or paremeter. Escape all special chars.

	_name = name;
	_escapedName = Util.escape(name.getStringRep());
    
public voidtranslate(com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator classGen, com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator methodGen)
This code generates a sequence of bytecodes that call the addParameter() method in AbstractTranslet. The method call will add (or update) the parameter frame with the new parameter value.

	final ConstantPoolGen cpg = classGen.getConstantPool();
	final InstructionList il = methodGen.getInstructionList();

	// Translate the value and put it on the stack
	if (_doParameterOptimization) {
	    translateValue(classGen, methodGen);
	    return;
	}
	
	// Make name acceptable for use as field name in class
	String name = Util.escape(getEscapedName());

	// Load reference to the translet (method is in AbstractTranslet)
	il.append(classGen.loadTranslet());

	// Load the name of the parameter
	il.append(new PUSH(cpg, name)); // TODO: namespace ?
	// Generete the value of the parameter (use value in 'select' by def.)
	translateValue(classGen, methodGen);
	// Mark this parameter value is not being the default value
	il.append(new PUSH(cpg, false));
	// Pass the parameter to the template
	il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
						     ADD_PARAMETER,
						     ADD_PARAMETER_SIG)));
	il.append(POP); // cleanup stack
    
public voidtranslateValue(com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator classGen, com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator methodGen)
Compile the value of the parameter, which is either in an expression in a 'select' attribute, or in the with-param element's body

	// Compile expression is 'select' attribute if present
	if (_select != null) {
	    _select.translate(classGen, methodGen);
	    _select.startIterator(classGen, methodGen);
	}
	// If not, compile result tree from parameter body if present.
	else if (hasContents()) {
	    compileResultTree(classGen, methodGen);
	}
	// If neither are present then store empty string in parameter slot
	else {
	    final ConstantPoolGen cpg = classGen.getConstantPool();
	    final InstructionList il = methodGen.getInstructionList();
	    il.append(new PUSH(cpg, Constants.EMPTYSTRING));
	}
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypetypeCheck(com.sun.org.apache.xalan.internal.xsltc.compiler.SymbolTable stable)
Type-check either the select attribute or the element body, depending on which is in use.

	if (_select != null) {
	    final Type tselect = _select.typeCheck(stable);
	    if (tselect instanceof ReferenceType == false) {
		_select = new CastExpr(_select, Type.Reference);
	    }
	}
	else {
	    typeCheckContents(stable);
	}
	return Type.Void;