KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > archive > JarArchive


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.archive;
8
9 import java.util.Collections JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import org.ejtools.archive.io.Reader;
16 import org.ejtools.archive.io.Writer;
17
18 /**
19  * Implementation for a Jar based archive.
20  *
21  * @author Laurent Etiemble
22  * @version $Revision: 1.2 $
23  */

24 public class JarArchive extends JarEntry implements Archive
25 {
26    /** Description of the Field */
27    private Map JavaDoc entries = new HashMap JavaDoc();
28    /** Description of the Field */
29    private Archive parent = null;
30
31
32    /**
33     * Constructor for the JarArchive object
34     *
35     * @param uri The URI of the archive
36     */

37    public JarArchive(String JavaDoc uri)
38    {
39       super(uri);
40    }
41
42
43    /**
44     * Visitor Pattern method to accept a Writer visitor
45     *
46     * @param visitor The writer visitor
47     */

48    public void accept(Writer visitor)
49    {
50       visitor.visit(this);
51    }
52
53
54    /**
55     * Visitor Pattern method to accept a Reader visitor
56     *
57     * @param visitor The reader visitor
58     */

59    public void accept(Reader visitor)
60    {
61       visitor.visit(this);
62    }
63
64
65    /**
66     * Adds an entry to this archive
67     *
68     * @param entry The archive entry to be added
69     */

70    public void addEntry(Entry entry)
71    {
72       this.entries.put(entry.getURI(), entry);
73    }
74
75
76    /**
77     * Adds a feature to the To attribute of the JarArchive object
78     *
79     * @param archive The feature to be added to the To attribute
80     */

81    public void addTo(Archive archive)
82    {
83       this.parent = archive;
84       archive.addEntry(this);
85    }
86
87
88    /**
89     * Returns an enumeration of entries contained in this archive
90     *
91     * @return The entries enumeration
92     */

93    public Enumeration JavaDoc getEntries()
94    {
95       return Collections.enumeration(entries.values());
96    }
97
98
99    /**
100     * Returns the archive entry designated by this URI
101     *
102     * @param uri The URI of the entry
103     * @return The archiev entry if exists
104     */

105    public Entry getEntry(String JavaDoc uri)
106    {
107       return (Entry) this.entries.get(uri);
108    }
109
110
111    /**
112     * Returns the manifest entry of this archive
113     *
114     * @return The manifest entry
115     */

116    public Entry getManifest()
117    {
118       return (Entry) this.entries.get("META-INF/MANIFEST.MF");
119    }
120
121
122    /**
123     * Return the parent archive of this archive
124     *
125     * @return The parent value
126     */

127    public Archive getParent()
128    {
129       return this.parent;
130    }
131
132
133    /**
134     * Always returns true as it is an archive
135     *
136     * @return Always true
137     */

138    public boolean isArchive()
139    {
140       return true;
141    }
142
143
144    /**
145     * Returns whether or not this archive is nested in an other archive
146     *
147     * @return True if it is nested
148     */

149    public boolean isNested()
150    {
151       return (this.parent != null);
152    }
153
154
155    /**
156     * Return an Iterator of the entries contained in this archive
157     *
158     * @return The entries Iterator
159     */

160    public Iterator JavaDoc iterator()
161    {
162       return this.entries.values().iterator();
163    }
164
165
166    /**
167     * Removes an entry from this archive
168     *
169     * @param uri The archive entry to be removed
170     */

171    public void removeEntry(String JavaDoc uri)
172    {
173       this.entries.remove(uri);
174    }
175
176
177    /**
178     * Removes an entry from this archive
179     *
180     * @param entry The archive entry to be removed
181     */

182    public void removeEntry(Entry entry)
183    {
184       this.removeEntry(entry.getURI());
185    }
186 }
187
Popular Tags