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

📄 walkerfactory.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
          if(Axis.PRECEDING == pat.getAxis())            pat.setAxis(Axis.PRECEDINGANDANCESTOR);                      else if(Axis.DESCENDANT == pat.getAxis())            pat.setAxis(Axis.DESCENDANTORSELF);                    pat = attrPat;        }        else if(Axis.CHILD == pat.getAxis())        {          // In this case just change the axis.          // pat.setWhatToShow(whatToShow);          pat.setAxis(Axis.ATTRIBUTE);        }      }      axis = nextAxis;      //paxis = nextPaxis;      tail = pat;    }        if(axis < Axis.ALL)    {      StepPattern selfPattern = new ContextMatchStepPattern(axis, paxis);      // We need to keep the new nodetest from affecting the score...      XNumber score = tail.getStaticScore();      tail.setRelativePathPattern(selfPattern);      tail.setStaticScore(score);      selfPattern.setStaticScore(score);    }            if (DEBUG_PATTERN_CREATION)    {      System.out.println("Done loading steps: "+step.toString());                  System.out.println("");    }    return step;  // start from last pattern?? //firstStep;  }  /**   * Create a StepPattern that is contained within a LocationPath.   *   *   * @param compiler The compiler that holds the syntax tree/op map to   * construct from.   * @param stepOpCodePos The current op code position within the opmap.   * @param mpi The MatchPatternIterator to which the steps will be attached.   * @param analysis 32 bits of analysis, from which the type of AxesWalker   *                 may be influenced.   * @param tail The step that is the first step analyzed, but the last    *                  step in the relative match linked list, i.e. the tail.   *                  May be null.   * @param head The step that is the current head of the relative    *                 match step linked list.   *                 May be null.   *   * @return the head of the list.   *   * @throws javax.xml.transform.TransformerException   */  private static StepPattern createDefaultStepPattern(          Compiler compiler, int opPos, MatchPatternIterator mpi,           int analysis, StepPattern tail, StepPattern head)            throws javax.xml.transform.TransformerException  {    int stepType = compiler.getOp(opPos);    boolean simpleInit = false;    int totalNumberWalkers = (analysis & BITS_COUNT);    boolean prevIsOneStepDown = true;    int firstStepPos = compiler.getFirstChildPos(opPos);        int whatToShow = compiler.getWhatToShow(opPos);    StepPattern ai = null;    int axis, predicateAxis;        switch (stepType)    {    case OpCodes.OP_VARIABLE :    case OpCodes.OP_EXTFUNCTION :    case OpCodes.OP_FUNCTION :    case OpCodes.OP_GROUP :      prevIsOneStepDown = false;      Expression expr;      switch (stepType)      {      case OpCodes.OP_VARIABLE :      case OpCodes.OP_EXTFUNCTION :      case OpCodes.OP_FUNCTION :      case OpCodes.OP_GROUP :        expr = compiler.compile(opPos);        break;      default :        expr = compiler.compile(opPos + 2);      }      axis = Axis.FILTEREDLIST;      predicateAxis = Axis.FILTEREDLIST;      ai = new FunctionPattern(expr, axis, predicateAxis);      simpleInit = true;      break;    case OpCodes.FROM_ROOT :      whatToShow = DTMFilter.SHOW_DOCUMENT                   | DTMFilter.SHOW_DOCUMENT_FRAGMENT;      axis = Axis.ROOT;      predicateAxis = Axis.ROOT;      ai = new StepPattern(DTMFilter.SHOW_DOCUMENT |                                 DTMFilter.SHOW_DOCUMENT_FRAGMENT,                                axis, predicateAxis);      break;    case OpCodes.FROM_ATTRIBUTES :      whatToShow = DTMFilter.SHOW_ATTRIBUTE;      axis = Axis.PARENT;      predicateAxis = Axis.ATTRIBUTE;      // ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);      break;    case OpCodes.FROM_NAMESPACE :      whatToShow = DTMFilter.SHOW_NAMESPACE;      axis = Axis.PARENT;      predicateAxis = Axis.NAMESPACE;      // ai = new StepPattern(whatToShow, axis, predicateAxis);      break;    case OpCodes.FROM_ANCESTORS :      axis = Axis.DESCENDANT;      predicateAxis = Axis.ANCESTOR;      break;    case OpCodes.FROM_CHILDREN :      axis = Axis.PARENT;      predicateAxis = Axis.CHILD;      break;    case OpCodes.FROM_ANCESTORS_OR_SELF :      axis = Axis.DESCENDANTORSELF;      predicateAxis = Axis.ANCESTORORSELF;      break;    case OpCodes.FROM_SELF :      axis = Axis.SELF;      predicateAxis = Axis.SELF;      break;    case OpCodes.FROM_PARENT :      axis = Axis.CHILD;      predicateAxis = Axis.PARENT;      break;    case OpCodes.FROM_PRECEDING_SIBLINGS :      axis = Axis.FOLLOWINGSIBLING;      predicateAxis = Axis.PRECEDINGSIBLING;      break;    case OpCodes.FROM_PRECEDING :      axis = Axis.FOLLOWING;      predicateAxis = Axis.PRECEDING;      break;    case OpCodes.FROM_FOLLOWING_SIBLINGS :      axis = Axis.PRECEDINGSIBLING;      predicateAxis = Axis.FOLLOWINGSIBLING;      break;    case OpCodes.FROM_FOLLOWING :      axis = Axis.PRECEDING;      predicateAxis = Axis.FOLLOWING;      break;    case OpCodes.FROM_DESCENDANTS_OR_SELF :      axis = Axis.ANCESTORORSELF;      predicateAxis = Axis.DESCENDANTORSELF;      break;    case OpCodes.FROM_DESCENDANTS :      axis = Axis.ANCESTOR;      predicateAxis = Axis.DESCENDANT;      break;    default :      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "                                 //+ stepType);    }    if(null == ai)    {      whatToShow = compiler.getWhatToShow(opPos); // %REVIEW%      ai = new StepPattern(whatToShow, compiler.getStepNS(opPos),                                compiler.getStepLocalName(opPos),                                axis, predicateAxis);    }       if (false || DEBUG_PATTERN_CREATION)    {      System.out.print("new step: "+ ai);      System.out.print(", axis: " + Axis.getNames(ai.getAxis()));      System.out.print(", predAxis: " + Axis.getNames(ai.getAxis()));      System.out.print(", what: ");      System.out.print("    ");      ai.debugWhatToShow(ai.getWhatToShow());    }    int argLen = compiler.getFirstPredicateOpPos(opPos);    ai.setPredicates(compiler.getCompiledPredicates(argLen));    return ai;  }  /**   * Analyze a step and give information about it's predicates.  Right now this   * just returns true or false if the step has a predicate.   *   * @param compiler non-null reference to compiler object that has processed   *                 the XPath operations into an opcode map.   * @param opPos The opcode position for the step.   * @param stepType The type of step, one of OP_GROUP, etc.   *   * @return true if step has a predicate.   *   * @throws javax.xml.transform.TransformerException   */  static boolean analyzePredicate(Compiler compiler, int opPos, int stepType)          throws javax.xml.transform.TransformerException  {    int argLen;    switch (stepType)    {    case OpCodes.OP_VARIABLE :    case OpCodes.OP_EXTFUNCTION :    case OpCodes.OP_FUNCTION :    case OpCodes.OP_GROUP :      argLen = compiler.getArgLength(opPos);      break;    default :      argLen = compiler.getArgLengthOfStep(opPos);    }    int pos = compiler.getFirstPredicateOpPos(opPos);    int nPredicates = compiler.countPredicates(pos);    return (nPredicates > 0) ? true : false;  }  /**   * Create the proper Walker from the axes type.   *   * @param compiler non-null reference to compiler object that has processed   *                 the XPath operations into an opcode map.   * @param opPos The opcode position for the step.   * @param lpi The owning location path iterator.   * @param analysis 32 bits of analysis, from which the type of AxesWalker   *                 may be influenced.   *   * @return non-null reference to AxesWalker derivative.   * @throws RuntimeException if the input is bad.   */  private static AxesWalker createDefaultWalker(Compiler compiler, int opPos,          WalkingIterator lpi, int analysis)  {    AxesWalker ai = null;    int stepType = compiler.getOp(opPos);    /*    System.out.println("0: "+compiler.getOp(opPos));    System.out.println("1: "+compiler.getOp(opPos+1));    System.out.println("2: "+compiler.getOp(opPos+2));    System.out.println("3: "+compiler.getOp(opPos+3));    System.out.println("4: "+compiler.getOp(opPos+4));    System.out.println("5: "+compiler.getOp(opPos+5));    */    boolean simpleInit = false;    int totalNumberWalkers = (analysis & BITS_COUNT);    boolean prevIsOneStepDown = true;    switch (stepType)    {    case OpCodes.OP_VARIABLE :    case OpCodes.OP_EXTFUNCTION :    case OpCodes.OP_FUNCTION :    case OpCodes.OP_GROUP :      prevIsOneStepDown = false;      if (DEBUG_WALKER_CREATION)        System.out.println("new walker:  FilterExprWalker: " + analysis                           + ", " + compiler.toString());      ai = new FilterExprWalker(lpi);      simpleInit = true;      break;    case OpCodes.FROM_ROOT :      ai = new AxesWalker(lpi, Axis.ROOT);      break;    case OpCodes.FROM_ANCESTORS :      prevIsOneStepDown = false;      ai = new ReverseAxesWalker(lpi, Axis.ANCESTOR);      break;    case OpCodes.FROM_ANCESTORS_OR_SELF :      prevIsOneStepDown = false;      ai = new ReverseAxesWalker(lpi, Axis.ANCESTORORSELF);      break;    case OpCodes.FROM_ATTRIBUTES :      ai = new AxesWalker(lpi, Axis.ATTRIBUTE);      break;    case OpCodes.FROM_NAMESPACE :      ai = new AxesWalker(lpi, Axis.NAMESPACE);      break;    case OpCodes.FROM_CHILDREN :      ai = new AxesWalker(lpi, Axis.CHILD);      break;    case OpCodes.FROM_DESCENDANTS :      prevIsOneStepDown = false;      ai = new AxesWalker(lpi, Axis.DESCENDANT);      break;    case OpCodes.FROM_DESCENDANTS_OR_SELF :      prevIsOneStepDown = false;      ai = new AxesWalker(lpi, Axis.DESCENDANTORSELF);      break;    case OpCodes.FROM_FOLLOWING :      prevIsOneStepDown = false;      ai = new AxesWalker(lpi, Axis.FOLLOWING);      break;    case OpCodes.FROM_FOLLOWING_SIBLINGS :      prevIsOneStepDown = false;      ai = new AxesWalker(lpi, Axis.FOLLOWINGSIBLING);      break;    case OpCodes.FROM_PRECEDING :      prevIsOneStepDown = false;      ai = new ReverseAxesWalker(lpi, Axis.PRECEDING);      break;    case OpCodes.FROM_PRECEDING_SIBLINGS :      prevIsOneStepDown = false;      ai = new ReverseAxesWalker(lpi, Axis.PRECEDINGSIBLING);      break;    case OpCodes.FROM_PARENT :      prevIsOneStepDown = false;      ai = new ReverseAxesWalker(lpi, Axis.PARENT);      break;    case OpCodes.FROM_SELF :      ai = new AxesWalker(lpi, Axis.SELF);      break;    default :      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "                                 //+ stepType);    }    if (simpleInit)    {      ai.initNodeTest(DTMFilter.SHOW_ALL);    }    else    {      int whatToShow = compiler.getWhatToShow(opPos);      /*      System.out.print("construct: ");      NodeTest.debugWhatToShow(whatToShow);      System.out.println("or stuff: "+(whatToShow & (DTMFilter.SHOW_ATTRIBUTE                             | DTMFilter.SHOW_ELEMENT                             | DTMFilter.SHOW_PROCESSING_INSTRUCTION)));      */      if ((0 == (whatToShow                 & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE | DTMFilter.SHOW_ELEMENT                    | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) || (whatToShow == DTMFilter.SHOW_ALL))        ai.initNodeTest(whatToShow);      else      {        ai.initNodeTest(whatToShow, compiler.getStepNS(opPos),                        compiler.getStepLocalName(opPos));      }    }    return ai;  }    public static String getAnalysisString(int analysis)  {    StringBuffer buf = new StringBuffer();    buf.append("count: "+getStepCount(analysis)+" ");    if((analysis & BIT_NODETEST_ANY) != 0)    {      buf.append("NTANY|");    }    if((analysis & BIT_PREDICATE) != 0)    {      buf.append("PRED|");    }    if((analysis & BIT_ANCESTOR) != 0)    {      buf.append("ANC|");    }    if((analysis & BIT_ANCESTOR_OR_SELF) != 0)    {      buf.append("ANCOS|");    }    if((analysis & BIT_ATTRIBUTE) != 0)    {      buf.append("ATTR|");    }    if((analysis & BIT_CHILD) != 0)    {      buf.append("CH|");    }    if((analysis & BIT_DESCENDANT) != 0)    {      buf.append("DESC|");    }    if((analysis & BIT_DESCENDANT_OR_SELF) != 0)    {      buf.append("DESCOS|");    }    if((analysis & BIT_FOLLOWING) != 0)    {      buf.append("FOL|");    }    if((analysis & BIT_FOLLOWING_SIBLING) != 0)    {      buf.append("FOLS|");    }    if((analysis & BIT_NAMESPACE) != 0)    {      buf.append("NS|");    }    if((analysis & BIT_PARENT) != 0)    {      buf.append("P|");    }    if((analysis & BIT_PRECEDING) != 0)    {      buf.append("PREC|");    }    if((analysis & BIT_PRECEDING_SIBLING) != 0)    {      buf.append("PRECS|");    }    if((analysis & BIT_SELF) != 0)    {      buf.append(".|");    }    if((analysis & BIT_FILTER) != 0)    {      buf.append("FLT|");    }    if((analysis & BIT_ROOT) != 0)    {      buf.append("R|");    }    return buf.toString();  }  /** Set to true for diagnostics about walker creation */  static final boolean DEBUG_PATTERN_CREATION = false;  /** Set to true for diagnostics about walker creation */  static final boolean DEBUG_WALKER_CREATION = false;  /** Set to true for diagnostics about iterator creation */  static final boolean DEBUG_ITERATOR_CREATION = false;    public static boolean hasPredicate(int analysis)  {    return (0 != (analysis & BIT_PREDICATE));  }  public static boolean isWild(int analysis)

⌨️ 快捷键说明

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