KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > TR > Impl > ComponentFiles


1 /**
2  * ComponentFiles.java is a part of the SOFA project.
3  * This file was created by pepan on 20.3.2003.
4  */

5 package SOFA.SOFAnode.TR.Impl;
6
7 import java.io.File JavaDoc;
8 import java.io.Serializable JavaDoc;
9 import java.util.Hashtable JavaDoc;
10
11 /**
12  * An internal representation of a component. It lists all files necessary for a component.
13  * @author Petr Panuska
14  */

15 class ComponentFiles implements Serializable JavaDoc {
16
17   /**
18    * List of files contained by this component. Each key is a {@link String} and
19    * serves as a name of the file in a bundle (JAR file). The associated value is
20    * of type {@link File} and directly denotes the file stored in the filesystem of the
21    * SOFA node.
22    */

23   private Hashtable JavaDoc files;
24
25   /**
26    * Creates an instance of this class with no files marked to be a part of this component.
27    */

28   ComponentFiles () {
29     files = new Hashtable JavaDoc();
30   }
31
32   /**
33    * Adds a file or a hierarchy of files to this component. If the specified path denotes
34    * a directory, it adds this directory as well as all sub-directories and files. Otherwise,
35    * it adds the specified file only.
36    * @param path string denoting a file or a directory being added.
37    */

38   void addFiles (String JavaDoc path, String JavaDoc name) {
39     File JavaDoc file = new File JavaDoc(path);
40     if (file.isDirectory()) { // list files in a directory
41
if (!path.endsWith(File.separator))
42         path = path + File.separator;
43       if (!name.endsWith(File.separator))
44         name = name + File.separator;
45       String JavaDoc[] subFiles = file.list();
46       for (int i = 0; i < subFiles.length; i++) {
47         String JavaDoc subFile = subFiles[i];
48         addFiles(path + subFile, name + subFile);
49       }
50     } else
51       files.put(name, file); // do not store directories
52
}
53
54   /**
55    * Adds one file under a given unique name. It must not be a directory.
56    * @param file the file being added.
57    * @param name the unique name.
58    */

59   void addFile (File JavaDoc file, String JavaDoc name) {
60     assert(file.isDirectory());
61     files.put(name, file); // do not store directories
62
}
63
64   /**
65    * Gets a list of files being part of this component.
66    * @return the component files.
67    * @see #files
68    */

69   Hashtable JavaDoc getFiles () {
70     return files;
71   }
72
73   /**
74    * Gets the assembly descriptor file of this component. It's the file called
75    * <em>index.dc</em>.
76    * @return the file describing the assembly of this component.
77    */

78   File JavaDoc getAssemblyDescriptorFile () {
79     return (File JavaDoc) files.get(File.separator + "index.dc");
80   }
81 }
82
Popular Tags