View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }