JarList.java

00001 
00027 package org.objectweb.jonas.ear.lib;
00028 
00029 //java import
00030 import java.io.File;
00031 import java.io.IOException;
00032 import java.net.URL;
00033 import java.util.Enumeration;
00034 import java.util.StringTokenizer;
00035 import java.util.Vector;
00036 
00037 import org.objectweb.jonas_ear.deployment.xml.Web;
00038 
00045 public class JarList extends Vector {
00046 
00050     public JarList() {
00051         super();
00052     }
00053 
00058     public JarList(StringTokenizer st) {
00059         super();
00060 
00061         //add each entries
00062         while (st.hasMoreTokens()) {
00063             String fileName = st.nextToken();
00064             add(fileName);
00065         }
00066     }
00067 
00072     public JarList(String[] strs) {
00073         super();
00074 
00075         for (int i = 0; i < strs.length; i++) {
00076             add(strs[i]);
00077         }
00078     }
00079 
00084     public JarList(Web[] wars) {
00085         super();
00086 
00087         for (int i = 0; i < wars.length; i++) {
00088             String s = wars[i].getWebUri();
00089             add(s);
00090         }
00091     }
00092 
00097     public void add(String fileName) {
00098         if (!contains(fileName) && !fileName.equals("")) {
00099             super.add(fileName);
00100         }
00101     }
00102 
00109     public URL[] getURLs(String dirName) throws JarListException {
00110 
00111         URL[] urls = new URL[elementCount];
00112         for (int i = 0; i < elementCount; i++) {
00113             String s = (String) elementData[i];
00114             try {
00115                 urls[i] = new File(new URL(dirName + File.separator + s).getFile()).getCanonicalFile().toURL();
00116             } catch (IOException e) {
00117                 throw new JarListException("Error when trying to get the canonical form for the file " + elementData[i]);
00118             }
00119         }
00120         return urls;
00121     }
00122 
00128     public void merge(JarList jarList) {
00129         for (Enumeration e = jarList.elements(); e.hasMoreElements();) {
00130             String s = (String) e.nextElement();
00131             //call add which call super.add
00132             add(s);
00133         }
00134     }
00135 
00140     public void remove(JarList jarList) {
00141 
00142         for (Enumeration e = jarList.elements(); e.hasMoreElements();) {
00143             String s = (String) e.nextElement();
00144             if (contains(s)) {
00145                 remove(s);
00146             }
00147         }
00148     }
00149 
00156     public void setRelativePath(String path) {
00157         if (path.equals("")) {
00158             return;
00159         }
00160 
00161         for (int i = 0; i < elementCount; i++) {
00162             elementData[i] = path + File.separator + elementData[i];
00163         }
00164     }
00165 }

Generated on Tue Feb 15 15:05:16 2005 for JOnAS by  doxygen 1.3.9.1