Package org.sindice.siren.qparser.json

Examples of org.sindice.siren.qparser.json.ParseException


  Integer parse() throws ParseException {
    final JsonNode value = node.path(LEVEL_PROPERTY);
    if (value.isInt()) {
      return value.asInt();
    }
    throw new ParseException("Invalid property '" + LEVEL_PROPERTY + "': value is not an integer");
  }
View Full Code Here


      if (fieldname.equals(BooleanPropertyParser.BOOLEAN_PROPERTY)) {
        final BooleanPropertyParser booleanParser = new BooleanPropertyParser(node, field);
        topNode.add(booleanParser.parse());
        return topNode;
      }
      throw new ParseException("Invalid JSON query: unknown property '" + fieldname + "'");
    }
    catch (final IOException e) {
      throw new ParseException("Invalid JSON query", e);
    }

  }
View Full Code Here

  private String getFirstFieldName(final JsonNode node) throws ParseException {
    final Iterator<String> fieldNames = node.getFieldNames();
    if (fieldNames.hasNext()) {
      return fieldNames.next();
    }
    throw new ParseException("Invalid JSON query: either a node, boolean or twig query must be defined");
  }
View Full Code Here

  Float parse() throws ParseException {
    final JsonNode value = node.path(BOOST_PROPERTY);
    if (value.isFloatingPointNumber()) {
      return (float) value.asDouble();
    }
    throw new ParseException("Invalid property '" + BOOST_PROPERTY + "': value is not a float");
  }
View Full Code Here

  @Override
  ArrayQueryNode parse() throws ParseException {
    final JsonNode value = node.path(CHILD_PROPERTY);
    if (!value.isArray()) {
      throw new ParseException("Invalid property'" + CHILD_PROPERTY + "': value is not an array");
    }

    final ArrayQueryNode arrayNode = new ArrayQueryNode();

    final Iterator<JsonNode> elements = value.getElements();
    while (elements.hasNext()) {
      final JsonNode element = elements.next();

      // parse occur
      final OccurPropertyParser occurParser = new OccurPropertyParser(element, field);
      Modifier mod = null;
      if (occurParser.isPropertyDefined()) {
        mod = occurParser.parse();
      }

      // check if there is either a node or a twig property and parse it
      QueryNode queryNode = null;
      if (element.has(NodePropertyParser.NODE_PROPERTY)) {
        final NodePropertyParser nodeParser = new NodePropertyParser(element, field);
        queryNode = nodeParser.parse();
      }
      if (element.has(TwigPropertyParser.TWIG_PROPERTY)) {
        final TwigPropertyParser twigParser = new TwigPropertyParser(element, field);
        queryNode = twigParser.parse();
      }

      // check if either a node or twig property has been defined
      if (queryNode == null) {
        throw new ParseException("Invalid property'" + CHILD_PROPERTY + "': object does not define a twig or node query");
      }

      // create a child query node and add it to the array query node
      arrayNode.add(new ChildQueryNode(queryNode, mod));
    }
View Full Code Here

  @Override
  ArrayQueryNode parse() throws ParseException {
    final JsonNode value = node.path(DESCENDANT_PROPERTY);
    if (!value.isArray()) {
      throw new ParseException("Invalid property'" + DESCENDANT_PROPERTY + "': value is not an array");
    }

    final ArrayQueryNode arrayNode = new ArrayQueryNode();

    final Iterator<JsonNode> elements = value.getElements();
    while (elements.hasNext()) {
      final JsonNode element = elements.next();

      // parse occur
      final OccurPropertyParser occurParser = new OccurPropertyParser(element, field);
      Modifier mod = null;
      if (occurParser.isPropertyDefined()) {
        mod = occurParser.parse();
      }

      // parse level
      final LevelPropertyParser levelParser = new LevelPropertyParser(element, field);
      int level = -1;
      if (levelParser.isPropertyDefined()) {
        level = levelParser.parse();
      }

      // check if there is either a node or a twig property and parse it
      QueryNode queryNode = null;
      if (element.has(NodePropertyParser.NODE_PROPERTY)) {
        final NodePropertyParser nodeParser = new NodePropertyParser(element, field);
        queryNode = nodeParser.parse();
      }
      if (element.has(TwigPropertyParser.TWIG_PROPERTY)) {
        final TwigPropertyParser twigParser = new TwigPropertyParser(element, field);
        queryNode = twigParser.parse();
      }

      // check if either a node or twig property has been defined
      if (queryNode == null) {
        throw new ParseException("Invalid property'" + DESCENDANT_PROPERTY + "': one array object does not define a twig or node query");
      }

      // create a descendant query node and add it to the array query node
      arrayNode.add(new DescendantQueryNode(queryNode, mod, level));
    }
View Full Code Here

    }
    else {
      if (this.optional) {
        return false;
      }
      throw new ParseException("Missing property '" + this.getProperty() + "'");
    }
  }
View Full Code Here

  int[] parse() throws ParseException {
    final int[] range = new int[2];
    final JsonNode value = node.path(RANGE_PROPERTY);

    if (!(value.isArray() && (value.size() == 2))) {
      throw new ParseException("Invalid value for property '" + RANGE_PROPERTY + "'");
    }

    final Iterator<JsonNode> it = value.iterator();
    JsonNode e;
    for (int i = 0; i < 2; i++) {
      e = it.next();
      if (!e.isInt()) {
        throw new ParseException("Invalid property '" + RANGE_PROPERTY + "': range value is not an integer");
      }
      range[i] = e.asInt();
    }

    return range;
View Full Code Here

  @Override
  BooleanQueryNode parse() throws ParseException {
    final JsonNode value = node.path(BOOLEAN_PROPERTY);
    if (!value.isArray()) {
      throw new ParseException("Invalid property '" + BOOLEAN_PROPERTY + "': value is not an array");
    }

    final BooleanQueryNode booleanNode = new BooleanQueryNode();

    final Iterator<JsonNode> elements = value.getElements();
    while (elements.hasNext()) {
      final JsonNode element = elements.next();

      // parse occur
      final OccurPropertyParser occurParser = new OccurPropertyParser(element, field);
      Modifier mod = null;
      if (occurParser.isPropertyDefined()) {
        mod = occurParser.parse();
      }

      // check if there is either a node or a twig property and parse it
      QueryNode queryNode = null;
      if (element.has(NodePropertyParser.NODE_PROPERTY)) {
        final NodePropertyParser nodeParser = new NodePropertyParser(element, field);
        queryNode = nodeParser.parse();
      }
      if (element.has(TwigPropertyParser.TWIG_PROPERTY)) {
        final TwigPropertyParser twigParser = new TwigPropertyParser(element, field);
        queryNode = twigParser.parse();
      }

      // check if either a node or twig property has been defined
      if (queryNode == null) {
        throw new ParseException("Invalid property '" + BOOLEAN_PROPERTY + "': object does not define a twig or node query");
      }

      // wrap the query node with a modifier, and add it to the boolean query
      booleanNode.add(new ModifierQueryNode(queryNode, mod));
    }
View Full Code Here

  @Override
  Modifier parse() throws ParseException {
    final JsonNode value = node.path(OCCUR_PROPERTY);

    if (!value.isTextual()) {
      throw new ParseException("Invalid property'" + OCCUR_PROPERTY + "': value is not textual");
    }

    try {
      final Occur occur = Occur.valueOf(value.asText());
      switch (occur) {
        case MUST:
          return Modifier.MOD_REQ;

        case SHOULD:
          return Modifier.MOD_NONE;

        case MUST_NOT:
          return Modifier.MOD_NOT;

        default:
          throw new ParseException("Invalid value '" + value.asText() + "' for property '" + OCCUR_PROPERTY + "'");
      }
    }
    catch (final IllegalArgumentException e) {
      throw new ParseException("Invalid value '" + value.asText() + "' for property '" + OCCUR_PROPERTY + "'", e);
    }
  }
View Full Code Here

TOP

Related Classes of org.sindice.siren.qparser.json.ParseException

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.