|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JarArchive.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 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;
|
|
| 10 |
import java.util.Enumeration;
|
|
| 11 |
import java.util.HashMap;
|
|
| 12 |
import java.util.Iterator;
|
|
| 13 |
import java.util.Map;
|
|
| 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 entries = new HashMap(); |
|
| 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 | 0 |
public JarArchive(String uri)
|
| 38 |
{
|
|
| 39 | 0 |
super(uri);
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
|
|
| 43 |
/**
|
|
| 44 |
* Visitor Pattern method to accept a Writer visitor
|
|
| 45 |
*
|
|
| 46 |
* @param visitor The writer visitor
|
|
| 47 |
*/
|
|
| 48 | 0 |
public void accept(Writer visitor) |
| 49 |
{
|
|
| 50 | 0 |
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 | 0 |
public void accept(Reader visitor) |
| 60 |
{
|
|
| 61 | 0 |
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 | 0 |
public void addEntry(Entry entry) |
| 71 |
{
|
|
| 72 | 0 |
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 | 0 |
public void addTo(Archive archive) |
| 82 |
{
|
|
| 83 | 0 |
this.parent = archive;
|
| 84 | 0 |
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 | 0 |
public Enumeration getEntries()
|
| 94 |
{
|
|
| 95 | 0 |
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 | 0 |
public Entry getEntry(String uri)
|
| 106 |
{
|
|
| 107 | 0 |
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 | 0 |
public Entry getManifest()
|
| 117 |
{
|
|
| 118 | 0 |
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 | 0 |
public Archive getParent()
|
| 128 |
{
|
|
| 129 | 0 |
return this.parent; |
| 130 |
} |
|
| 131 |
|
|
| 132 |
|
|
| 133 |
/**
|
|
| 134 |
* Always returns true as it is an archive
|
|
| 135 |
*
|
|
| 136 |
* @return Always true
|
|
| 137 |
*/
|
|
| 138 | 0 |
public boolean isArchive() |
| 139 |
{
|
|
| 140 | 0 |
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 | 0 |
public boolean isNested() |
| 150 |
{
|
|
| 151 | 0 |
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 | 0 |
public Iterator iterator()
|
| 161 |
{
|
|
| 162 | 0 |
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 | 0 |
public void removeEntry(String uri) |
| 172 |
{
|
|
| 173 | 0 |
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 | 0 |
public void removeEntry(Entry entry) |
| 183 |
{
|
|
| 184 | 0 |
this.removeEntry(entry.getURI());
|
| 185 |
} |
|
| 186 |
} |
|
| 187 |
|
|
||||||||||