1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.geronimo.deployment.tools.loader; 19 20 import java.net.URL; 21 import java.net.URLClassLoader; 22 import java.util.ArrayList; 23 import java.util.Enumeration; 24 import java.util.List; 25 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException; 26 import javax.enterprise.deploy.shared.ModuleType; 27 28 import org.apache.geronimo.kernel.config.MultiParentClassLoader; 29 30 /** 31 * 32 * 33 * @version $Rev: 594759 $ $Date: 2007-11-13 20:32:35 -0800 (Tue, 13 Nov 2007) $ 34 */ 35 public class WebDeployable extends AbstractDeployable { 36 private final ClassLoader webLoader; 37 38 public WebDeployable(URL moduleURL) throws DDBeanCreateException{ 39 this(moduleURL, null); 40 } 41 42 public WebDeployable(URL moduleURL, List parentClassLoaders) throws DDBeanCreateException { 43 super(ModuleType.WAR, moduleURL, "WEB-INF/web.xml"); 44 ClassLoader parent = super.getModuleLoader(); 45 List path = new ArrayList(); 46 URL url = parent.getResource("WEB-INF/classes/"); 47 if (url != null) { 48 path.add(url); 49 } 50 Enumeration e = entries(); 51 while (e.hasMoreElements()) { 52 String entry = (String) e.nextElement(); 53 if (entry.startsWith("WEB-INF/lib/")) { 54 String jarName = entry.substring(12); 55 if (jarName.indexOf('/') == -1 && (jarName.endsWith(".jar") || jarName.endsWith(".zip"))) { 56 path.add(parent.getResource(entry)); 57 } 58 } 59 } 60 URL[] urls = (URL[]) path.toArray(new URL[path.size()]); 61 if (parentClassLoaders != null) { 62 parentClassLoaders.add(parent); 63 ClassLoader[] parents = (ClassLoader[]) parentClassLoaders.toArray(new ClassLoader[parentClassLoaders.size()]); 64 webLoader = new MultiParentClassLoader(null, urls, parents); 65 } else { 66 webLoader = new URLClassLoader(urls, parent); 67 } 68 } 69 70 public ClassLoader getModuleLoader() { 71 return webLoader; 72 } 73 }