KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > BuildConfigModel


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

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 /**
34  * @author Mik Kersten
35  */

36 public class BuildConfigModel extends StructureModel {
37
38     private String JavaDoc sourceFile;
39      
40     public BuildConfigModel(String JavaDoc sourceFile) {
41         this.sourceFile = sourceFile;
42     }
43
44     /**
45      * @param path java.io.File.separator delimited path
46      * @return corresponding node if the path is found, the root otherwise
47      */

48     public BuildConfigNode getNodeForPath(String JavaDoc 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 JavaDoc 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 JavaDoc pathItem = (String JavaDoc)st.nextElement();
71             for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
72                 node = (BuildConfigNode)it.next();
73                 String JavaDoc 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 JavaDoc getSourceFile() {
100         return sourceFile;
101     }
102     
103     public void setSourceFile(String JavaDoc sourceFile) {
104         this.sourceFile = sourceFile;
105     }
106 }
107
108
109
Popular Tags