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
22 import java.io.File;
23
24 /***
25 * @author Srinath Perera(hemapani@opensource.lk)
26 */
27 public class ModuleFactory {
28
29 /***
30 * @param path - path to the package
31 * @param firstmodule - is it the first module or a module inside other module
32 * @return
33 * @throws GenerationFault
34 */
35 public static Module createPackageModule(String path,File outDir) throws UnrecoverableGenerationFault {
36 return createPackageModule(path, Thread.currentThread().getContextClassLoader(),outDir);
37 }
38
39 public static Module createPackageModule(String path,
40 ClassLoader parentCL,File outDir) throws UnrecoverableGenerationFault {
41 try {
42 if (path != null) {
43 File file = new File(path);
44 if (!file.exists())
45 throw new UnrecoverableGenerationFault("file not found " + file.getAbsolutePath());
46 if (file.isDirectory()) {
47 return new DirModule(path, parentCL);
48 } else if (path.endsWith(".jar") || path.endsWith(".JAR"))
49 return new JarModule(path, parentCL);
50 else if (path.endsWith(".war") || path.endsWith(".WAR"))
51 return new WARModule(path, parentCL,outDir);
52 else if (path.endsWith(".ear") || path.endsWith(".EAR"))
53 return new EARModule(path,outDir);
54 else if (path.endsWith(".xml"))
55 return new DirModule(new File(path));
56 else
57 throw new UnrecoverableGenerationFault("unknown type of file");
58 }
59 } catch (GenerationFault e) {
60 throw new UnrecoverableGenerationFault(path + " not found ", e);
61 }
62 throw new UnrecoverableGenerationFault("path is null");
63 }
64 }