Java Code Examples for com.sun.org.apache.xpath.internal.objects.XObject#CLASS_NUMBER

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XObject#CLASS_NUMBER . 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: XPathResultImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Given an XObject, determine the corresponding DOM XPath type
   *
   * @return type string
   */
  private short getTypeFromXObject(XObject object) {
      switch (object.getType()) {
        case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
        case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NUMBER: return NUMBER_TYPE;
        case XObject.CLASS_STRING: return STRING_TYPE;
        // XPath 2.0 types
//          case XObject.CLASS_DATE:
//          case XObject.CLASS_DATETIME:
//          case XObject.CLASS_DTDURATION:
//          case XObject.CLASS_GDAY:
//          case XObject.CLASS_GMONTH:
//          case XObject.CLASS_GMONTHDAY:
//          case XObject.CLASS_GYEAR:
//          case XObject.CLASS_GYEARMONTH:
//          case XObject.CLASS_TIME:
//          case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?

        case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
        default: return ANY_TYPE; // throw exception ?
    }

  }
 
Example 2
Source File: XPathResultImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Given an XObject, determine the corresponding DOM XPath type
   *
   * @return type string
   */
  private short getTypeFromXObject(XObject object) {
      switch (object.getType()) {
        case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
        case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NUMBER: return NUMBER_TYPE;
        case XObject.CLASS_STRING: return STRING_TYPE;
        // XPath 2.0 types
//          case XObject.CLASS_DATE:
//          case XObject.CLASS_DATETIME:
//          case XObject.CLASS_DTDURATION:
//          case XObject.CLASS_GDAY:
//          case XObject.CLASS_GMONTH:
//          case XObject.CLASS_GMONTHDAY:
//          case XObject.CLASS_GYEAR:
//          case XObject.CLASS_GYEARMONTH:
//          case XObject.CLASS_TIME:
//          case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?

        case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
        default: return ANY_TYPE; // throw exception ?
    }

  }
 
Example 3
Source File: XPathResultImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Given an XObject, determine the corresponding DOM XPath type
   *
   * @return type string
   */
  private short getTypeFromXObject(XObject object) {
      switch (object.getType()) {
        case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
        case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NUMBER: return NUMBER_TYPE;
        case XObject.CLASS_STRING: return STRING_TYPE;
        // XPath 2.0 types
//          case XObject.CLASS_DATE:
//          case XObject.CLASS_DATETIME:
//          case XObject.CLASS_DTDURATION:
//          case XObject.CLASS_GDAY:
//          case XObject.CLASS_GMONTH:
//          case XObject.CLASS_GMONTHDAY:
//          case XObject.CLASS_GYEAR:
//          case XObject.CLASS_GYEARMONTH:
//          case XObject.CLASS_TIME:
//          case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?

        case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
        default: return ANY_TYPE; // throw exception ?
    }

  }
 
Example 4
Source File: XPathResultImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read the internal result object and return the value in accordance with
 * the type specified.
 *
 * @param <T> The expected class type.
 * @param resultObject internal XPath result object
 * @param type the class type
 * @return The value of the result, null in case of unexpected type.
 * @throws TransformerException  if there is an error reading the XPath
 * result.
 */
static <T> T getValue(XObject resultObject, Class<T> type) throws TransformerException {
    Objects.requireNonNull(type);
    if (type.isAssignableFrom(XPathEvaluationResult.class)) {
        return type.cast(new XPathResultImpl<T>(resultObject, type));
    }
    int resultType = classToInternalType(type);
    switch (resultType) {
        case XObject.CLASS_BOOLEAN:
            return type.cast(resultObject.bool());
        case XObject.CLASS_NUMBER:
            if (Double.class.isAssignableFrom(type)) {
                return type.cast(resultObject.num());
            } else if (Integer.class.isAssignableFrom(type)) {
                return type.cast((int)resultObject.num());
            } else if (Long.class.isAssignableFrom(type)) {
                return type.cast((long)resultObject.num());
            }
            /*
              This is to suppress warnings. By the current specification,
            among numeric types, only Double, Integer and Long are supported.
            */
            break;
        case XObject.CLASS_STRING:
            return type.cast(resultObject.str());
        case XObject.CLASS_NODESET:
            XPathNodes nodeSet = new XPathNodesImpl(resultObject.nodelist(),
                    Node.class);
            return type.cast(nodeSet);
        case XObject.CLASS_RTREEFRAG:  //NODE
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            return type.cast(ni.nextNode());
    }

    return null;
}
 
Example 5
Source File: XPathResultImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Map the specified class type to the internal result type
 *
 * @param <T> The expected class type.
 * @param type the class type
 * @return the internal XObject type.
 */
static <T> int classToInternalType(Class<T> type) {
    if (type.isAssignableFrom(Boolean.class)) {
        return XObject.CLASS_BOOLEAN;
    } else if (Number.class.isAssignableFrom(type)) {
        return XObject.CLASS_NUMBER;
    } else if (type.isAssignableFrom(String.class)) {
        return XObject.CLASS_STRING;
    } else if (type.isAssignableFrom(XPathNodes.class)) {
        return XObject.CLASS_NODESET;
    } else if (type.isAssignableFrom(Node.class)) {
        return XObject.CLASS_RTREEFRAG;
    }
    return XObject.CLASS_NULL;
}
 
Example 6
Source File: StepPattern.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * New Method to check whether the current node satisfies a position predicate
 *
 * @param xctxt The XPath runtime context.
 * @param predPos Which predicate we're evaluating of foo[1][2][3].
 * @param dtm The DTM of the current node.
 * @param context The currentNode.
 * @param pos The position being requested, i.e. the value returned by
 *            m_predicates[predPos].execute(xctxt).
 *
 * @return true of the position of the context matches pos, false otherwise.
 */
private final boolean checkProximityPosition(XPathContext xctxt,
        int predPos, DTM dtm, int context, int pos)
{

  try
  {
    DTMAxisTraverser traverser =
      dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);

    for (int child = traverser.first(context); DTM.NULL != child;
            child = traverser.next(context, child))
    {
      try
      {
        xctxt.pushCurrentNode(child);

        if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
        {
          boolean pass = true;

          try
          {
            xctxt.pushSubContextList(this);

            for (int i = 0; i < predPos; i++)
            {
              xctxt.pushPredicatePos(i);
              try
              {
                XObject pred = m_predicates[i].execute(xctxt);

                try
                {
                  if (XObject.CLASS_NUMBER == pred.getType())
                  {
                    throw new Error("Why: Should never have been called");
                  }
                  else if (!pred.boolWithSideEffects())
                  {
                    pass = false;

                    break;
                  }
                }
                finally
                {
                  pred.detach();
                }
              }
              finally
              {
                xctxt.popPredicatePos();
              }
            }
          }
          finally
          {
            xctxt.popSubContextList();
          }

          if (pass)
            pos--;

          if (pos < 1)
            return false;
        }
      }
      finally
      {
        xctxt.popCurrentNode();
      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: should keep throw sax exception...
    throw new java.lang.RuntimeException(se.getMessage());
  }

  return (pos == 1);
}
 
Example 7
Source File: StepPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * New Method to check whether the current node satisfies a position predicate
 *
 * @param xctxt The XPath runtime context.
 * @param predPos Which predicate we're evaluating of foo[1][2][3].
 * @param dtm The DTM of the current node.
 * @param context The currentNode.
 * @param pos The position being requested, i.e. the value returned by
 *            m_predicates[predPos].execute(xctxt).
 *
 * @return true of the position of the context matches pos, false otherwise.
 */
private final boolean checkProximityPosition(XPathContext xctxt,
        int predPos, DTM dtm, int context, int pos)
{

  try
  {
    DTMAxisTraverser traverser =
      dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);

    for (int child = traverser.first(context); DTM.NULL != child;
            child = traverser.next(context, child))
    {
      try
      {
        xctxt.pushCurrentNode(child);

        if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
        {
          boolean pass = true;

          try
          {
            xctxt.pushSubContextList(this);

            for (int i = 0; i < predPos; i++)
            {
              xctxt.pushPredicatePos(i);
              try
              {
                XObject pred = m_predicates[i].execute(xctxt);

                try
                {
                  if (XObject.CLASS_NUMBER == pred.getType())
                  {
                    throw new Error("Why: Should never have been called");
                  }
                  else if (!pred.boolWithSideEffects())
                  {
                    pass = false;

                    break;
                  }
                }
                finally
                {
                  pred.detach();
                }
              }
              finally
              {
                xctxt.popPredicatePos();
              }
            }
          }
          finally
          {
            xctxt.popSubContextList();
          }

          if (pass)
            pos--;

          if (pos < 1)
            return false;
        }
      }
      finally
      {
        xctxt.popCurrentNode();
      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: should keep throw sax exception...
    throw new java.lang.RuntimeException(se.getMessage());
  }

  return (pos == 1);
}
 
Example 8
Source File: PredicatedNodeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 9
Source File: PredicatedNodeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 10
Source File: PredicatedNodeTest.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 11
Source File: StepPattern.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * New Method to check whether the current node satisfies a position predicate
 *
 * @param xctxt The XPath runtime context.
 * @param predPos Which predicate we're evaluating of foo[1][2][3].
 * @param dtm The DTM of the current node.
 * @param context The currentNode.
 * @param pos The position being requested, i.e. the value returned by
 *            m_predicates[predPos].execute(xctxt).
 *
 * @return true of the position of the context matches pos, false otherwise.
 */
private final boolean checkProximityPosition(XPathContext xctxt,
        int predPos, DTM dtm, int context, int pos)
{

  try
  {
    DTMAxisTraverser traverser =
      dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);

    for (int child = traverser.first(context); DTM.NULL != child;
            child = traverser.next(context, child))
    {
      try
      {
        xctxt.pushCurrentNode(child);

        if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
        {
          boolean pass = true;

          try
          {
            xctxt.pushSubContextList(this);

            for (int i = 0; i < predPos; i++)
            {
              xctxt.pushPredicatePos(i);
              try
              {
                XObject pred = m_predicates[i].execute(xctxt);

                try
                {
                  if (XObject.CLASS_NUMBER == pred.getType())
                  {
                    throw new Error("Why: Should never have been called");
                  }
                  else if (!pred.boolWithSideEffects())
                  {
                    pass = false;

                    break;
                  }
                }
                finally
                {
                  pred.detach();
                }
              }
              finally
              {
                xctxt.popPredicatePos();
              }
            }
          }
          finally
          {
            xctxt.popSubContextList();
          }

          if (pass)
            pos--;

          if (pos < 1)
            return false;
        }
      }
      finally
      {
        xctxt.popCurrentNode();
      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: should keep throw sax exception...
    throw new java.lang.RuntimeException(se.getMessage());
  }

  return (pos == 1);
}
 
Example 12
Source File: StepPattern.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * New Method to check whether the current node satisfies a position predicate
 *
 * @param xctxt The XPath runtime context.
 * @param predPos Which predicate we're evaluating of foo[1][2][3].
 * @param dtm The DTM of the current node.
 * @param context The currentNode.
 * @param pos The position being requested, i.e. the value returned by
 *            m_predicates[predPos].execute(xctxt).
 *
 * @return true of the position of the context matches pos, false otherwise.
 */
private final boolean checkProximityPosition(XPathContext xctxt,
        int predPos, DTM dtm, int context, int pos)
{

  try
  {
    DTMAxisTraverser traverser =
      dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);

    for (int child = traverser.first(context); DTM.NULL != child;
            child = traverser.next(context, child))
    {
      try
      {
        xctxt.pushCurrentNode(child);

        if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
        {
          boolean pass = true;

          try
          {
            xctxt.pushSubContextList(this);

            for (int i = 0; i < predPos; i++)
            {
              xctxt.pushPredicatePos(i);
              try
              {
                XObject pred = m_predicates[i].execute(xctxt);

                try
                {
                  if (XObject.CLASS_NUMBER == pred.getType())
                  {
                    throw new Error("Why: Should never have been called");
                  }
                  else if (!pred.boolWithSideEffects())
                  {
                    pass = false;

                    break;
                  }
                }
                finally
                {
                  pred.detach();
                }
              }
              finally
              {
                xctxt.popPredicatePos();
              }
            }
          }
          finally
          {
            xctxt.popSubContextList();
          }

          if (pass)
            pos--;

          if (pos < 1)
            return false;
        }
      }
      finally
      {
        xctxt.popCurrentNode();
      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: should keep throw sax exception...
    throw new java.lang.RuntimeException(se.getMessage());
  }

  return (pos == 1);
}
 
Example 13
Source File: StepPattern.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute the predicates on this step to determine if the current node
 * should be filtered or accepted.
 *
 * @param xctxt The XPath runtime context.
 * @param dtm The DTM of the current node.
 * @param currentNode The current node context.
 *
 * @return true if the node should be accepted, false otherwise.
 *
 * @throws javax.xml.transform.TransformerException
 */
protected final boolean executePredicates(
        XPathContext xctxt, DTM dtm, int currentNode)
          throws javax.xml.transform.TransformerException
{

  boolean result = true;
  boolean positionAlreadySeen = false;
  int n = getPredicateCount();

  try
  {
    xctxt.pushSubContextList(this);

    for (int i = 0; i < n; i++)
    {
      xctxt.pushPredicatePos(i);

      try
      {
        XObject pred = m_predicates[i].execute(xctxt);

        try
        {
          if (XObject.CLASS_NUMBER == pred.getType())
          {
            int pos = (int) pred.num();

            if (positionAlreadySeen)
            {
              result = (pos == 1);

              break;
            }
            else
            {
              positionAlreadySeen = true;

              if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
              {
                result = false;

                break;
              }
            }

          }
          else if (!pred.boolWithSideEffects())
          {
            result = false;

            break;
          }
        }
        finally
        {
          pred.detach();
        }
      }
      finally
      {
        xctxt.popPredicatePos();
      }
    }
  }
  finally
  {
    xctxt.popSubContextList();
  }

  return result;
}
 
Example 14
Source File: StepPattern.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute the predicates on this step to determine if the current node
 * should be filtered or accepted.
 *
 * @param xctxt The XPath runtime context.
 * @param dtm The DTM of the current node.
 * @param currentNode The current node context.
 *
 * @return true if the node should be accepted, false otherwise.
 *
 * @throws javax.xml.transform.TransformerException
 */
protected final boolean executePredicates(
        XPathContext xctxt, DTM dtm, int currentNode)
          throws javax.xml.transform.TransformerException
{

  boolean result = true;
  boolean positionAlreadySeen = false;
  int n = getPredicateCount();

  try
  {
    xctxt.pushSubContextList(this);

    for (int i = 0; i < n; i++)
    {
      xctxt.pushPredicatePos(i);

      try
      {
        XObject pred = m_predicates[i].execute(xctxt);

        try
        {
          if (XObject.CLASS_NUMBER == pred.getType())
          {
            int pos = (int) pred.num();

            if (positionAlreadySeen)
            {
              result = (pos == 1);

              break;
            }
            else
            {
              positionAlreadySeen = true;

              if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
              {
                result = false;

                break;
              }
            }

          }
          else if (!pred.boolWithSideEffects())
          {
            result = false;

            break;
          }
        }
        finally
        {
          pred.detach();
        }
      }
      finally
      {
        xctxt.popPredicatePos();
      }
    }
  }
  finally
  {
    xctxt.popSubContextList();
  }

  return result;
}
 
Example 15
Source File: StepPattern.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute the predicates on this step to determine if the current node
 * should be filtered or accepted.
 *
 * @param xctxt The XPath runtime context.
 * @param dtm The DTM of the current node.
 * @param currentNode The current node context.
 *
 * @return true if the node should be accepted, false otherwise.
 *
 * @throws javax.xml.transform.TransformerException
 */
protected final boolean executePredicates(
        XPathContext xctxt, DTM dtm, int currentNode)
          throws javax.xml.transform.TransformerException
{

  boolean result = true;
  boolean positionAlreadySeen = false;
  int n = getPredicateCount();

  try
  {
    xctxt.pushSubContextList(this);

    for (int i = 0; i < n; i++)
    {
      xctxt.pushPredicatePos(i);

      try
      {
        XObject pred = m_predicates[i].execute(xctxt);

        try
        {
          if (XObject.CLASS_NUMBER == pred.getType())
          {
            int pos = (int) pred.num();

            if (positionAlreadySeen)
            {
              result = (pos == 1);

              break;
            }
            else
            {
              positionAlreadySeen = true;

              if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
              {
                result = false;

                break;
              }
            }

          }
          else if (!pred.boolWithSideEffects())
          {
            result = false;

            break;
          }
        }
        finally
        {
          pred.detach();
        }
      }
      finally
      {
        xctxt.popPredicatePos();
      }
    }
  }
  finally
  {
    xctxt.popSubContextList();
  }

  return result;
}
 
Example 16
Source File: StepPattern.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * New Method to check whether the current node satisfies a position predicate
 *
 * @param xctxt The XPath runtime context.
 * @param predPos Which predicate we're evaluating of foo[1][2][3].
 * @param dtm The DTM of the current node.
 * @param context The currentNode.
 * @param pos The position being requested, i.e. the value returned by
 *            m_predicates[predPos].execute(xctxt).
 *
 * @return true of the position of the context matches pos, false otherwise.
 */
private final boolean checkProximityPosition(XPathContext xctxt,
        int predPos, DTM dtm, int context, int pos)
{

  try
  {
    DTMAxisTraverser traverser =
      dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);

    for (int child = traverser.first(context); DTM.NULL != child;
            child = traverser.next(context, child))
    {
      try
      {
        xctxt.pushCurrentNode(child);

        if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
        {
          boolean pass = true;

          try
          {
            xctxt.pushSubContextList(this);

            for (int i = 0; i < predPos; i++)
            {
              xctxt.pushPredicatePos(i);
              try
              {
                XObject pred = m_predicates[i].execute(xctxt);

                try
                {
                  if (XObject.CLASS_NUMBER == pred.getType())
                  {
                    throw new Error("Why: Should never have been called");
                  }
                  else if (!pred.boolWithSideEffects())
                  {
                    pass = false;

                    break;
                  }
                }
                finally
                {
                  pred.detach();
                }
              }
              finally
              {
                xctxt.popPredicatePos();
              }
            }
          }
          finally
          {
            xctxt.popSubContextList();
          }

          if (pass)
            pos--;

          if (pos < 1)
            return false;
        }
      }
      finally
      {
        xctxt.popCurrentNode();
      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: should keep throw sax exception...
    throw new java.lang.RuntimeException(se.getMessage());
  }

  return (pos == 1);
}
 
Example 17
Source File: PredicatedNodeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 18
Source File: StepPattern.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the predicates on this step to determine if the current node
 * should be filtered or accepted.
 *
 * @param xctxt The XPath runtime context.
 * @param dtm The DTM of the current node.
 * @param currentNode The current node context.
 *
 * @return true if the node should be accepted, false otherwise.
 *
 * @throws javax.xml.transform.TransformerException
 */
protected final boolean executePredicates(
        XPathContext xctxt, DTM dtm, int currentNode)
          throws javax.xml.transform.TransformerException
{

  boolean result = true;
  boolean positionAlreadySeen = false;
  int n = getPredicateCount();

  try
  {
    xctxt.pushSubContextList(this);

    for (int i = 0; i < n; i++)
    {
      xctxt.pushPredicatePos(i);

      try
      {
        XObject pred = m_predicates[i].execute(xctxt);

        try
        {
          if (XObject.CLASS_NUMBER == pred.getType())
          {
            int pos = (int) pred.num();

            if (positionAlreadySeen)
            {
              result = (pos == 1);

              break;
            }
            else
            {
              positionAlreadySeen = true;

              if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
              {
                result = false;

                break;
              }
            }

          }
          else if (!pred.boolWithSideEffects())
          {
            result = false;

            break;
          }
        }
        finally
        {
          pred.detach();
        }
      }
      finally
      {
        xctxt.popPredicatePos();
      }
    }
  }
  finally
  {
    xctxt.popSubContextList();
  }

  return result;
}
 
Example 19
Source File: PredicatedNodeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }

        // If there is a proximity index that will not change during the
        // course of itteration, then we know there can be no more true
        // occurances of this predicate, so flag that we're done after
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}
 
Example 20
Source File: Number.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param right non-null reference to the evaluated right operand.
 *
 * @return non-null reference to the XObject that represents the result of the operation.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject operate(XObject right) throws javax.xml.transform.TransformerException
{

  if (XObject.CLASS_NUMBER == right.getType())
    return right;
  else
    return new XNumber(right.num());
}