private FilterImpl parse_and() { int lookahead = pos; skipWhiteSpace(); if (filterChars[pos] != '(') { pos = lookahead - 1; return parse_item(); } List<FilterImpl> operands = new ArrayList<FilterImpl>(10); while (filterChars[pos] == '(') { FilterImpl child = parse_filter(); operands.add(child); } return new FilterImpl(FilterImpl.AND, null, operands.toArray(new FilterImpl[operands.size()])); }
private FilterImpl parse_filter() { FilterImpl filter; skipWhiteSpace(); if (filterChars[pos] != '(') { throw new IllegalArgumentException("Missing '(' in: " + filterstring); } pos++; filter = parse_filtercomp(); skipWhiteSpace(); if (filterChars[pos] != ')') { throw new IllegalArgumentException("Missing ')' in: " + filterstring); } pos++; skipWhiteSpace(); return filter; }
private FilterImpl parse_item() { String attr = parse_attr(); skipWhiteSpace(); if (filterChars[pos + 1] == '=') { pos += 2; return new FilterImpl(FilterImpl.APPROX, attr, parse_value()); if (filterChars[pos + 1] == '=') { pos += 2; return new FilterImpl(FilterImpl.GREATER, attr, parse_value()); if (filterChars[pos + 1] == '=') { pos += 2; return new FilterImpl(FilterImpl.LESS, attr, parse_value()); int oldpos = pos; pos += 2; skipWhiteSpace(); if (filterChars[pos] == ')') { return new FilterImpl(FilterImpl.PRESENT, attr, null); Object string = parse_substring();
private FilterImpl parse_filtercomp() { skipWhiteSpace(); char c = filterChars[pos]; switch (c) { case '&' : { pos++; return parse_and(); } case '|' : { pos++; return parse_or(); } case '!' : { pos++; return parse_not(); } } return parse_item(); }
/** * Constructs a {@link FilterImpl} object. This filter object may be * used to match a {@link ServiceReference} or a Dictionary. * * <p> * If the filter cannot be parsed, an {@link InvalidSyntaxException} * will be thrown with a human readable message where the filter became * unparsable. * * @param filterString the filter string. * @If the filter parameter contains an * invalid filter string that cannot be parsed. */ static FilterImpl newInstance(String filterString) { return new Parser(filterString).parse(); }
private FilterImpl parse_or() { int lookahead = pos; skipWhiteSpace(); if (filterChars[pos] != '(') { pos = lookahead - 1; return parse_item(); } List<FilterImpl> operands = new ArrayList<FilterImpl>(10); while (filterChars[pos] == '(') { FilterImpl child = parse_filter(); operands.add(child); } return new FilterImpl(FilterImpl.OR, null, operands.toArray(new FilterImpl[operands.size()])); }
FilterImpl parse() { FilterImpl filter; try { filter = parse_filter(); } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("Filter ended abruptly: " + filterstring, e); } if (pos != filterChars.length) { throw new IllegalArgumentException("Extraneous trailing characters in: " + filterstring); } return filter; }
private FilterImpl parse_not() { int lookahead = pos; skipWhiteSpace(); if (filterChars[pos] != '(') { pos = lookahead - 1; return parse_item(); } FilterImpl child = parse_filter(); return new FilterImpl(FilterImpl.NOT, null, child); }