001 /** 002 * 003 * Copyright 2003-2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.deployment.tools.loader; 019 020 import java.net.URL; 021 import java.net.URLClassLoader; 022 import java.util.ArrayList; 023 import java.util.Enumeration; 024 import java.util.List; 025 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException; 026 import javax.enterprise.deploy.shared.ModuleType; 027 028 /** 029 * 030 * 031 * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $ 032 */ 033 public class WebDeployable extends AbstractDeployable { 034 private final ClassLoader webLoader; 035 036 public WebDeployable(URL moduleURL) throws DDBeanCreateException { 037 super(ModuleType.WAR, moduleURL, "WEB-INF/web.xml"); 038 ClassLoader parent = super.getModuleLoader(); 039 List path = new ArrayList(); 040 path.add(parent.getResource("WEB-INF/classes/")); 041 Enumeration e = entries(); 042 while (e.hasMoreElements()) { 043 String entry = (String) e.nextElement(); 044 if (entry.startsWith("WEB-INF/lib/")) { 045 String jarName = entry.substring(12); 046 if (jarName.indexOf('/') == -1 && (jarName.endsWith(".jar") || jarName.endsWith(".zip"))) { 047 path.add(parent.getResource(entry)); 048 } 049 } 050 } 051 webLoader = new URLClassLoader((URL[]) path.toArray(new URL[path.size()]), parent); 052 } 053 054 protected ClassLoader getModuleLoader() { 055 return webLoader; 056 } 057 }