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 the accept 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(EntityNotCondition cond) {
              system.out.println("EntityNotCondition");
         }

         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(EntityNotCondition cond) {}
         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: