1 16 17 package org.apache.axis2.deployment.repository.util; 18 19 import org.apache.axis2.deployment.DeploymentEngine; 20 import org.apache.axis2.deployment.DeploymentException; 21 import org.apache.axis2.engine.AxisFault; 22 23 import javax.xml.namespace.QName ; 24 import java.io.*; 25 import java.net.URL ; 26 import java.net.URLClassLoader ; 27 import java.util.ArrayList ; 28 import java.util.zip.ZipEntry ; 29 import java.util.zip.ZipInputStream ; 30 import java.util.zip.ZipOutputStream ; 31 32 36 public class ArchiveFileData { 37 38 private ClassLoader classLoader; 39 private File file = null; 40 private int type; 41 private String messgeReceiver; 42 private String moduleClass; 43 private String name; 44 45 private ArrayList modules = new ArrayList (); 46 47 48 public ArchiveFileData(int type, String name) { 49 this.type = type; 50 this.name = name; 51 } 52 53 public String getMessgeReceiver() { 54 return messgeReceiver; 55 } 56 57 public void setMessgeReceiver(String messgeReceiver) { 58 this.messgeReceiver = messgeReceiver; 59 } 60 61 public ArchiveFileData(File file, int type) { 62 this.file = file; 63 this.type = type; 64 } 65 66 public String getName() { 67 return file.getName(); 68 } 69 70 public String getServiceName() { 71 if (file != null) { 72 return file.getName(); 73 } else 74 return name; 75 } 76 77 public String getAbsolutePath() { 78 return file.getAbsolutePath(); 79 } 80 81 public int getType() { 82 return type; 83 } 84 85 public File getFile() { 86 return file; 87 } 88 89 public ClassLoader getClassLoader() { 90 return classLoader; 91 } 92 93 public void setClassLoader(ClassLoader classLoader) { 94 this.classLoader = classLoader; 95 } 96 97 public String getModuleClass() { 98 return moduleClass; 99 } 100 101 public void setModuleClass(String moduleClass) { 102 this.moduleClass = moduleClass; 103 } 104 105 public void setClassLoader() throws AxisFault { 106 ClassLoader parent = Thread.currentThread().getContextClassLoader(); 107 ArrayList URLs = new ArrayList (); 108 boolean tobeRecreated = false; if (file != null) { 111 URL [] urlsToLoadFrom = new URL [0]; 112 try { 113 if (!file.exists()) { 114 throw new RuntimeException ("file not found !!!!!!!!!!!!!!!"); 115 } 116 URLs.add(file.toURL()); 117 urlsToLoadFrom = new URL []{file.toURL()}; 118 classLoader = new URLClassLoader (urlsToLoadFrom, parent); 119 } catch (Exception e) { 120 throw new AxisFault(e); 121 } 122 try { 123 ZipInputStream zin = new ZipInputStream (new FileInputStream(file)); 124 ZipEntry entry; 125 String entryName = ""; 126 int BUFFER = 2048; 127 while ((entry = zin.getNextEntry()) != null) { 128 entryName = entry.getName(); 129 if (entryName != null && entryName.startsWith("lib/") && entryName.endsWith(".jar")) { 130 File libFile = new File(DeploymentEngine.axis2repository, entryName); 132 FileOutputStream dest = new FileOutputStream(libFile); 133 ZipOutputStream out = new ZipOutputStream (new BufferedOutputStream(dest)); 134 byte data[] = new byte[BUFFER]; 135 InputStream in = classLoader.getResourceAsStream(entryName); 136 ZipInputStream jar_zin = null; 137 jar_zin = new ZipInputStream (in); 138 ZipEntry jarentry; 139 while ((jarentry = jar_zin.getNextEntry()) != null) { 140 ZipEntry zip = new ZipEntry (jarentry); 141 out.putNextEntry(zip); 142 int count; 143 while ((count = jar_zin.read(data, 0, BUFFER)) != -1) { 144 out.write(data, 0, count); 145 } 146 } 147 out.close(); 148 jar_zin.close(); 149 URLs.add(libFile.toURL()); 150 tobeRecreated = true; 151 } 152 } 153 zin.close(); 154 if (tobeRecreated) { 155 URL [] urlstobeload = new URL [URLs.size()]; 156 for (int i = 0; i < URLs.size(); i++) { 157 URL url = (URL ) URLs.get(i); 158 urlstobeload[i] = url; 159 } 160 classLoader = new URLClassLoader (urlstobeload, parent); 162 } 163 } catch (IOException e) { 164 throw new DeploymentException(e); 165 } 166 } 167 } 168 169 public void addModule(QName moduleName) { 170 modules.add(moduleName); 171 } 172 173 public ArrayList getModules() { 174 return modules; 175 } 176 } 177 | Popular Tags |