Java Code Examples for com.sun.org.apache.xml.internal.dtm.Axis#DESCENDANTORSELF

The following examples show how to use com.sun.org.apache.xml.internal.dtm.Axis#DESCENDANTORSELF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleResultTreeImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public DTMAxisIterator getTypedAxisIterator(final int axis, final int type)
{
    switch (axis)
    {
        case Axis.CHILD:
        case Axis.DESCENDANT:
            return new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type);
        case Axis.PARENT:
        case Axis.ANCESTOR:
            return new SimpleIterator(SimpleIterator.DIRECTION_UP, type);
        case Axis.ANCESTORORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_UP, type)).includeSelf();
        case Axis.DESCENDANTORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type)).includeSelf();
        case Axis.SELF:
            return new SingletonIterator(type);
        default:
            return EMPTY_ITERATOR;
    }
}
 
Example 2
Source File: SimpleResultTreeImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public DTMAxisIterator getAxisIterator(final int axis)
{
    switch (axis)
    {
        case Axis.CHILD:
        case Axis.DESCENDANT:
            return new SimpleIterator(SimpleIterator.DIRECTION_DOWN);
        case Axis.PARENT:
        case Axis.ANCESTOR:
            return new SimpleIterator(SimpleIterator.DIRECTION_UP);
        case Axis.ANCESTORORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_UP)).includeSelf();
        case Axis.DESCENDANTORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_DOWN)).includeSelf();
        case Axis.SELF:
            return new SingletonIterator();
        default:
            return EMPTY_ITERATOR;
    }
}
 
Example 3
Source File: SimpleResultTreeImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public DTMAxisIterator getAxisIterator(final int axis)
{
    switch (axis)
    {
        case Axis.CHILD:
        case Axis.DESCENDANT:
            return new SimpleIterator(SimpleIterator.DIRECTION_DOWN);
        case Axis.PARENT:
        case Axis.ANCESTOR:
            return new SimpleIterator(SimpleIterator.DIRECTION_UP);
        case Axis.ANCESTORORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_UP)).includeSelf();
        case Axis.DESCENDANTORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_DOWN)).includeSelf();
        case Axis.SELF:
            return new SingletonIterator();
        default:
            return EMPTY_ITERATOR;
    }
}
 
Example 4
Source File: SimpleResultTreeImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public DTMAxisIterator getTypedAxisIterator(final int axis, final int type)
{
    switch (axis)
    {
        case Axis.CHILD:
        case Axis.DESCENDANT:
            return new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type);
        case Axis.PARENT:
        case Axis.ANCESTOR:
            return new SimpleIterator(SimpleIterator.DIRECTION_UP, type);
        case Axis.ANCESTORORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_UP, type)).includeSelf();
        case Axis.DESCENDANTORSELF:
            return (new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type)).includeSelf();
        case Axis.SELF:
            return new SingletonIterator(type);
        default:
            return EMPTY_ITERATOR;
    }
}
 
Example 5
Source File: WalkerFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Tell if the given axis goes downword.  Bogus name, if you can think of
   * a better one, please do tell.  This really has to do with inverting
   * attribute axis.
   * @param axis One of Axis.XXX.
   * @return true if the axis is not a child axis and does not go up from
   * the axis root.
   */
  public static boolean isDownwardAxisOfMany(int axis)
  {
    return ((Axis.DESCENDANTORSELF == axis) ||
          (Axis.DESCENDANT == axis)
          || (Axis.FOLLOWING == axis)
//          || (Axis.FOLLOWINGSIBLING == axis)
          || (Axis.PRECEDING == axis)
//          || (Axis.PRECEDINGSIBLING == axis)
          );
  }
 
Example 6
Source File: SAXImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is a shortcut to the iterators that implement the
 * supported XPath axes (only namespace::) is not supported.
 * Returns a bare-bones iterator that must be initialized
 * with a start node (using iterator.setStartNode()).
 */
public DTMAxisIterator getAxisIterator(final int axis)
{
    switch (axis)
    {
        case Axis.SELF:
            return new SingletonIterator();
        case Axis.CHILD:
            return new ChildrenIterator();
        case Axis.PARENT:
            return new ParentIterator();
        case Axis.ANCESTOR:
            return new AncestorIterator();
        case Axis.ANCESTORORSELF:
            return (new AncestorIterator()).includeSelf();
        case Axis.ATTRIBUTE:
            return new AttributeIterator();
        case Axis.DESCENDANT:
            return new DescendantIterator();
        case Axis.DESCENDANTORSELF:
            return (new DescendantIterator()).includeSelf();
        case Axis.FOLLOWING:
            return new FollowingIterator();
        case Axis.PRECEDING:
            return new PrecedingIterator();
        case Axis.FOLLOWINGSIBLING:
            return new FollowingSiblingIterator();
        case Axis.PRECEDINGSIBLING:
            return new PrecedingSiblingIterator();
        case Axis.NAMESPACE:
            return new NamespaceIterator();
        case Axis.ROOT:
            return new RootIterator();
        default:
            BasisLibrary.runTimeError(BasisLibrary.AXIS_SUPPORT_ERR,
                    Axis.getNames(axis));
    }
    return null;
}
 
Example 7
Source File: WalkerFactory.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
   * Tell if the given axis goes downword.  Bogus name, if you can think of
   * a better one, please do tell.  This really has to do with inverting
   * attribute axis.
   * @param axis One of Axis.XXX.
   * @return true if the axis is not a child axis and does not go up from
   * the axis root.
   */
  public static boolean isDownwardAxisOfMany(int axis)
  {
    return ((Axis.DESCENDANTORSELF == axis) ||
          (Axis.DESCENDANT == axis)
          || (Axis.FOLLOWING == axis)
//          || (Axis.FOLLOWINGSIBLING == axis)
          || (Axis.PRECEDING == axis)
//          || (Axis.PRECEDINGSIBLING == axis)
          );
  }
 
Example 8
Source File: SAXImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is a shortcut to the iterators that implement the
 * supported XPath axes (only namespace::) is not supported.
 * Returns a bare-bones iterator that must be initialized
 * with a start node (using iterator.setStartNode()).
 */
public DTMAxisIterator getAxisIterator(final int axis)
{
    switch (axis)
    {
        case Axis.SELF:
            return new SingletonIterator();
        case Axis.CHILD:
            return new ChildrenIterator();
        case Axis.PARENT:
            return new ParentIterator();
        case Axis.ANCESTOR:
            return new AncestorIterator();
        case Axis.ANCESTORORSELF:
            return (new AncestorIterator()).includeSelf();
        case Axis.ATTRIBUTE:
            return new AttributeIterator();
        case Axis.DESCENDANT:
            return new DescendantIterator();
        case Axis.DESCENDANTORSELF:
            return (new DescendantIterator()).includeSelf();
        case Axis.FOLLOWING:
            return new FollowingIterator();
        case Axis.PRECEDING:
            return new PrecedingIterator();
        case Axis.FOLLOWINGSIBLING:
            return new FollowingSiblingIterator();
        case Axis.PRECEDINGSIBLING:
            return new PrecedingSiblingIterator();
        case Axis.NAMESPACE:
            return new NamespaceIterator();
        case Axis.ROOT:
            return new RootIterator();
        default:
            BasisLibrary.runTimeError(BasisLibrary.AXIS_SUPPORT_ERR,
                    Axis.getNames(axis));
    }
    return null;
}
 
Example 9
Source File: WalkingIteratorSorted.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Tell if the nodeset can be walked in doc order, via static analysis.
 *
 *
 * @return true if the nodeset can be walked in doc order, without sorting.
 */
boolean canBeWalkedInNaturalDocOrderStatic()
{

  if (null != m_firstWalker)
  {
    AxesWalker walker = m_firstWalker;
    int prevAxis = -1;
    boolean prevIsSimpleDownAxis = true;

    for(int i = 0; null != walker; i++)
    {
      int axis = walker.getAxis();

      if(walker.isDocOrdered())
      {
        boolean isSimpleDownAxis = ((axis == Axis.CHILD)
                                 || (axis == Axis.SELF)
                                 || (axis == Axis.ROOT));
        // Catching the filtered list here is only OK because
        // FilterExprWalker#isDocOrdered() did the right thing.
        if(isSimpleDownAxis || (axis == -1))
          walker = walker.getNextWalker();
        else
        {
          boolean isLastWalker = (null == walker.getNextWalker());
          if(isLastWalker)
          {
            if(walker.isDocOrdered() && (axis == Axis.DESCENDANT ||
               axis == Axis.DESCENDANTORSELF || axis == Axis.DESCENDANTSFROMROOT
               || axis == Axis.DESCENDANTSORSELFFROMROOT) || (axis == Axis.ATTRIBUTE))
              return true;
          }
          return false;
        }
      }
      else
        return false;
    }
    return true;
  }
  return false;
}
 
Example 10
Source File: WalkerFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Special purpose function to see if we can optimize the pattern for
 * a DescendantIterator.
 *
 * @param compiler non-null reference to compiler object that has processed
 *                 the XPath operations into an opcode map.
 * @param stepOpCodePos The opcode position for the step.
 *
 * @return 32 bits as an integer that give information about the location
 * path as a whole.
 *
 * @throws javax.xml.transform.TransformerException
 */
public static int getAxisFromStep(
        Compiler compiler, int stepOpCodePos)
          throws javax.xml.transform.TransformerException
{

  int stepType = compiler.getOp(stepOpCodePos);

  switch (stepType)
  {
  case OpCodes.FROM_FOLLOWING :
    return Axis.FOLLOWING;
  case OpCodes.FROM_FOLLOWING_SIBLINGS :
    return Axis.FOLLOWINGSIBLING;
  case OpCodes.FROM_PRECEDING :
    return Axis.PRECEDING;
  case OpCodes.FROM_PRECEDING_SIBLINGS :
    return Axis.PRECEDINGSIBLING;
  case OpCodes.FROM_PARENT :
    return Axis.PARENT;
  case OpCodes.FROM_NAMESPACE :
    return Axis.NAMESPACE;
  case OpCodes.FROM_ANCESTORS :
    return Axis.ANCESTOR;
  case OpCodes.FROM_ANCESTORS_OR_SELF :
    return Axis.ANCESTORORSELF;
  case OpCodes.FROM_ATTRIBUTES :
    return Axis.ATTRIBUTE;
  case OpCodes.FROM_ROOT :
    return Axis.ROOT;
  case OpCodes.FROM_CHILDREN :
    return Axis.CHILD;
  case OpCodes.FROM_DESCENDANTS_OR_SELF :
    return Axis.DESCENDANTORSELF;
  case OpCodes.FROM_DESCENDANTS :
    return Axis.DESCENDANT;
  case OpCodes.FROM_SELF :
    return Axis.SELF;
  case OpCodes.OP_EXTFUNCTION :
  case OpCodes.OP_FUNCTION :
  case OpCodes.OP_GROUP :
  case OpCodes.OP_VARIABLE :
    return Axis.FILTEREDLIST;
  }

  throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
                             //+ stepType);
 }
 
Example 11
Source File: ParentLocationPath.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void translateStep(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Backwards branches are prohibited if an uninitialized object is
    // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
    // We don't know whether this code might contain backwards branches
    // so we mustn't create the new object until after we've created
    // the suspect arguments to its constructor.  Instead we calculate
    // the values of the arguments to the constructor first, store them
    // in temporary variables, create the object and reload the
    // arguments from the temporaries to avoid the problem.

    LocalVariableGen pathTemp
            = methodGen.addLocalVariable("parent_location_path_tmp1",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

    _step.translate(classGen, methodGen);
    LocalVariableGen stepTemp
            = methodGen.addLocalVariable("parent_location_path_tmp2",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    stepTemp.setStart(il.append(new ASTORE(stepTemp.getIndex())));

    // Create new StepIterator
    final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
                                        "<init>",
                                        "("
                                        +NODE_ITERATOR_SIG
                                        +NODE_ITERATOR_SIG
                                        +")V");
    il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
    il.append(DUP);

    pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
    stepTemp.setEnd(il.append(new ALOAD(stepTemp.getIndex())));

    // Initialize StepIterator with iterators from the stack
    il.append(new INVOKESPECIAL(initSI));

    // This is a special case for the //* path with or without predicates
    Expression stp = _step;
    if (stp instanceof ParentLocationPath)
        stp = ((ParentLocationPath)stp).getStep();

    if ((_path instanceof Step) && (stp instanceof Step)) {
        final int path = ((Step)_path).getAxis();
        final int step = ((Step)stp).getAxis();
        if ((path == Axis.DESCENDANTORSELF && step == Axis.CHILD) ||
            (path == Axis.PRECEDING        && step == Axis.PARENT)) {
            final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
                                              "includeSelf",
                                              "()" + NODE_ITERATOR_SIG);
            il.append(new INVOKEVIRTUAL(incl));
        }
    }

    /*
     * If this pattern contains a sequence of descendant iterators we
     * run the risk of returning the same node several times. We put
     * a new iterator on top of the existing one to assure node order
     * and prevent returning a single node multiple times.
     */
    if (_orderNodes) {
        final int order = cpg.addInterfaceMethodref(DOM_INTF,
                                                    ORDER_ITERATOR,
                                                    ORDER_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(methodGen.loadContextNode());
        il.append(new INVOKEINTERFACE(order, 3));
    }
}
 
Example 12
Source File: MatchPatternIterator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a LocPathIterator object, including creation
 * of step walkers from the opcode list, and call back
 * into the Compiler to create predicate expressions.
 *
 * @param compiler The Compiler which is creating
 * this expression.
 * @param opPos The position of this iterator in the
 * opcode list from the compiler.
 * @param analysis Analysis bits that give general information about the
 * LocationPath.
 *
 * @throws javax.xml.transform.TransformerException
 */
MatchPatternIterator(Compiler compiler, int opPos, int analysis)
        throws javax.xml.transform.TransformerException
{

  super(compiler, opPos, analysis, false);

  int firstStepPos = OpMap.getFirstChildPos(opPos);

  m_pattern = WalkerFactory.loadSteps(this, compiler, firstStepPos, 0);

  boolean fromRoot = false;
  boolean walkBack = false;
  boolean walkDescendants = false;
  boolean walkAttributes = false;

  if (0 != (analysis & (WalkerFactory.BIT_ROOT |
                        WalkerFactory.BIT_ANY_DESCENDANT_FROM_ROOT)))
    fromRoot = true;

  if (0 != (analysis
            & (WalkerFactory.BIT_ANCESTOR
               | WalkerFactory.BIT_ANCESTOR_OR_SELF
               | WalkerFactory.BIT_PRECEDING
               | WalkerFactory.BIT_PRECEDING_SIBLING
               | WalkerFactory.BIT_FOLLOWING
               | WalkerFactory.BIT_FOLLOWING_SIBLING
               | WalkerFactory.BIT_PARENT | WalkerFactory.BIT_FILTER)))
    walkBack = true;

  if (0 != (analysis
            & (WalkerFactory.BIT_DESCENDANT_OR_SELF
               | WalkerFactory.BIT_DESCENDANT
               | WalkerFactory.BIT_CHILD)))
    walkDescendants = true;

  if (0 != (analysis
            & (WalkerFactory.BIT_ATTRIBUTE | WalkerFactory.BIT_NAMESPACE)))
    walkAttributes = true;

  if(false || DEBUG)
  {
    System.out.print("analysis: "+Integer.toBinaryString(analysis));
    System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
  }

  if(fromRoot || walkBack)
  {
    if(walkAttributes)
    {
      m_superAxis = Axis.ALL;
    }
    else
    {
      m_superAxis = Axis.DESCENDANTSFROMROOT;
    }
  }
  else if(walkDescendants)
  {
    if(walkAttributes)
    {
      m_superAxis = Axis.ALLFROMNODE;
    }
    else
    {
      m_superAxis = Axis.DESCENDANTORSELF;
    }
  }
  else
  {
    m_superAxis = Axis.ALL;
  }
  if(false || DEBUG)
  {
    System.out.println("axis: "+Axis.getNames(m_superAxis));
  }

}
 
Example 13
Source File: MatchPatternIterator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a LocPathIterator object, including creation
 * of step walkers from the opcode list, and call back
 * into the Compiler to create predicate expressions.
 *
 * @param compiler The Compiler which is creating
 * this expression.
 * @param opPos The position of this iterator in the
 * opcode list from the compiler.
 * @param analysis Analysis bits that give general information about the
 * LocationPath.
 *
 * @throws javax.xml.transform.TransformerException
 */
MatchPatternIterator(Compiler compiler, int opPos, int analysis)
        throws javax.xml.transform.TransformerException
{

  super(compiler, opPos, analysis, false);

  int firstStepPos = OpMap.getFirstChildPos(opPos);

  m_pattern = WalkerFactory.loadSteps(this, compiler, firstStepPos, 0);

  boolean fromRoot = false;
  boolean walkBack = false;
  boolean walkDescendants = false;
  boolean walkAttributes = false;

  if (0 != (analysis & (WalkerFactory.BIT_ROOT |
                        WalkerFactory.BIT_ANY_DESCENDANT_FROM_ROOT)))
    fromRoot = true;

  if (0 != (analysis
            & (WalkerFactory.BIT_ANCESTOR
               | WalkerFactory.BIT_ANCESTOR_OR_SELF
               | WalkerFactory.BIT_PRECEDING
               | WalkerFactory.BIT_PRECEDING_SIBLING
               | WalkerFactory.BIT_FOLLOWING
               | WalkerFactory.BIT_FOLLOWING_SIBLING
               | WalkerFactory.BIT_PARENT | WalkerFactory.BIT_FILTER)))
    walkBack = true;

  if (0 != (analysis
            & (WalkerFactory.BIT_DESCENDANT_OR_SELF
               | WalkerFactory.BIT_DESCENDANT
               | WalkerFactory.BIT_CHILD)))
    walkDescendants = true;

  if (0 != (analysis
            & (WalkerFactory.BIT_ATTRIBUTE | WalkerFactory.BIT_NAMESPACE)))
    walkAttributes = true;

  if(false || DEBUG)
  {
    System.out.print("analysis: "+Integer.toBinaryString(analysis));
    System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
  }

  if(fromRoot || walkBack)
  {
    if(walkAttributes)
    {
      m_superAxis = Axis.ALL;
    }
    else
    {
      m_superAxis = Axis.DESCENDANTSFROMROOT;
    }
  }
  else if(walkDescendants)
  {
    if(walkAttributes)
    {
      m_superAxis = Axis.ALLFROMNODE;
    }
    else
    {
      m_superAxis = Axis.DESCENDANTORSELF;
    }
  }
  else
  {
    m_superAxis = Axis.ALL;
  }
  if(false || DEBUG)
  {
    System.out.println("axis: "+Axis.getNames(m_superAxis));
  }

}
 
Example 14
Source File: ParentLocationPath.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is used to determine if this parent location path is a
 * combination of two step's with axes that will create duplicate or
 * unordered nodes.
 */
public boolean checkAxisMismatch() {

    int left = _path.getAxis();
    int right = ((Step)_step).getAxis();

    if (((left == Axis.ANCESTOR) || (left == Axis.ANCESTORORSELF)) &&
        ((right == Axis.CHILD) ||
         (right == Axis.DESCENDANT) ||
         (right == Axis.DESCENDANTORSELF) ||
         (right == Axis.PARENT) ||
         (right == Axis.PRECEDING) ||
         (right == Axis.PRECEDINGSIBLING)))
        return true;

    if ((left == Axis.CHILD) &&
        (right == Axis.ANCESTOR) ||
        (right == Axis.ANCESTORORSELF) ||
        (right == Axis.PARENT) ||
        (right == Axis.PRECEDING))
        return true;

    if ((left == Axis.DESCENDANT) || (left == Axis.DESCENDANTORSELF))
        return true;

    if (((left == Axis.FOLLOWING) || (left == Axis.FOLLOWINGSIBLING)) &&
        ((right == Axis.FOLLOWING) ||
         (right == Axis.PARENT) ||
         (right == Axis.PRECEDING) ||
         (right == Axis.PRECEDINGSIBLING)))
        return true;

    if (((left == Axis.PRECEDING) || (left == Axis.PRECEDINGSIBLING)) &&
        ((right == Axis.DESCENDANT) ||
         (right == Axis.DESCENDANTORSELF) ||
         (right == Axis.FOLLOWING) ||
         (right == Axis.FOLLOWINGSIBLING) ||
         (right == Axis.PARENT) ||
         (right == Axis.PRECEDING) ||
         (right == Axis.PRECEDINGSIBLING)))
        return true;

    if ((right == Axis.FOLLOWING) && (left == Axis.CHILD)) {
        // Special case for '@*/following::*' expressions. The resulting
        // iterator is initialised with the parent's first child, and this
        // can cause duplicates in the output if the parent has more than
        // one attribute that matches the left step.
        if (_path instanceof Step) {
            int type = ((Step)_path).getNodeType();
            if (type == DTM.ATTRIBUTE_NODE) return true;
        }
    }

    return false;
}
 
Example 15
Source File: SAXImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Similar to getAxisIterator, but this one returns an iterator
 * containing nodes of a typed axis (ex.: child::foo)
 */
public DTMAxisIterator getTypedAxisIterator(int axis, int type)
{
    // Most common case handled first
    if (axis == Axis.CHILD) {
        return new TypedChildrenIterator(type);
    }

    if (type == NO_TYPE) {
        return(EMPTYITERATOR);
    }

    switch (axis)
    {
        case Axis.SELF:
            return new TypedSingletonIterator(type);
        case Axis.CHILD:
            return new TypedChildrenIterator(type);
        case Axis.PARENT:
            return new ParentIterator().setNodeType(type);
        case Axis.ANCESTOR:
            return new TypedAncestorIterator(type);
        case Axis.ANCESTORORSELF:
            return (new TypedAncestorIterator(type)).includeSelf();
        case Axis.ATTRIBUTE:
            return new TypedAttributeIterator(type);
        case Axis.DESCENDANT:
            return new TypedDescendantIterator(type);
        case Axis.DESCENDANTORSELF:
            return (new TypedDescendantIterator(type)).includeSelf();
        case Axis.FOLLOWING:
            return new TypedFollowingIterator(type);
        case Axis.PRECEDING:
            return new TypedPrecedingIterator(type);
        case Axis.FOLLOWINGSIBLING:
            return new TypedFollowingSiblingIterator(type);
        case Axis.PRECEDINGSIBLING:
            return new TypedPrecedingSiblingIterator(type);
        case Axis.NAMESPACE:
            return  new TypedNamespaceIterator(type);
        case Axis.ROOT:
            return new TypedRootIterator(type);
        default:
            BasisLibrary.runTimeError(BasisLibrary.TYPED_AXIS_SUPPORT_ERR,
                    Axis.getNames(axis));
    }
    return null;
}
 
Example 16
Source File: WalkingIteratorSorted.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell if the nodeset can be walked in doc order, via static analysis.
 *
 *
 * @return true if the nodeset can be walked in doc order, without sorting.
 */
boolean canBeWalkedInNaturalDocOrderStatic()
{

  if (null != m_firstWalker)
  {
    AxesWalker walker = m_firstWalker;
    int prevAxis = -1;
    boolean prevIsSimpleDownAxis = true;

    for(int i = 0; null != walker; i++)
    {
      int axis = walker.getAxis();

      if(walker.isDocOrdered())
      {
        boolean isSimpleDownAxis = ((axis == Axis.CHILD)
                                 || (axis == Axis.SELF)
                                 || (axis == Axis.ROOT));
        // Catching the filtered list here is only OK because
        // FilterExprWalker#isDocOrdered() did the right thing.
        if(isSimpleDownAxis || (axis == -1))
          walker = walker.getNextWalker();
        else
        {
          boolean isLastWalker = (null == walker.getNextWalker());
          if(isLastWalker)
          {
            if(walker.isDocOrdered() && (axis == Axis.DESCENDANT ||
               axis == Axis.DESCENDANTORSELF || axis == Axis.DESCENDANTSFROMROOT
               || axis == Axis.DESCENDANTSORSELFFROMROOT) || (axis == Axis.ATTRIBUTE))
              return true;
          }
          return false;
        }
      }
      else
        return false;
    }
    return true;
  }
  return false;
}
 
Example 17
Source File: ParentLocationPath.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void translateStep(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Backwards branches are prohibited if an uninitialized object is
    // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
    // We don't know whether this code might contain backwards branches
    // so we mustn't create the new object until after we've created
    // the suspect arguments to its constructor.  Instead we calculate
    // the values of the arguments to the constructor first, store them
    // in temporary variables, create the object and reload the
    // arguments from the temporaries to avoid the problem.

    LocalVariableGen pathTemp
            = methodGen.addLocalVariable("parent_location_path_tmp1",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

    _step.translate(classGen, methodGen);
    LocalVariableGen stepTemp
            = methodGen.addLocalVariable("parent_location_path_tmp2",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    stepTemp.setStart(il.append(new ASTORE(stepTemp.getIndex())));

    // Create new StepIterator
    final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
                                        "<init>",
                                        "("
                                        +NODE_ITERATOR_SIG
                                        +NODE_ITERATOR_SIG
                                        +")V");
    il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
    il.append(DUP);

    pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
    stepTemp.setEnd(il.append(new ALOAD(stepTemp.getIndex())));

    // Initialize StepIterator with iterators from the stack
    il.append(new INVOKESPECIAL(initSI));

    // This is a special case for the //* path with or without predicates
    Expression stp = _step;
    if (stp instanceof ParentLocationPath)
        stp = ((ParentLocationPath)stp).getStep();

    if ((_path instanceof Step) && (stp instanceof Step)) {
        final int path = ((Step)_path).getAxis();
        final int step = ((Step)stp).getAxis();
        if ((path == Axis.DESCENDANTORSELF && step == Axis.CHILD) ||
            (path == Axis.PRECEDING        && step == Axis.PARENT)) {
            final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
                                              "includeSelf",
                                              "()" + NODE_ITERATOR_SIG);
            il.append(new INVOKEVIRTUAL(incl));
        }
    }

    /*
     * If this pattern contains a sequence of descendant iterators we
     * run the risk of returning the same node several times. We put
     * a new iterator on top of the existing one to assure node order
     * and prevent returning a single node multiple times.
     */
    if (_orderNodes) {
        final int order = cpg.addInterfaceMethodref(DOM_INTF,
                                                    ORDER_ITERATOR,
                                                    ORDER_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(methodGen.loadContextNode());
        il.append(new INVOKEINTERFACE(order, 3));
    }
}
 
Example 18
Source File: WalkerFactory.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Special purpose function to see if we can optimize the pattern for
 * a DescendantIterator.
 *
 * @param compiler non-null reference to compiler object that has processed
 *                 the XPath operations into an opcode map.
 * @param stepOpCodePos The opcode position for the step.
 *
 * @return 32 bits as an integer that give information about the location
 * path as a whole.
 *
 * @throws javax.xml.transform.TransformerException
 */
public static int getAxisFromStep(
        Compiler compiler, int stepOpCodePos)
          throws javax.xml.transform.TransformerException
{

  int stepType = compiler.getOp(stepOpCodePos);

  switch (stepType)
  {
  case OpCodes.FROM_FOLLOWING :
    return Axis.FOLLOWING;
  case OpCodes.FROM_FOLLOWING_SIBLINGS :
    return Axis.FOLLOWINGSIBLING;
  case OpCodes.FROM_PRECEDING :
    return Axis.PRECEDING;
  case OpCodes.FROM_PRECEDING_SIBLINGS :
    return Axis.PRECEDINGSIBLING;
  case OpCodes.FROM_PARENT :
    return Axis.PARENT;
  case OpCodes.FROM_NAMESPACE :
    return Axis.NAMESPACE;
  case OpCodes.FROM_ANCESTORS :
    return Axis.ANCESTOR;
  case OpCodes.FROM_ANCESTORS_OR_SELF :
    return Axis.ANCESTORORSELF;
  case OpCodes.FROM_ATTRIBUTES :
    return Axis.ATTRIBUTE;
  case OpCodes.FROM_ROOT :
    return Axis.ROOT;
  case OpCodes.FROM_CHILDREN :
    return Axis.CHILD;
  case OpCodes.FROM_DESCENDANTS_OR_SELF :
    return Axis.DESCENDANTORSELF;
  case OpCodes.FROM_DESCENDANTS :
    return Axis.DESCENDANT;
  case OpCodes.FROM_SELF :
    return Axis.SELF;
  case OpCodes.OP_EXTFUNCTION :
  case OpCodes.OP_FUNCTION :
  case OpCodes.OP_GROUP :
  case OpCodes.OP_VARIABLE :
    return Axis.FILTEREDLIST;
  }

  throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
                             //+ stepType);
 }
 
Example 19
Source File: WalkerFactory.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Get a corresponding BIT_XXX from an axis.
 * @param axis One of Axis.ANCESTOR, etc.
 * @return One of BIT_ANCESTOR, etc.
 */
static public int getAnalysisBitFromAxes(int axis)
{
  switch (axis) // Generate new traverser
    {
    case Axis.ANCESTOR :
      return BIT_ANCESTOR;
    case Axis.ANCESTORORSELF :
      return BIT_ANCESTOR_OR_SELF;
    case Axis.ATTRIBUTE :
      return BIT_ATTRIBUTE;
    case Axis.CHILD :
      return BIT_CHILD;
    case Axis.DESCENDANT :
      return BIT_DESCENDANT;
    case Axis.DESCENDANTORSELF :
      return BIT_DESCENDANT_OR_SELF;
    case Axis.FOLLOWING :
      return BIT_FOLLOWING;
    case Axis.FOLLOWINGSIBLING :
      return BIT_FOLLOWING_SIBLING;
    case Axis.NAMESPACE :
    case Axis.NAMESPACEDECLS :
      return BIT_NAMESPACE;
    case Axis.PARENT :
      return BIT_PARENT;
    case Axis.PRECEDING :
      return BIT_PRECEDING;
    case Axis.PRECEDINGSIBLING :
      return BIT_PRECEDING_SIBLING;
    case Axis.SELF :
      return BIT_SELF;
    case Axis.ALLFROMNODE :
      return BIT_DESCENDANT_OR_SELF;
      // case Axis.PRECEDINGANDANCESTOR :
    case Axis.DESCENDANTSFROMROOT :
    case Axis.ALL :
    case Axis.DESCENDANTSORSELFFROMROOT :
      return BIT_ANY_DESCENDANT_FROM_ROOT;
    case Axis.ROOT :
      return BIT_ROOT;
    case Axis.FILTEREDLIST :
      return BIT_FILTER;
    default :
      return BIT_FILTER;
  }
}
 
Example 20
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Similar to getAxisIterator, but this one returns an iterator
 * containing nodes of a typed axis (ex.: child::foo)
 */
public DTMAxisIterator getTypedAxisIterator(int axis, int type)
{
    // Most common case handled first
    if (axis == Axis.CHILD) {
        return new TypedChildrenIterator(type);
    }

    if (type == NO_TYPE) {
        return(EMPTYITERATOR);
    }

    switch (axis)
    {
        case Axis.SELF:
            return new TypedSingletonIterator(type);
        case Axis.CHILD:
            return new TypedChildrenIterator(type);
        case Axis.PARENT:
            return new ParentIterator().setNodeType(type);
        case Axis.ANCESTOR:
            return new TypedAncestorIterator(type);
        case Axis.ANCESTORORSELF:
            return (new TypedAncestorIterator(type)).includeSelf();
        case Axis.ATTRIBUTE:
            return new TypedAttributeIterator(type);
        case Axis.DESCENDANT:
            return new TypedDescendantIterator(type);
        case Axis.DESCENDANTORSELF:
            return (new TypedDescendantIterator(type)).includeSelf();
        case Axis.FOLLOWING:
            return new TypedFollowingIterator(type);
        case Axis.PRECEDING:
            return new TypedPrecedingIterator(type);
        case Axis.FOLLOWINGSIBLING:
            return new TypedFollowingSiblingIterator(type);
        case Axis.PRECEDINGSIBLING:
            return new TypedPrecedingSiblingIterator(type);
        case Axis.NAMESPACE:
            return  new TypedNamespaceIterator(type);
        case Axis.ROOT:
            return new TypedRootIterator(type);
        default:
            BasisLibrary.runTimeError(BasisLibrary.TYPED_AXIS_SUPPORT_ERR,
                    Axis.getNames(axis));
    }
    return null;
}