1 2 25 26 package org.aspectj.ajde.ui; 27 28 import java.io.*; 29 import java.util.*; 30 31 import org.aspectj.asm.StructureModel; 32 33 36 public class BuildConfigModel extends StructureModel { 37 38 private String sourceFile; 39 40 public BuildConfigModel(String sourceFile) { 41 this.sourceFile = sourceFile; 42 } 43 44 48 public BuildConfigNode getNodeForPath(String path) { 49 BuildConfigNode upPathMatch = searchUpPaths(path); 50 if (upPathMatch != null && upPathMatch != root) { 51 return upPathMatch; 52 } else { 53 StringTokenizer st = new StringTokenizer(path, "/"); 54 BuildConfigNode node = (BuildConfigNode)root; 55 return getNodeForPathHelper(st, node); 56 } 57 } 58 59 private BuildConfigNode searchUpPaths(String path) { 60 for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { 61 BuildConfigNode node = (BuildConfigNode)it.next(); 62 if (node.getName().equals(path)) return node; 63 } 64 return null; 65 } 66 67 private BuildConfigNode getNodeForPathHelper(StringTokenizer st, BuildConfigNode node) { 68 BuildConfigNode parent = node; 69 while (st.hasMoreElements()) { 70 String pathItem = (String )st.nextElement(); 71 for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { 72 node = (BuildConfigNode)it.next(); 73 String childName = node.getName(); 74 if (childName.equals(pathItem)) { 75 return getNodeForPathHelper(st, node); 76 } 77 } 78 } 79 return parent; 80 } 81 82 public List getActiveNodes(BuildConfigNode.Kind kind) { 83 List nodes = new ArrayList(); 84 getActiveNodesHelper((BuildConfigNode)getRoot(), kind, nodes); 85 return nodes; 86 } 87 88 private void getActiveNodesHelper(BuildConfigNode node, BuildConfigNode.Kind kind, List nodes) { 89 for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { 90 BuildConfigNode currNode = (BuildConfigNode)it.next(); 91 if (currNode.getBuildConfigNodeKind().equals(kind) 92 && currNode.isActive()) { 93 nodes.add(currNode); 94 } 95 getActiveNodesHelper(currNode, kind, nodes); 96 } 97 } 98 99 public String getSourceFile() { 100 return sourceFile; 101 } 102 103 public void setSourceFile(String sourceFile) { 104 this.sourceFile = sourceFile; 105 } 106 } 107 108 109 | Popular Tags |