public StringNode asStringNode() { throw new InvalidPathException("Expected string node"); }
public UndefinedNode asUndefinedNode() { throw new InvalidPathException("Expected undefined node"); }
public PathNode asPathNode() { throw new InvalidPathException("Expected path node"); }
public PredicateNode asPredicateNode() { throw new InvalidPathException("Expected predicate node"); }
public static boolean fail(String message) { throw new InvalidPathException(message); } }
public PatternNode asPatternNode() { throw new InvalidPathException("Expected regexp node"); }
public JsonNode asJsonNode() { throw new InvalidPathException("Expected json node"); }
public BooleanNode asBooleanNode() { throw new InvalidPathException("Expected boolean node"); }
public NullNode asNullNode() { throw new InvalidPathException("Expected null node"); }
private static Integer parseInteger(String token) { try { return Integer.parseInt(token); } catch (Exception e){ throw new InvalidPathException("Failed to parse token in ArrayIndexOperation: " + token, e); } } }
public PropertyPathToken(List<String> properties, char stringDelimiter) { if (properties.isEmpty()) { throw new InvalidPathException("Empty properties"); } this.properties = properties; this.stringDelimiter = Character.toString(stringDelimiter); }
public static LogicalOperator fromString(String operatorString){ if(AND.operatorString.equals(operatorString)) return AND; else if(NOT.operatorString.equals(operatorString)) return NOT; else if(OR.operatorString.equals(operatorString)) return OR; else throw new InvalidPathException("Failed to parse operator " + operatorString); } }
public static RelationalOperator fromString(String operatorString){ for (RelationalOperator operator : RelationalOperator.values()) { if(operator.operatorString.equals(operatorString.toUpperCase()) ){ return operator; } } throw new InvalidPathException("Filter operator " + operatorString + " is not supported!"); }
private LogicalOperator readLogicalOperator(){ int begin = filter.skipBlanks().position(); int end = begin+1; if(!filter.inBounds(end)){ throw new InvalidPathException("Expected boolean literal"); } CharSequence logicalOperator = filter.subSequence(begin, end+1); if(!logicalOperator.equals("||") && !logicalOperator.equals("&&")){ throw new InvalidPathException("Expected logical operator"); } filter.incrementPosition(logicalOperator.length()); logger.trace("LogicalOperator from {} to {} -> [{}]", begin, end, logicalOperator); return LogicalOperator.fromString(logicalOperator.toString()); }
public void readSignificantChar(char c) { if (skipBlanks().currentChar() != c) { throw new InvalidPathException(String.format("Expected character: %c", c)); } incrementPosition(1); }
private BooleanNode readBooleanLiteral() { int begin = filter.position(); int end = filter.currentChar() == TRUE ? filter.position() + 3 : filter.position() + 4; if(!filter.inBounds(end)){ throw new InvalidPathException("Expected boolean literal"); } CharSequence boolValue = filter.subSequence(begin, end+1); if(!boolValue.equals("true") && !boolValue.equals("false")){ throw new InvalidPathException("Expected boolean literal"); } filter.incrementPosition(boolValue.length()); logger.trace("BooleanLiteral from {} to {} -> [{}]", begin, end, boolValue); return ValueNode.createBooleanNode(boolValue); }
private NullNode readNullLiteral() { int begin = filter.position(); if(filter.currentChar() == NULL && filter.inBounds(filter.position() + 3)){ CharSequence nullValue = filter.subSequence(filter.position(), filter.position() + 4); if("null".equals(nullValue.toString())){ logger.trace("NullLiteral from {} to {} -> [{}]", begin, filter.position()+3, nullValue); filter.incrementPosition(nullValue.length()); return ValueNode.createNullNode(); } } throw new InvalidPathException("Expected <null> value"); }
private StringNode readStringLiteral(char endChar) { int begin = filter.position(); int closingSingleQuoteIndex = filter.nextIndexOfUnescaped(endChar); if (closingSingleQuoteIndex == -1) { throw new InvalidPathException("String literal does not have matching quotes. Expected " + endChar + " in " + filter); } else { filter.setPosition(closingSingleQuoteIndex + 1); } CharSequence stringLiteral = filter.subSequence(begin, filter.position()); logger.trace("StringLiteral from {} to {} -> [{}]", begin, filter.position(), stringLiteral); return ValueNode.createStringNode(stringLiteral, true); }
private boolean readDotToken(PathTokenAppender appender) { if (path.currentCharIs(PERIOD) && path.nextCharIs(PERIOD)) { appender.appendPathToken(PathTokenFactory.crateScanToken()); path.incrementPosition(2); } else if (!path.hasMoreCharacters()) { throw new InvalidPathException("Path must not end with a '."); } else { path.incrementPosition(1); } if(path.currentCharIs(PERIOD)){ throw new InvalidPathException("Character '.' on position " + path.position() + " is not valid."); } return readNextToken(appender); }
private ValueNode readValueNode() { switch (filter.skipBlanks().currentChar()) { case DOC_CONTEXT : return readPath(); case EVAL_CONTEXT : return readPath(); case NOT: filter.incrementPosition(1); switch (filter.skipBlanks().currentChar()) { case DOC_CONTEXT : return readPath(); case EVAL_CONTEXT : return readPath(); default: throw new InvalidPathException(String.format("Unexpected character: %c", NOT)); } default : return readLiteral(); } }