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

📄 steppattern.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: StepPattern.java,v 1.2.4.1 2005/09/12 11:13:19 pvedula Exp $ */package com.sun.org.apache.xalan.internal.xsltc.compiler;import java.util.Vector;import com.sun.org.apache.bcel.internal.classfile.Field;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.BranchHandle;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.GOTO;import com.sun.org.apache.bcel.internal.generic.GOTO_W;import com.sun.org.apache.bcel.internal.generic.IFLT;import com.sun.org.apache.bcel.internal.generic.IFNE;import com.sun.org.apache.bcel.internal.generic.IFNONNULL;import com.sun.org.apache.bcel.internal.generic.IF_ICMPEQ;import com.sun.org.apache.bcel.internal.generic.IF_ICMPLT;import com.sun.org.apache.bcel.internal.generic.IF_ICMPNE;import com.sun.org.apache.bcel.internal.generic.ILOAD;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.ISTORE;import com.sun.org.apache.bcel.internal.generic.InstructionHandle;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.bcel.internal.generic.PUTFIELD;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;import com.sun.org.apache.xml.internal.dtm.Axis;import com.sun.org.apache.xml.internal.dtm.DTM;/** * @author Jacek Ambroziak * @author Santiago Pericas-Geertsen * @author Erwin Bolwidt <ejb@klomp.org> */class StepPattern extends RelativePathPattern {    private static final int NO_CONTEXT = 0;    private static final int SIMPLE_CONTEXT = 1;    private static final int GENERAL_CONTEXT = 2;    protected final int _axis;    protected final int _nodeType;    protected Vector _predicates;    private Step    _step = null;    private boolean _isEpsilon = false;    private int     _contextCase;    private double  _priority = Double.MAX_VALUE;    public StepPattern(int axis, int nodeType, Vector predicates) {	_axis = axis;	_nodeType = nodeType;	_predicates = predicates;    }    public void setParser(Parser parser) {	super.setParser(parser);	if (_predicates != null) {	    final int n = _predicates.size();	    for (int i = 0; i < n; i++) {		final Predicate exp = (Predicate)_predicates.elementAt(i);		exp.setParser(parser);		exp.setParent(this);	    }	}    }    public int getNodeType() {	return _nodeType;    }    public void setPriority(double priority) {	_priority = priority;    }        public StepPattern getKernelPattern() {	return this;    }	    public boolean isWildcard() {	return _isEpsilon && hasPredicates() == false;    }    public StepPattern setPredicates(Vector predicates) {	_predicates = predicates;	return(this);    }        protected boolean hasPredicates() {	return _predicates != null && _predicates.size() > 0;    }    public double getDefaultPriority() {	if (_priority != Double.MAX_VALUE) {	    return _priority;	}	if (hasPredicates()) {	    return 0.5;	}	else {	    switch(_nodeType) {	    case -1:		return -0.5;	// node()	    case 0:		return 0.0;	    default:		return (_nodeType >= NodeTest.GTYPE) ? 0.0 : -0.5;	    }	}    }        public int getAxis() {	return _axis;    }    public void reduceKernelPattern() {	_isEpsilon = true;    }	    public String toString() {	final StringBuffer buffer = new StringBuffer("stepPattern(\"");    buffer.append(Axis.getNames(_axis))	    .append("\", ")	    .append(_isEpsilon ? 			("epsilon{" + Integer.toString(_nodeType) + "}") :			 Integer.toString(_nodeType));	if (_predicates != null)	    buffer.append(", ").append(_predicates.toString());	return buffer.append(')').toString();    }        private int analyzeCases() {	boolean noContext = true;	final int n = _predicates.size();	for (int i = 0; i < n && noContext; i++) {	    Predicate pred = (Predicate) _predicates.elementAt(i);            if (pred.isNthPositionFilter() ||                 pred.hasPositionCall() ||                 pred.hasLastCall())             {		noContext = false;	    }	}	if (noContext) {	    return NO_CONTEXT;	}	else if (n == 1) {	    return SIMPLE_CONTEXT;	}	return GENERAL_CONTEXT;    }    private String getNextFieldName() {	return  "__step_pattern_iter_" + getXSLTC().nextStepPatternSerial();    }    public Type typeCheck(SymbolTable stable) throws TypeCheckError {        if (hasPredicates()) {            // Type check all the predicates (e -> position() = e)            final int n = _predicates.size();            for (int i = 0; i < n; i++) {                final Predicate pred = (Predicate)_predicates.elementAt(i);                pred.typeCheck(stable);            }            // Analyze context cases            _contextCase = analyzeCases();            Step step = null;            // Create an instance of Step to do the translation            if (_contextCase == SIMPLE_CONTEXT) {                Predicate pred = (Predicate)_predicates.elementAt(0);                if (pred.isNthPositionFilter()) {                    _contextCase = GENERAL_CONTEXT;                    step = new Step(_axis, _nodeType, _predicates);                } else {                    step = new Step(_axis, _nodeType, null);                }            } else if (_contextCase == GENERAL_CONTEXT) {                final int len = _predicates.size();                for (int i = 0; i < len; i++) {                    ((Predicate)_predicates.elementAt(i)).dontOptimize();                }                step = new Step(_axis, _nodeType, _predicates);            }                        if (step != null) {                step.setParser(getParser());                step.typeCheck(stable);                _step = step;            }        }        return _axis == Axis.CHILD ? Type.Element : Type.Attribute;    }    private void translateKernel(ClassGenerator classGen, 				 MethodGenerator methodGen) {	final ConstantPoolGen cpg = classGen.getConstantPool();	final InstructionList il = methodGen.getInstructionList();		if (_nodeType == DTM.ELEMENT_NODE) {	    final int check = cpg.addInterfaceMethodref(DOM_INTF,							"isElement", "(I)Z");	    il.append(methodGen.loadDOM());	    il.append(SWAP);	    il.append(new INVOKEINTERFACE(check, 2));		    // Need to allow for long jumps here	    final BranchHandle icmp = il.append(new IFNE(null));	    _falseList.add(il.append(new GOTO_W(null)));	    icmp.setTarget(il.append(NOP));	}	else if (_nodeType == DTM.ATTRIBUTE_NODE) {	    final int check = cpg.addInterfaceMethodref(DOM_INTF,							"isAttribute", "(I)Z");	    il.append(methodGen.loadDOM());	    il.append(SWAP);	    il.append(new INVOKEINTERFACE(check, 2));		    // Need to allow for long jumps here	    final BranchHandle icmp = il.append(new IFNE(null));	    _falseList.add(il.append(new GOTO_W(null)));	    icmp.setTarget(il.append(NOP));	}	else {	    // context node is on the stack	    final int getEType = cpg.addInterfaceMethodref(DOM_INTF,							  "getExpandedTypeID",                                                          "(I)I");	    il.append(methodGen.loadDOM());

⌨️ 快捷键说明

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