Java Code Examples for com.sun.org.apache.xpath.internal.objects.XObject#num()

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XObject#num() . 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: StepPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the match score of the given node.
 *
 * @param xctxt The XPath runtime context.
 * @param context The node to be tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public double getMatchScore(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  xctxt.pushCurrentNode(context);
  xctxt.pushCurrentExpressionNode(context);

  try
  {
    XObject score = execute(xctxt);

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
Example 2
Source File: UnionPattern.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches any of the patterns in the union.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject bestScore = null;
  int n = m_patterns.length;

  for (int i = 0; i < n; i++)
  {
    XObject score = m_patterns[i].execute(xctxt);

    if (score != NodeTest.SCORE_NONE)
    {
      if (null == bestScore)
        bestScore = score;
      else if (score.num() > bestScore.num())
        bestScore = score;
    }
  }

  if (null == bestScore)
  {
    bestScore = NodeTest.SCORE_NONE;
  }

  return bestScore;
}
 
Example 3
Source File: XPathExpressionImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException ( fmsg );
}
 
Example 4
Source File: XPath.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the match score of the given node.
 *
 * @param xctxt XPath runtime context.
 * @param context The current source tree context node.
 *
 * @return score, one of {@link #MATCH_SCORE_NODETEST},
 * {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER},
 * or {@link #MATCH_SCORE_QNAME}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public double getMatchScore(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  xctxt.pushCurrentNode(context);
  xctxt.pushCurrentExpressionNode(context);

  try
  {
    XObject score = m_mainExp.execute(xctxt);

    if (DEBUG_MATCHES)
    {
      DTM dtm = xctxt.getDTM(context);
      System.out.println("score: " + score.num() + " for "
                         + dtm.getNodeName(context) + " for xpath "
                         + this.getPatternString());
    }

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
Example 5
Source File: FuncRound.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
Example 6
Source File: StepPattern.java    From jdk8u60 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 7
Source File: StepPattern.java    From jdk1.8-source-analysis 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 8
Source File: StepPattern.java    From JDKSourceCode1.8 with MIT License 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 9
Source File: PredicatedNodeTest.java    From openjdk-jdk9 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: Number.java    From openjdk-jdk8u-backup 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());
}
 
Example 11
Source File: Quo.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber((int) (left.num() / right.num()));
}
 
Example 12
Source File: Neg.java    From TencentKona-8 with GNU General Public License v2.0 2 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
{
  return new XNumber(-right.num());
}
 
Example 13
Source File: Minus.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber(left.num() - right.num());
}
 
Example 14
Source File: Mod.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber(left.num() % right.num());
}
 
Example 15
Source File: Plus.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber(left.num() + right.num());
}
 
Example 16
Source File: Div.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber(left.num() / right.num());
}
 
Example 17
Source File: Mod.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber(left.num() % right.num());
}
 
Example 18
Source File: Quo.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber((int) (left.num() / right.num()));
}
 
Example 19
Source File: Mod.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber(left.num() % right.num());
}
 
Example 20
Source File: Quo.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @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 left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return new XNumber((int) (left.num() / right.num()));
}