Interface EntityConditionVisitor
-
public interface EntityConditionVisitor
A visitor of entity conditions in the style of the visitor design pattern.Classes implementing this interface can extend the dynamically dispatched behavior associated with
EntityCondition
without augmenting its interface. Those classes are meant be passed to theaccept
method which calls the corresponding method in the visitor.Usage Examples: Here is a dummy example that should print EntityExpr\n to the standard output.
EntityExpr expr; expr.accept(new EntityConditionVisitor() { public void visit(EntityConditionFunction func) { system.out.println("EntityConditionFunction"); } public <T extends EntityCondition> void visit(EntityConditionList<T> l) { system.out.println("EntityConditionList"); } public void visit(EntityFieldMap m) { system.out.println("EntityFieldMap"); } public void visit(EntityDateFilterCondition df) { system.out.println("EntityDateFilterCondition"); } public void visit(EntityExpr expr) { system.out.println("EntityExpr"); } public void visit(EntityWhereString ws) { system.out.println("EntityWhereString"); } });
Here is a more complex example asserting the presence of a raw string condition even when it is embedded inside another one.
class ContainsRawCondition implements EntityConditionVisitor { public boolean hasRawCondition = false; public void visit(EntityConditionFunction func) {} public void visit(EntityFieldMap m) {} public void visit(EntityDateFilterCondition df) {} public <T extends EntityCondition> void visit(EntityConditionList<T> l) { Iterator<T> it = l.getConditionIterator(); while (it.hasNext()) { it.next().accept(this); } } public void visit(EntityExpr expr) { Object lhs = expr.getLhs(); Object rhs = expr.getRhs(); if (lhs instanceof EntityCondition) { ((EntityCondition) lhs).accept(this); } if (rhs instanceof EntityCondition) { ((EntityCondition) rhs).accept(this); } } public void visit(EntityWhereString ws) { hasRawCondition = true; } } EntityCondition ec = EntityCondition.makeCondition(EntityCondition.makeConditionWhere("foo=bar")); EntityConditionVisitor visitor = new ContainsRawCondition(); ec.accept(visitor); assert visitor.hasRawCondition;
- See Also:
EntityCondition
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
visit(EntityConditionFunction func)
Visits an entity condition function.<T extends EntityCondition>
voidvisit(EntityConditionList<T> l)
Visits a list of entity conditions.void
visit(EntityDateFilterCondition df)
Visits a date filter condition.void
visit(EntityExpr expr)
Visits an entity expression.void
visit(EntityFieldMap m)
Visits a map of entity fields.void
visit(EntityWhereString ws)
Visits a raw string condition.
-
-
-
Method Detail
-
visit
void visit(EntityConditionFunction func)
Visits an entity condition function.- Parameters:
func
- the visited class- See Also:
EntityConditionFunction
-
visit
<T extends EntityCondition> void visit(EntityConditionList<T> l)
Visits a list of entity conditions.- Parameters:
l
- the visited class- See Also:
EntityConditionList
-
visit
void visit(EntityFieldMap m)
Visits a map of entity fields.- Parameters:
m
- the visited class- See Also:
EntityFieldMap
-
visit
void visit(EntityDateFilterCondition df)
Visits a date filter condition.- Parameters:
df
- the visited class- See Also:
EntityDateFilterCondition
-
visit
void visit(EntityExpr expr)
Visits an entity expression.- Parameters:
expr
- the visited class- See Also:
EntityExpr
-
visit
void visit(EntityWhereString ws)
Visits a raw string condition.- Parameters:
ws
- the visited class- See Also:
EntityWhereString
-
-