001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 2000, 2001, 2002, 2003 Jesse Stockall. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution, if
019: * any, must include the following acknowlegement:
020: * "This product includes software developed by the
021: * Apache Software Foundation (http://www.apache.org/)."
022: * Alternately, this acknowlegement may appear in the software itself,
023: * if and wherever such third-party acknowlegements normally appear.
024: *
025: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
026: * Foundation" must not be used to endorse or promote products derived
027: * from this software without prior written permission. For written
028: * permission, please contact apache@apache.org.
029: *
030: * 5. Products derived from this software may not be called "Apache"
031: * nor may "Apache" appear in their names without prior written
032: * permission of the Apache Group.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: */
049: package org.apache.tools.ant.taskdefs.optional.genjar;
050:
051: import java.io.File;
052: import java.util.Date;
053: import java.util.Iterator;
054: import java.util.jar.Attributes;
055:
056: /**
057: * Represents one object (file) that is to be placed into the jar.<p>
058: *
059: * This includes all <class> names specified in the project file, all
060: * <resource> files specified in the project file and all generated class
061: * references.<p>
062: *
063: *
064: *
065: * @author Original Code: <a href="mailto:jake@riggshill.com">John W. Kohler
066: * </a>
067: * @author Jesse Stockall
068: * @version $Revision: 1.2 $ $Date: 2003/02/23 10:43:21 $
069: */
070: public class JarEntrySpec {
071: Attributes atts;
072: String jarName;
073: File srcFile;
074:
075: /** Constructor for the JarEntrySpec object */
076: JarEntrySpec() {
077: atts = new Attributes();
078: }
079:
080: /**
081: * create a new jar entry given a name (jar path) and a fully qualified file
082: * path.
083: *
084: * @param jarName Description of the Parameter
085: * @param srcFile Description of the Parameter
086: */
087: JarEntrySpec(String jarName, File srcFile) {
088: this .jarName = jarName.replace('\\', '/');
089: this .srcFile = srcFile;
090: atts = new Attributes();
091:
092: if (srcFile != null) {
093: setAttribute("Content-Location", srcFile.getAbsolutePath());
094: setAttribute("Content-Length", srcFile.length());
095: setAttribute("Last-Modified", new Date(srcFile
096: .lastModified()));
097: }
098: }
099:
100: /**
101: * Gets the jarName attribute of the JarEntrySpec object
102: *
103: * @return The jarName value
104: */
105: String getJarName() {
106: return jarName;
107: }
108:
109: /**
110: * Sets the jarName attribute of the JarEntrySpec object
111: *
112: * @param jn The new jarName value
113: */
114: void setJarName(String jn) {
115: jarName = jn;
116: }
117:
118: /**
119: * Gets the sourceFile attribute of the JarEntrySpec object
120: *
121: * @return The sourceFile value
122: */
123: File getSourceFile() {
124: return srcFile;
125: }
126:
127: /**
128: * Sets the sourceFile attribute of the JarEntrySpec object
129: *
130: * @param f The new sourceFile value
131: */
132: void setSourceFile(File f) {
133: srcFile = f;
134: }
135:
136: /**
137: * Gets the attributes attribute of the JarEntrySpec object
138: *
139: * @return The attributes value
140: */
141: Attributes getAttributes() {
142: return atts;
143: }
144:
145: /**
146: * copy an Attributes into this entry's attributs
147: *
148: * @param a The feature to be added to the Attributes attribute
149: */
150: public void addAttributes(Attributes a) {
151: if (a != null) {
152: for (Iterator it = a.keySet().iterator(); it.hasNext();) {
153: String key = it.next().toString();
154: atts.putValue(key, a.getValue(key));
155: }
156: }
157: }
158:
159: /**
160: * Sets the attribute attribute of the JarEntrySpec object
161: *
162: * @param name The new attribute value
163: * @param val The new attribute value
164: */
165: void setAttribute(String name, int val) {
166: setAttribute(name, Integer.toString(val));
167: }
168:
169: /**
170: * Sets the attribute attribute of the JarEntrySpec object
171: *
172: * @param name The new attribute value
173: * @param val The new attribute value
174: */
175: void setAttribute(String name, long val) {
176: setAttribute(name, Long.toString(val));
177: }
178:
179: /**
180: * Sets the attribute attribute of the JarEntrySpec object
181: *
182: * @param name The new attribute value
183: * @param val The new attribute value
184: */
185: void setAttribute(String name, float val) {
186: setAttribute(name, Float.toString(val));
187: }
188:
189: /**
190: * Sets the attribute attribute of the JarEntrySpec object
191: *
192: * @param name The new attribute value
193: * @param val The new attribute value
194: */
195: void setAttribute(String name, double val) {
196: setAttribute(name, Double.toString(val));
197: }
198:
199: /**
200: * Sets the attribute attribute of the JarEntrySpec object
201: *
202: * @param name The new attribute value
203: * @param d The new attribute value
204: */
205: void setAttribute(String name, Date d) {
206: atts.putValue(name, d.toString());
207: }
208:
209: /**
210: * Sets the attribute attribute of the JarEntrySpec object
211: *
212: * @param name The new attribute value
213: * @param obj The new attribute value
214: */
215: void setAttribute(String name, Object obj) {
216: atts.putValue(name, obj.toString());
217: }
218:
219: /**
220: * Description of the Method
221: *
222: * @param o Description of the Parameter
223: * @return Description of the Return Value
224: */
225: public boolean equals(Object o) {
226: if (o == null || !(o instanceof JarEntrySpec)) {
227: return false;
228: }
229: return jarName.equals(((JarEntrySpec) o).jarName);
230: }
231:
232: /**
233: * Description of the Method
234: *
235: * @return Description of the Return Value
236: */
237: public String toString() {
238: String key;
239: StringBuffer sb = new StringBuffer("JarEntrySpec:");
240:
241: sb.append("\n\tJar Name:");
242: sb.append(jarName);
243: sb.append("\n\tStream :");
244: if (srcFile == null) {
245: sb.append("** NOT RESOLVED **");
246: } else {
247: sb.append(srcFile.getAbsolutePath());
248: }
249:
250: for (Iterator it = atts.keySet().iterator(); it.hasNext();) {
251: sb.append("\n\tAtt: ");
252: sb.append(key = it.next().toString());
253: sb.append(": ");
254: sb.append(atts.getValue(key));
255: }
256: return sb.toString();
257: }
258: }
|