1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.module;
18
19 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
20 import org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenerationFault;
21 import org.apache.geronimo.ews.ws4j2ee.utils.FileUtils;
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.ArrayList;
26 import java.util.Enumeration;
27 import java.util.Vector;
28 import java.util.zip.ZipEntry;
29 import java.util.zip.ZipFile;
30
31 /***
32 * @author hemapani@opensource.lk
33 */
34 public class EARModule implements Module {
35 private Module pkgModule;
36 private Vector classPathElements;
37 private ClassLoader parentCL;
38
39 /***
40 * @param jarFile
41 * @throws GenerationFault
42 */
43 public EARModule(String jarFile,File outDir)
44 throws GenerationFault {
45 try {
46 ZipFile earFile = new ZipFile(jarFile);
47 Enumeration enumeration = earFile.entries();
48 int index = 0;
49 while (enumeration.hasMoreElements()) {
50 index++;
51 ZipEntry entry = (ZipEntry) enumeration.nextElement();
52 if (entry.getName().endsWith(".war") || entry.getName().endsWith(".jar")) {
53 File outWar = new File(new File(outDir,String.valueOf(index)), entry.getName());
54 FileUtils.uncompressFile(earFile.getInputStream(entry), outWar);
55 pkgModule = ModuleFactory.createPackageModule(outWar.getAbsolutePath(),new File(outDir,String.valueOf(index)));
56 }
57 }
58 } catch (UnrecoverableGenerationFault e) {
59 e.printStackTrace();
60 throw GenerationFault.createGenerationFault(e);
61 } catch (IOException e) {
62 e.printStackTrace();
63 throw GenerationFault.createGenerationFault(e);
64 }
65 }
66
67 /***
68 * @return
69 * @throws GenerationFault
70 */
71 public ClassLoader getClassLoaderWithPackageLoaded() throws GenerationFault {
72 return pkgModule.getClassLoaderWithPackageLoaded();
73 }
74
75 /***
76 * @return
77 * @throws GenerationFault
78 */
79 public ArrayList getClassPathElements() throws GenerationFault {
80 return pkgModule.getClassPathElements();
81 }
82
83 public boolean equals(Object obj) {
84 return pkgModule.equals(obj);
85 }
86
87 /***
88 * @param path
89 * @return
90 * @throws GenerationFault
91 */
92 public InputStream findFileInModule(String path) throws GenerationFault {
93 return pkgModule.findFileInModule(path);
94 }
95
96 /***
97 * @return
98 * @throws GenerationFault
99 */
100 public InputStream getEjbJarfile() throws GenerationFault {
101 return pkgModule.getEjbJarfile();
102 }
103
104 /***
105 * @return
106 * @throws GenerationFault
107 */
108 public InputStream getWebddfile() throws GenerationFault {
109 return pkgModule.getWebddfile();
110 }
111
112 /***
113 * @return
114 * @throws GenerationFault
115 */
116 public InputStream getWscfFile() throws GenerationFault {
117 return pkgModule.getWscfFile();
118 }
119
120
121
122
123 public int hashCode() {
124 return pkgModule.hashCode();
125 }
126
127 /***
128 * @param stream
129 * @throws GenerationFault
130 */
131 public void setEjbJarfile(InputStream stream) throws GenerationFault {
132 pkgModule.setEjbJarfile(stream);
133 }
134
135 /***
136 * @param stream
137 * @throws GenerationFault
138 */
139 public void setWebddfile(InputStream stream) throws GenerationFault {
140 pkgModule.setWebddfile(stream);
141 }
142
143 /***
144 * @param stream
145 * @throws GenerationFault
146 */
147 public void setWscfFile(InputStream stream) throws GenerationFault {
148 pkgModule.setWscfFile(stream);
149 }
150
151
152
153
154 public String toString() {
155 return pkgModule.toString();
156 }
157 }