Exemplo n.º 1
0
  private Trail handleDefaultChild(Trail trail, Node node, EvaluationContext context) {

    // "The defaultChild missing value strategy requires the presence of the defaultChild attribute
    // in every non-leaf Node"
    String defaultChild = node.getDefaultChild();
    if (defaultChild == null) {
      throw new InvalidFeatureException(node);
    }

    trail.addMissingLevel();

    List<Node> children = node.getNodes();
    for (int i = 0, max = children.size(); i < max; i++) {
      Node child = children.get(i);

      String id = child.getId();
      if (id != null && (id).equals(defaultChild)) {
        // The predicate of the referenced Node is not evaluated
        return handleTrue(trail, child, context);
      }
    }

    // "Only Nodes which are immediate children of the respective Node can be referenced"
    throw new InvalidFeatureException(node);
  }
Exemplo n.º 2
0
  private Trail handleTrue(Trail trail, Node node, EvaluationContext context) {

    // A "true" leaf node
    if (!node.hasNodes()) {
      return trail.selectNode(node);
    }

    trail.push(node);

    List<Node> children = node.getNodes();
    for (int i = 0, max = children.size(); i < max; i++) {
      Node child = children.get(i);

      Boolean status = evaluateNode(trail, child, context);

      if (status == null) {
        Trail destination = handleMissingValue(trail, node, child, context);

        if (destination != null) {
          return destination;
        }
      } else if (status.booleanValue()) {
        return handleTrue(trail, child, context);
      }
    }

    // A "true" non-leaf node
    return handleNoTrueChild(trail);
  }
Exemplo n.º 3
0
            private ImmutableBiMap.Builder<String, Node> collectNodes(
                Node node, AtomicInteger index, ImmutableBiMap.Builder<String, Node> builder) {
              builder = EntityUtil.put(node, index, builder);

              if (!node.hasNodes()) {
                return builder;
              }

              List<Node> children = node.getNodes();
              for (Node child : children) {
                builder = collectNodes(child, index, builder);
              }

              return builder;
            }