KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > config > classpath > ClasspathDirectoryEntry


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.browser.config.classpath;
9
10 import javax.swing.tree.DefaultTreeModel JavaDoc;
11 import java.io.File JavaDoc;
12
13 /**
14     Classpath entry for a directory.
15
16     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
17     @version $Revision: 1.1 $ $Date: 2003/08/18 08:10:15 $
18 */

19 public class ClasspathDirectoryEntry extends ClasspathEntry {
20
21     public FindResult findClass(String JavaDoc className) {
22
23         File JavaDoc file = getFile();
24         if (file == null) {
25             return null;
26         }
27         File JavaDoc classFile = new File JavaDoc(file, className.replace('.', '/') + ".class");
28         if (classFile.exists() && classFile.canRead()) {
29             FindResult findResult = new FindResult(this, classFile.getPath());
30             return findResult;
31         }
32
33         return null;
34     }
35
36     public void mergeClassesIntoTree(DefaultTreeModel JavaDoc model, boolean reset) {
37
38         File JavaDoc directory = getFile();
39         if (directory == null) {
40             return;
41         }
42
43         ClassTreeNode rootNode = (ClassTreeNode)model.getRoot();
44         mergeDirectory(directory, rootNode, model, reset);
45
46     }
47
48     private void mergeDirectory(File JavaDoc directory, ClassTreeNode parentNode, DefaultTreeModel JavaDoc model, boolean reset) {
49
50         File JavaDoc[] files = directory.listFiles();
51         if (files == null) {
52             return;
53         }
54         for (int i = 0; i < files.length; i++) {
55             File JavaDoc file = files[i];
56             if (file.isDirectory()) {
57                 ClassTreeNode directoryNode = addOrFindNode(file.getName(), parentNode, true, model, reset);
58                 mergeDirectory(file, directoryNode, model, reset);
59                 if ((directoryNode.getChildCount() == 0)) {
60                     int deletionIndex = parentNode.getIndex(directoryNode);
61                     parentNode.remove(directoryNode);
62                     if (!reset) {
63                         model.nodesWereRemoved(parentNode, new int[] {deletionIndex}, new Object JavaDoc[] {directoryNode});
64                     }
65                 }
66             } else if (file.getName().toLowerCase().endsWith(CLASSFILE_SUFFIX)) {
67                 addOrFindNode(stripClassSuffix(file.getName()), parentNode, false, model, reset);
68             }
69         }
70
71     }
72
73 }
74
Popular Tags