1 19 20 package org.apache.cayenne.project; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import org.apache.cayenne.access.DataNode; 26 27 33 public class FlatProjectView { 34 35 protected static FlatProjectView instance = new FlatProjectView(); 36 37 40 public static FlatProjectView getInstance() { 41 return instance; 42 } 43 44 47 public List flattenProjectTree(Object rootNode) { 48 List nodes = new ArrayList (); 49 TraversalHelper helper = new TraversalHelper(nodes); 50 new ProjectTraversal(helper).traverse(rootNode); 51 return nodes; 52 } 53 54 57 class TraversalHelper implements ProjectTraversalHandler { 58 protected List nodes; 59 60 public TraversalHelper(List nodes) { 61 this.nodes = nodes; 62 } 63 64 public void projectNode(ProjectPath path) { 65 nodes.add(path); 66 } 67 68 71 public boolean shouldReadChildren( 72 Object node, 73 ProjectPath parentPath) { 74 return !(node instanceof DataNode); 76 } 77 } 78 } 79 | Popular Tags |