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

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XObject#bool() . 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: XPathImplUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get result depending on the QName type defined in XPathConstants
 * @param resultObject the result of an evaluation
 * @param returnType the return type
 * @return result per the return type
 * @throws TransformerException if the result can not be converted to
 * the specified return type.
 */
Object getResultAsType(XObject resultObject, QName returnType)
    throws TransformerException {
    // XPathConstants.STRING
    if (returnType.equals(XPathConstants.STRING)) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if (returnType.equals(XPathConstants.NUMBER)) {
        return resultObject.num();
    }
    // XPathConstants.BOOLEAN
    if (returnType.equals(XPathConstants.BOOLEAN)) {
        return 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 2
Source File: And.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example 3
Source File: Or.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example 4
Source File: And.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example 5
Source File: XPathExpressionImpl.java    From TencentKona-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 6
Source File: Or.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example 7
Source File: And.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example 8
Source File: Or.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example 9
Source File: XPathImpl.java    From JDKSourceCode1.8 with MIT License 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();
    }
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException( fmsg );
}
 
Example 10
Source File: XPathResultImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Read the XObject and set values in accordance with the result type
 * @param resultObject  internal XPath result object
 * @throws TransformerException  if there is an error reading the XPath
 * result.
 */
private void getResult(XObject resultObject) throws TransformerException {
    switch (resultType) {
        case XObject.CLASS_BOOLEAN:
            boolValue = resultObject.bool();
            mapToType = XPathResultType.BOOLEAN;
            break;
        case XObject.CLASS_NUMBER:
            numValue = resultObject.num();
            mapToType = XPathResultType.NUMBER;
            break;
        case XObject.CLASS_STRING:
            strValue = resultObject.str();
            mapToType = XPathResultType.STRING;
            break;
        case XObject.CLASS_NODESET:
            mapToType = XPathResultType.NODESET;
            nodeList = resultObject.nodelist();
            break;
        case XObject.CLASS_RTREEFRAG:  //NODE
            mapToType = XPathResultType.NODE;
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            node = ni.nextNode();
            break;
    }
}
 
Example 11
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 12
Source File: PredicatedNodeTest.java    From jdk1.8-source-analysis 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 13
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 14
Source File: Bool.java    From Bytecoder with Apache License 2.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_BOOLEAN == right.getType())
    return right;
  else
    return right.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example 15
Source File: XalanXPathAPI.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Evaluate an XPath string and return true if the output is to be included or not.
 *  @param contextNode The node to start searching from.
 *  @param xpathnode The XPath node
 *  @param str The XPath expression
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 */
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
    throws TransformerException {
    XObject object = eval(contextNode, xpathnode, str, namespaceNode);
    return object.bool();
}
 
Example 16
Source File: XalanXPathAPI.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Evaluate an XPath string and return true if the output is to be included or not.
 *  @param contextNode The node to start searching from.
 *  @param xpathnode The XPath node
 *  @param str The XPath expression
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 */
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
    throws TransformerException {
    XObject object = eval(contextNode, xpathnode, str, namespaceNode);
    return object.bool();
}
 
Example 17
Source File: XalanXPathAPI.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Evaluate an XPath string and return true if the output is to be included or not.
 *  @param contextNode The node to start searching from.
 *  @param xpathnode The XPath node
 *  @param str The XPath expression
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 */
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
    throws TransformerException {
    XObject object = eval(contextNode, xpathnode, str, namespaceNode);
    return object.bool();
}
 
Example 18
Source File: XalanXPathAPI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Evaluate an XPath string and return true if the output is to be included or not.
 *  @param contextNode The node to start searching from.
 *  @param xpathnode The XPath node
 *  @param str The XPath expression
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 */
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
    throws TransformerException {
    XObject object = eval(contextNode, xpathnode, str, namespaceNode);
    return object.bool();
}
 
Example 19
Source File: XalanXPathAPI.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Evaluate an XPath string and return true if the output is to be included or not.
 *  @param contextNode The node to start searching from.
 *  @param xpathnode The XPath node
 *  @param str The XPath expression
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 */
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
    throws TransformerException {
    XObject object = eval(contextNode, xpathnode, str, namespaceNode);
    return object.bool();
}
 
Example 20
Source File: XalanXPathAPI.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Evaluate an XPath string and return true if the output is to be included or not.
 *  @param contextNode The node to start searching from.
 *  @param xpathnode The XPath node
 *  @param str The XPath expression
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 */
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
    throws TransformerException {
    XObject object = eval(contextNode, xpathnode, str, namespaceNode);
    return object.bool();
}