1 56 package org.objectstyle.cayenne.project; 57 58 import java.util.ArrayList ; 59 import java.util.List ; 60 61 import org.objectstyle.cayenne.access.DataNode; 62 63 69 public class FlatProjectView { 70 71 protected static FlatProjectView instance = new FlatProjectView(); 72 73 76 public static FlatProjectView getInstance() { 77 return instance; 78 } 79 80 83 public List flattenProjectTree(Object rootNode) { 84 List nodes = new ArrayList (); 85 TraversalHelper helper = new TraversalHelper(nodes); 86 new ProjectTraversal(helper).traverse(rootNode); 87 return nodes; 88 } 89 90 93 class TraversalHelper implements ProjectTraversalHandler { 94 protected List nodes; 95 96 public TraversalHelper(List nodes) { 97 this.nodes = nodes; 98 } 99 100 public void projectNode(ProjectPath path) { 101 nodes.add(path); 102 } 103 104 107 public boolean shouldReadChildren( 108 Object node, 109 ProjectPath parentPath) { 110 return !(node instanceof DataNode); 112 } 113 } 114 } 115 | Popular Tags |