/**
  * Return the Java value corresponding to an XPath result.
  *
  * @param xo the XPath type
  * @return the corresponding Java value per the JSTL mapping rules
  * @throws TransformerException if there was a problem converting the type
  */
 static Object coerceToJava(XObject xo) throws TransformerException {
   if (xo instanceof XBoolean) {
     return xo.bool();
   } else if (xo instanceof XNumber) {
     return xo.num();
   } else if (xo instanceof XString) {
     return xo.str();
   } else if (xo instanceof XNodeSet) {
     NodeList nodes = xo.nodelist();
     // if there is only one node in the nodeset return it rather than the list
     if (nodes.getLength() == 1) {
       return nodes.item(0);
     } else {
       return nodes;
     }
   } else {
     // unexpected result type
     throw new AssertionError();
   }
 }
Beispiel #2
0
  /**
   * 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;
  }