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.utils.FileUtils;
21  
22  
23  import java.io.File;
24  import java.io.IOException;
25  import java.net.MalformedURLException;
26  import java.net.URL;
27  import java.net.URLClassLoader;
28  import java.util.ArrayList;
29  
30  /***
31   * @author Srinath Perera(hemapani@opensource.lk)
32   */
33  public class WARModule extends AbstractModule {
34      private ArrayList urls;
35      private ClassLoader cl;
36  
37      /***
38       * @param jarFile
39       * @throws GenerationFault
40       */
41      public WARModule(String jarFile, ClassLoader parentCL,File outDir)
42              throws GenerationFault {
43          super(jarFile, parentCL);
44          try {
45              urls = FileUtils.uncompressWar(new File(outDir,"unpacked"), new File(zip.getName()));
46              URL[] aurls = new URL[urls.size()];
47              for (int i = 0; i < aurls.length; i++) {
48                  aurls[i] = ((File) urls.get(i)).toURL();
49                  System.out.println(aurls[i]);
50              }
51              cl = new URLClassLoader(aurls, Thread.currentThread().getContextClassLoader());
52              wscfFile = getInputStreamForJarEntry(jarFile, "WEB-INF/webservices.xml");
53              if (wscfFile == null) {
54                  wscfFile = getInputStreamForJarEntry(jarFile, "webservices.xml");
55              }
56              webddfile = getInputStreamForJarEntry(jarFile, "WEB-INF/web.xml");
57              if (webddfile == null)
58                  webddfile = getInputStreamForJarEntry(jarFile, "web.xml");
59              if (wscfFile == null)
60                  throw new GenerationFault("wscf file must not be null");
61          } catch (MalformedURLException e) {
62              e.printStackTrace();
63              throw GenerationFault.createGenerationFault(e);
64          } catch (IOException e) {
65              e.printStackTrace();
66              throw GenerationFault.createGenerationFault(e);
67          } catch (GenerationFault e) {
68              e.printStackTrace();
69              throw GenerationFault.createGenerationFault(e);
70          }
71      }
72  
73      /* (non-Javadoc)
74       * @see org.apache.geronimo.ews.ws4j2ee.utils.packager.load.PackageModule#getClassLoaderWithPackageLoaded()
75       */
76      public ClassLoader getClassLoaderWithPackageLoaded() throws GenerationFault {
77          return cl;
78      }
79  
80      public ArrayList getClassPathElements() {
81          return urls;
82      }
83  
84  }