Exemplo n.º 1
0
  @XACMLFunction({"urn:oasis:names:tc:xacml:1.0:function:xpath-node-count"})
  public static AttributeValue nodeCount(EvaluationContext ctx, Object[] params)
      throws IndeterminateException {
    checkArguments(params, 1);
    AttributeValue exp = (AttributeValue) params[0];
    checkArgumentType(exp, Constants.TYPE_STRING);
    String xpathExp = (String) exp.getValue();

    try {
      NodeList nList = evaluateXPath(ctx, xpathExp);
      return AttributeValue.getInstance(
          Constants.TYPE_INTEGER, BigInteger.valueOf(nList.getLength()));
    } catch (IndeterminateException intEx) {
      throw intEx;
    } catch (Exception ex) {
      throw new IndeterminateException(
          "Error occurs while evaluating function nodeCount : " + xpathExp);
    }
  }