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

The following examples show how to use com.sun.org.apache.xml.internal.dtm.Axis#ATTRIBUTE . 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: SAXImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Do not think that this returns an iterator for the namespace axis.
 * It returns an iterator with nodes that belong in a certain namespace,
 * such as with <xsl:apply-templates select="blob/foo:*"/>
 * The 'axis' specifies the axis for the base iterator from which the
 * nodes are taken, while 'ns' specifies the namespace URI type.
 */
public DTMAxisIterator getNamespaceAxisIterator(int axis, int ns)
{

    DTMAxisIterator iterator = null;

    if (ns == NO_TYPE) {
        return EMPTYITERATOR;
    }
    else {
        switch (axis) {
            case Axis.CHILD:
                return new NamespaceChildrenIterator(ns);
            case Axis.ATTRIBUTE:
                return new NamespaceAttributeIterator(ns);
            default:
                return new NamespaceWildcardIterator(axis, ns);
        }
    }
}
 
Example 2
Source File: UnionPathExpr.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public void setParser(Parser parser) {
    super.setParser(parser);
    // find all expressions in this Union
    final Vector components = new Vector();
    flatten(components);
    final int size = components.size();
    _components = (Expression[])components.toArray(new Expression[size]);
    for (int i = 0; i < size; i++) {
        _components[i].setParser(parser);
        _components[i].setParent(this);
        if (_components[i] instanceof Step) {
            final Step step = (Step)_components[i];
            final int axis = step.getAxis();
            final int type = step.getNodeType();
            // Put attribute iterators first
            if ((axis == Axis.ATTRIBUTE) || (type == DTM.ATTRIBUTE_NODE)) {
                _components[i] = _components[0];
                _components[0] = step;
            }
            // Check if the union contains a reverse iterator
    if (Axis.isReverse(axis)) _reverse = true;
        }
    }
    // No need to reverse anything if another expression lies on top of this
    if (getParent() instanceof Expression) _reverse = false;
}
 
Example 3
Source File: UnionPathExpr.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void setParser(Parser parser) {
    super.setParser(parser);
    // find all expressions in this Union
    final Vector components = new Vector();
    flatten(components);
    final int size = components.size();
    _components = (Expression[])components.toArray(new Expression[size]);
    for (int i = 0; i < size; i++) {
        _components[i].setParser(parser);
        _components[i].setParent(this);
        if (_components[i] instanceof Step) {
            final Step step = (Step)_components[i];
            final int axis = step.getAxis();
            final int type = step.getNodeType();
            // Put attribute iterators first
            if ((axis == Axis.ATTRIBUTE) || (type == DTM.ATTRIBUTE_NODE)) {
                _components[i] = _components[0];
                _components[0] = step;
            }
            // Check if the union contains a reverse iterator
    if (Axis.isReverse(axis)) _reverse = true;
        }
    }
    // No need to reverse anything if another expression lies on top of this
    if (getParent() instanceof Expression) _reverse = false;
}
 
Example 4
Source File: UnionPathExpr.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void setParser(Parser parser) {
    super.setParser(parser);
    // find all expressions in this Union
    final Vector components = new Vector();
    flatten(components);
    final int size = components.size();
    _components = (Expression[])components.toArray(new Expression[size]);
    for (int i = 0; i < size; i++) {
        _components[i].setParser(parser);
        _components[i].setParent(this);
        if (_components[i] instanceof Step) {
            final Step step = (Step)_components[i];
            final int axis = step.getAxis();
            final int type = step.getNodeType();
            // Put attribute iterators first
            if ((axis == Axis.ATTRIBUTE) || (type == DTM.ATTRIBUTE_NODE)) {
                _components[i] = _components[0];
                _components[0] = step;
            }
            // Check if the union contains a reverse iterator
    if (Axis.isReverse(axis)) _reverse = true;
        }
    }
    // No need to reverse anything if another expression lies on top of this
    if (getParent() instanceof Expression) _reverse = false;
}
 
Example 5
Source File: SAXImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Do not think that this returns an iterator for the namespace axis.
 * It returns an iterator with nodes that belong in a certain namespace,
 * such as with <xsl:apply-templates select="blob/foo:*"/>
 * The 'axis' specifies the axis for the base iterator from which the
 * nodes are taken, while 'ns' specifies the namespace URI type.
 */
public DTMAxisIterator getNamespaceAxisIterator(int axis, int ns)
{
    if (ns == NO_TYPE) {
        return EMPTYITERATOR;
    }
    else {
        switch (axis) {
            case Axis.CHILD:
                return new NamespaceChildrenIterator(ns);
            case Axis.ATTRIBUTE:
                return new NamespaceAttributeIterator(ns);
            default:
                return new NamespaceWildcardIterator(axis, ns);
        }
    }
}
 
Example 6
Source File: SAXImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Do not think that this returns an iterator for the namespace axis.
 * It returns an iterator with nodes that belong in a certain namespace,
 * such as with <xsl:apply-templates select="blob/foo:*"/>
 * The 'axis' specifies the axis for the base iterator from which the
 * nodes are taken, while 'ns' specifies the namespace URI type.
 */
public DTMAxisIterator getNamespaceAxisIterator(int axis, int ns)
{
    if (ns == NO_TYPE) {
        return EMPTYITERATOR;
    }
    else {
        switch (axis) {
            case Axis.CHILD:
                return new NamespaceChildrenIterator(ns);
            case Axis.ATTRIBUTE:
                return new NamespaceAttributeIterator(ns);
            default:
                return new NamespaceWildcardIterator(axis, ns);
        }
    }
}
 
Example 7
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 8
Source File: WalkerFactory.java    From hottub 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 9
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 10
Source File: WalkerFactory.java    From Bytecoder with Apache License 2.0 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 11
Source File: WalkerFactory.java    From TencentKona-8 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 12
Source File: WalkingIteratorSorted.java    From TencentKona-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 13
Source File: SAXImpl.java    From openjdk-jdk9 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;
}
 
Example 14
Source File: Mode.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds a pattern to a pattern group
 */
private void addPattern(int kernelType, LocationPathPattern pattern) {
    // Make sure the array of pattern groups is long enough
    final int oldLength = _patternGroups.length;
    if (kernelType >= oldLength) {
        Vector[] newGroups = new Vector[kernelType * 2];
        System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
        _patternGroups = newGroups;
    }

    // Find the vector to put this pattern into
    Vector patterns;

    if (kernelType == DOM.NO_TYPE) {
        if (pattern.getAxis() == Axis.ATTRIBUTE) {
            patterns = (_attribNodeGroup == null) ?
                (_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
        }
        else {
            patterns = (_childNodeGroup == null) ?
                (_childNodeGroup = new Vector(2)) : _childNodeGroup;
        }
    }
    else {
        patterns = (_patternGroups[kernelType] == null) ?
            (_patternGroups[kernelType] = new Vector(2)) :
            _patternGroups[kernelType];
    }

    if (patterns.size() == 0) {
        patterns.addElement(pattern);
    }
    else {
        boolean inserted = false;
        for (int i = 0; i < patterns.size(); i++) {
            final LocationPathPattern lppToCompare =
                (LocationPathPattern)patterns.elementAt(i);

            if (pattern.noSmallerThan(lppToCompare)) {
                inserted = true;
                patterns.insertElementAt(pattern, i);
                break;
            }
        }
        if (inserted == false) {
            patterns.addElement(pattern);
        }
    }
}
 
Example 15
Source File: SAXImpl.java    From openjdk-8 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;
}
 
Example 16
Source File: Mode.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Adds a pattern to a pattern group
 */
private void addPattern(int kernelType, LocationPathPattern pattern) {
    // Make sure the array of pattern groups is long enough
    final int oldLength = _patternGroups.length;
    if (kernelType >= oldLength) {
        Vector[] newGroups = new Vector[kernelType * 2];
        System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
        _patternGroups = newGroups;
    }

    // Find the vector to put this pattern into
    Vector patterns;

    if (kernelType == DOM.NO_TYPE) {
        if (pattern.getAxis() == Axis.ATTRIBUTE) {
            patterns = (_attribNodeGroup == null) ?
                (_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
        }
        else {
            patterns = (_childNodeGroup == null) ?
                (_childNodeGroup = new Vector(2)) : _childNodeGroup;
        }
    }
    else {
        patterns = (_patternGroups[kernelType] == null) ?
            (_patternGroups[kernelType] = new Vector(2)) :
            _patternGroups[kernelType];
    }

    if (patterns.size() == 0) {
        patterns.addElement(pattern);
    }
    else {
        boolean inserted = false;
        for (int i = 0; i < patterns.size(); i++) {
            final LocationPathPattern lppToCompare =
                (LocationPathPattern)patterns.elementAt(i);

            if (pattern.noSmallerThan(lppToCompare)) {
                inserted = true;
                patterns.insertElementAt(pattern, i);
                break;
            }
        }
        if (inserted == false) {
            patterns.addElement(pattern);
        }
    }
}
 
Example 17
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 18
Source File: Mode.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Adds a pattern to a pattern group
 */
private void addPattern(int kernelType, LocationPathPattern pattern) {
    // Make sure the array of pattern groups is long enough
    final int oldLength = _patternGroups.length;
    if (kernelType >= oldLength) {
        Vector[] newGroups = new Vector[kernelType * 2];
        System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
        _patternGroups = newGroups;
    }

    // Find the vector to put this pattern into
    Vector patterns;

    if (kernelType == DOM.NO_TYPE) {
        if (pattern.getAxis() == Axis.ATTRIBUTE) {
            patterns = (_attribNodeGroup == null) ?
                (_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
        }
        else {
            patterns = (_childNodeGroup == null) ?
                (_childNodeGroup = new Vector(2)) : _childNodeGroup;
        }
    }
    else {
        patterns = (_patternGroups[kernelType] == null) ?
            (_patternGroups[kernelType] = new Vector(2)) :
            _patternGroups[kernelType];
    }

    if (patterns.size() == 0) {
        patterns.addElement(pattern);
    }
    else {
        boolean inserted = false;
        for (int i = 0; i < patterns.size(); i++) {
            final LocationPathPattern lppToCompare =
                (LocationPathPattern)patterns.elementAt(i);

            if (pattern.noSmallerThan(lppToCompare)) {
                inserted = true;
                patterns.insertElementAt(pattern, i);
                break;
            }
        }
        if (inserted == false) {
            patterns.addElement(pattern);
        }
    }
}
 
Example 19
Source File: Mode.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds a pattern to a pattern group
 */
private void addPattern(int kernelType, LocationPathPattern pattern) {
    // Make sure the array of pattern groups is long enough
    final int oldLength = _patternGroups.length;
    if (kernelType >= oldLength) {
        Vector[] newGroups = new Vector[kernelType * 2];
        System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
        _patternGroups = newGroups;
    }

    // Find the vector to put this pattern into
    Vector patterns;

    if (kernelType == DOM.NO_TYPE) {
        if (pattern.getAxis() == Axis.ATTRIBUTE) {
            patterns = (_attribNodeGroup == null) ?
                (_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
        }
        else {
            patterns = (_childNodeGroup == null) ?
                (_childNodeGroup = new Vector(2)) : _childNodeGroup;
        }
    }
    else {
        patterns = (_patternGroups[kernelType] == null) ?
            (_patternGroups[kernelType] = new Vector(2)) :
            _patternGroups[kernelType];
    }

    if (patterns.size() == 0) {
        patterns.addElement(pattern);
    }
    else {
        boolean inserted = false;
        for (int i = 0; i < patterns.size(); i++) {
            final LocationPathPattern lppToCompare =
                (LocationPathPattern)patterns.elementAt(i);

            if (pattern.noSmallerThan(lppToCompare)) {
                inserted = true;
                patterns.insertElementAt(pattern, i);
                break;
            }
        }
        if (inserted == false) {
            patterns.addElement(pattern);
        }
    }
}
 
Example 20
Source File: WalkerFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 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;
  }
}