⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resulttreetype.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: ResultTreeType.java,v 1.2.4.1 2005/09/05 11:30:01 pvedula Exp $ */package com.sun.org.apache.xalan.internal.xsltc.compiler.util;import com.sun.org.apache.bcel.internal.generic.ALOAD;import com.sun.org.apache.bcel.internal.generic.ASTORE;import com.sun.org.apache.bcel.internal.generic.CHECKCAST;import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;import com.sun.org.apache.bcel.internal.generic.GETFIELD;import com.sun.org.apache.bcel.internal.generic.IFEQ;import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;import com.sun.org.apache.bcel.internal.generic.Instruction;import com.sun.org.apache.bcel.internal.generic.InstructionList;import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;import com.sun.org.apache.bcel.internal.generic.NEW;import com.sun.org.apache.bcel.internal.generic.PUSH;import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;/** * @author Jacek Ambroziak * @author Santiago Pericas-Geertsen * @author Morten Jorgensen */public final class ResultTreeType extends Type {    private final String _methodName;    protected ResultTreeType() {	_methodName = null;    }    public ResultTreeType(String methodName) {	_methodName = methodName;    }    public String toString() {	return "result-tree";    }    public boolean identicalTo(Type other) {	return (other instanceof ResultTreeType);    }    public String toSignature() {	return DOM_INTF_SIG;    }    public com.sun.org.apache.bcel.internal.generic.Type toJCType() {	return Util.getJCRefType(toSignature());    }    public String getMethodName() {	return _methodName;    }    public boolean implementedAsMethod() {	return _methodName != null;    }    /**     * Translates a result tree to object of internal type <code>type</code>.      * The translation to int is undefined since result trees     * are always converted to reals in arithmetic expressions.     *     * @param classGen A BCEL class generator     * @param methodGen A BCEL method generator     * @param type An instance of the type to translate the result tree to     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo     */    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 			    Type type) {	if (type == Type.String) {	    translateTo(classGen, methodGen, (StringType)type);	}	else if (type == Type.Boolean) {	    translateTo(classGen, methodGen, (BooleanType)type);	}	else if (type == Type.Real) {	    translateTo(classGen, methodGen, (RealType)type);	}	else if (type == Type.NodeSet) {	    translateTo(classGen, methodGen, (NodeSetType)type);	}	else if (type == Type.Reference) {	    translateTo(classGen, methodGen, (ReferenceType)type);	}	else if (type == Type.Object) {	    translateTo(classGen, methodGen, (ObjectType) type);	}	else {	    ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,					toString(), type.toString());	    classGen.getParser().reportError(Constants.FATAL, err);	}    }    /**     * Expects an result tree on the stack and pushes a boolean.     * Translates a result tree to a boolean by first converting it to string.     *     * @param classGen A BCEL class generator     * @param methodGen A BCEL method generator     * @param type An instance of BooleanType (any)     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo     */    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 			    BooleanType type) {	// A result tree is always 'true' when converted to a boolean value,	// since the tree always has at least one node (the root).	final ConstantPoolGen cpg = classGen.getConstantPool();	final InstructionList il = methodGen.getInstructionList();	il.append(POP);      // don't need the DOM reference	il.append(ICONST_1); // push 'true' on the stack    }    /**     * Expects an result tree on the stack and pushes a string.     *     * @param classGen A BCEL class generator     * @param methodGen A BCEL method generator     * @param type An instance of StringType (any)     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo     */    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 			    StringType type) {	final ConstantPoolGen cpg = classGen.getConstantPool();	final InstructionList il = methodGen.getInstructionList();		if (_methodName == null) {	    int index = cpg.addInterfaceMethodref(DOM_INTF,						  "getStringValue", 						  "()"+STRING_SIG);	    il.append(new INVOKEINTERFACE(index, 1));	}	else {	    final String className = classGen.getClassName();	    final int current = methodGen.getLocalIndex("current");	    	    // Push required parameters 	    il.append(classGen.loadTranslet());	    if (classGen.isExternal()) {		il.append(new CHECKCAST(cpg.addClass(className)));	    }	    il.append(DUP);	    il.append(new GETFIELD(cpg.addFieldref(className, "_dom",						   DOM_INTF_SIG)));	    // Create a new instance of a StringValueHandler	    int index = cpg.addMethodref(STRING_VALUE_HANDLER, "<init>", "()V");	    il.append(new NEW(cpg.addClass(STRING_VALUE_HANDLER)));	    il.append(DUP);	    il.append(DUP);	    il.append(new INVOKESPECIAL(index));	    	    // Store new Handler into a local variable	    final LocalVariableGen handler =		methodGen.addLocalVariable("rt_to_string_handler", 					   Util.getJCRefType(STRING_VALUE_HANDLER_SIG),					   null, null);	    il.append(new ASTORE(handler.getIndex()));	    // Call the method that implements this result tree	    index = cpg.addMethodref(className, _methodName,				     "("+DOM_INTF_SIG+TRANSLET_OUTPUT_SIG+")V");	    il.append(new INVOKEVIRTUAL(index));	    	    // Restore new handler and call getValue()	    il.append(new ALOAD(handler.getIndex()));	    index = cpg.addMethodref(STRING_VALUE_HANDLER,				     "getValue",				     "()" + STRING_SIG);	    il.append(new INVOKEVIRTUAL(index));	}    }    /**     * Expects an result tree on the stack and pushes a real.     * Translates a result tree into a real by first converting it to string.     *     * @param classGen A BCEL class generator     * @param methodGen A BCEL method generator     * @param type An instance of RealType (any)     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo     */    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 			    RealType type) {	translateTo(classGen, methodGen, Type.String);	Type.String.translateTo(classGen, methodGen, Type.Real);	    }    /**     * Expects a result tree on the stack and pushes a boxed result tree.     * Result trees are already boxed so the translation is just a NOP.     *     * @param classGen A BCEL class generator     * @param methodGen A BCEL method generator     * @param type An instance of ReferenceType (any)     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo     */    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 			    ReferenceType type) {	final ConstantPoolGen cpg = classGen.getConstantPool();	final InstructionList il = methodGen.getInstructionList();	if (_methodName == null) {	    il.append(NOP);	}	else {	    LocalVariableGen domBuilder, newDom;	    final String className = classGen.getClassName();	    final int current = methodGen.getLocalIndex("current");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -