Package org.sindice.siren.qparser.json.nodes

Examples of org.sindice.siren.qparser.json.nodes.TwigQueryNode


    this.keywordParser = keywordParser;
  }

  @Override
  public TwigQuery build(final QueryNode queryNode) throws QueryNodeException {
    final TwigQueryNode twigNode = (TwigQueryNode) queryNode;
    final List<QueryNode> children = twigNode.getChildren();
    final TwigQuery query = new TwigQuery();

    // check if the node has a level constraint
    if (twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) {
      query.setLevelConstraint((Integer) twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY));
    }

    // check if the node has a node range constraint
    if (twigNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) {
      final int[] range = (int[]) twigNode.getTag(RangePropertyParser.RANGE_PROPERTY);
      query.setNodeConstraint(range[0], range[1]);
    }

    // process root query
    if (twigNode.hasRoot()) {
      final String rootExpr = twigNode.getRoot().toString();
      final String field = twigNode.getField().toString();
      query.addRoot((NodeQuery) keywordParser.parse(rootExpr, field));
    }

    // process child and descendant queries
    try {
      processChildren(children, query);
    }
    catch (final TooManyClauses ex) {
      throw new QueryNodeException(new MessageImpl(
          QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
          BooleanQuery.getMaxClauseCount(),
          twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
    }

    return query;
  }
View Full Code Here


    return TWIG_PROPERTY;
  }

  @Override
  TwigQueryNode parse() throws ParseException {
    final TwigQueryNode twigNode = new TwigQueryNode();
    twigNode.setField(field);

    final JsonNode objectNode = node.path(this.getProperty());

    final RootPropertyParser rootParser = new RootPropertyParser(objectNode, field);
    rootParser.setOptional(true);
    if (rootParser.isPropertyDefined()) {
      twigNode.setRoot(rootParser.parse());
    }

    final LevelPropertyParser levelParser = new LevelPropertyParser(objectNode, field);
    levelParser.setOptional(true);
    if (levelParser.isPropertyDefined()) {
      twigNode.setTag(levelParser.getProperty(), levelParser.parse());
    }

    final RangePropertyParser rangeParser = new RangePropertyParser(objectNode, field);
    rangeParser.setOptional(true);
    if (rangeParser.isPropertyDefined()) {
      twigNode.setTag(rangeParser.getProperty(), rangeParser.parse());
    }

    final ChildPropertyParser childParser = new ChildPropertyParser(objectNode, field);
    childParser.setOptional(true);
    if (childParser.isPropertyDefined()) {
      final ArrayQueryNode arrayNode = childParser.parse();
      twigNode.add(arrayNode.getChildren());
    }

    final DescendantPropertyParser descendantParser = new DescendantPropertyParser(objectNode, field);
    descendantParser.setOptional(true);
    if (descendantParser.isPropertyDefined()) {
      final ArrayQueryNode arrayNode = descendantParser.parse();
      twigNode.add(arrayNode.getChildren());
    }

    return twigNode;
  }
View Full Code Here

TOP

Related Classes of org.sindice.siren.qparser.json.nodes.TwigQueryNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.