@Override public String toFilter() { boolean leftParens = left instanceof LogicalExpression; boolean rightParens = right instanceof LogicalExpression; String leftString = (leftParens ? "(" : "") + left.toFilter() + (leftParens ? ")" : ""); String rightString = (rightParens ? "(" : "") + right.toFilter() + (rightParens ? ")" : ""); return leftString + " " + operator + " " + rightString; }
@Override public void setAttributePath(String urn, String parentAttributeName) { this.left.setAttributePath(urn, parentAttributeName); this.right.setAttributePath(urn, parentAttributeName); }
@Override public String toUnqualifiedFilter() { return (not ? "NOT" : "") + "(" + filterExpression.toUnqualifiedFilter() + ")"; } }
@Override public String toString() { return expression.toFilter(); } }
@Override public void setAttributePath(String urn, String parentAttributeName) { this.filterExpression.setAttributePath(urn, parentAttributeName); }
@Override public String toUnqualifiedFilter() { boolean leftParens = this.left instanceof LogicalExpression; boolean rightParens = this.right instanceof LogicalExpression; String leftString = (leftParens ? "(" : "") + left.toUnqualifiedFilter() + (leftParens ? ")" : ""); String rightString = (rightParens ? "(" : "") + right.toUnqualifiedFilter() + (rightParens ? ")" : ""); return leftString + " " + operator + " " + rightString; } }
@Override public String toFilter() { return (not ? "NOT" : "") + "(" + filterExpression.toFilter() + ")"; }
@Override public void exitFilterValuePathExpression(FilterValuePathExpressionContext ctx) { String attributePath = ctx.attributePath.getText(); AttributeReference attributeReference = new AttributeReference(attributePath); String urn = attributeReference.getUrn(); String parentAttributeName = attributeReference.getAttributeName(); FilterExpression attributeExpression = (FilterExpression) expressionStack.pop(); ValuePathExpression valuePathExpression = new ValuePathExpression(attributeReference, attributeExpression); attributeExpression.setAttributePath(urn, parentAttributeName); expressionStack.push(valuePathExpression); }
@Override public String toUnqualifiedFilter() { String filter; if (this.attributeExpression != null) { String attributeName = this.attributePath.getAttributeName(); String subAttributeName = this.attributePath.getSubAttributeName(); String attributeExpressionFilter = this.attributeExpression.toUnqualifiedFilter(); if (subAttributeName != null) { filter = attributeName + "[" + attributeExpressionFilter + "]." + subAttributeName; } else { filter = attributeName + "[" + attributeExpressionFilter + "]"; } } else { String subAttributeName = this.attributePath.getSubAttributeName(); filter = this.attributePath.getAttributeName() + (subAttributeName != null ? "." + subAttributeName : ""); } return filter; } }
@Override public String toString() { String filterString = filterExpression.toFilter(); try { return URLEncoder.encode(filterString, "UTF-8").replace("+", "%20"); } catch (UnsupportedEncodingException e) { log.error("Unsupported encoding:", e); return null; } }
@Override public void setAttributePath(String urn, String parentAttributeName) { this.attributePath.setUrn(urn); String subAttributeName = this.attributePath.getAttributeName(); this.attributePath.setAttributeName(parentAttributeName); this.attributePath.setSubAttributeName(subAttributeName); this.attributeExpression.setAttributePath(urn, parentAttributeName); }
@Override public String toFilter() { String filter; if (this.attributeExpression != null) { String subAttributeName = this.attributePath.getSubAttributeName(); String attributeExpressionFilter = this.attributeExpression.toUnqualifiedFilter(); if (subAttributeName != null) { String base = this.attributePath.getAttributeBase(); filter = base + "[" + attributeExpressionFilter + "]." + subAttributeName; } else { String attribute = this.attributePath.getFullyQualifiedAttributeName(); filter = attribute + "[" + attributeExpressionFilter + "]"; } } else { filter = this.attributePath.getFullyQualifiedAttributeName(); } return filter; }
@Override public String marshal(Filter filter) throws Exception { if (filter == null) { return null; } return filter.getExpression().toFilter(); }
@Override public void exitPatchPathFull(PatchPathFullContext ctx) { super.exitPatchPathFull(ctx); String attributePathText = ctx.attributePath.getText(); String subAttributeName = ctx.subAttributeName != null ? ctx.subAttributeName.getText() : null; FilterExpression attributeExpression = expressionStack.pop(); AttributeReference attributePath = new AttributeReference(attributePathText); String urn = attributePath.getUrn(); String parentAttributeName = attributePath.getAttributeName(); attributeExpression.setAttributePath(urn, parentAttributeName); if (subAttributeName != null) { attributePath.setAttributeName(parentAttributeName); attributePath.setSubAttributeName(subAttributeName); } this.valuePathExpression = new ValuePathExpression(attributePath, attributeExpression); }