1 19 20 package org.apache.cayenne.util; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.apache.cayenne.project.ProjectPath; 26 27 33 public class BaseTreeVisitor implements HierarchicalTreeVisitor { 35 36 protected Map childVisitors; 37 protected boolean terminatingOnNoChildVisitor; 38 39 public BaseTreeVisitor() { 40 this.terminatingOnNoChildVisitor = true; 41 } 42 43 public boolean isTerminatingOnNoChildVisitor() { 44 return terminatingOnNoChildVisitor; 45 } 46 47 public void setTerminatingOnNoChildVisitor(boolean terminatingOnNoChildVisitor) { 48 this.terminatingOnNoChildVisitor = terminatingOnNoChildVisitor; 49 } 50 51 public HierarchicalTreeVisitor childVisitor(ProjectPath path, Class childType) { 52 if (childVisitors == null) { 53 return terminatingOnNoChildVisitor ? null : this; 54 } 55 56 HierarchicalTreeVisitor childVisitor = (HierarchicalTreeVisitor) childVisitors 57 .get(childType.getName()); 58 return childVisitor != null ? childVisitor : terminatingOnNoChildVisitor 59 ? null 60 : this; 61 } 62 63 public void onFinishNode(ProjectPath path) { 64 } 65 66 public boolean onStartNode(ProjectPath path) { 67 return true; 68 } 69 70 public void addChildVisitor(Class childClass, HierarchicalTreeVisitor visitor) { 71 if (childVisitors == null) { 72 childVisitors = new HashMap (); 73 } 74 75 childVisitors.put(childClass.getName(), visitor); 76 } 77 } 78 | Popular Tags |