001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. 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 import org.apache.geronimo.kernel.config.MultiParentClassLoader;
029
030 /**
031 *
032 *
033 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
034 */
035 public class WebDeployable extends AbstractDeployable {
036 private final ClassLoader webLoader;
037
038 public WebDeployable(URL moduleURL) throws DDBeanCreateException{
039 this(moduleURL, null);
040 }
041
042 public WebDeployable(URL moduleURL, List parentClassLoaders) throws DDBeanCreateException {
043 super(ModuleType.WAR, moduleURL, "WEB-INF/web.xml");
044 ClassLoader parent = super.getModuleLoader();
045 List path = new ArrayList();
046 URL url = parent.getResource("WEB-INF/classes/");
047 if (url != null) {
048 path.add(url);
049 }
050 Enumeration e = entries();
051 while (e.hasMoreElements()) {
052 String entry = (String) e.nextElement();
053 if (entry.startsWith("WEB-INF/lib/")) {
054 String jarName = entry.substring(12);
055 if (jarName.indexOf('/') == -1 && (jarName.endsWith(".jar") || jarName.endsWith(".zip"))) {
056 path.add(parent.getResource(entry));
057 }
058 }
059 }
060 URL[] urls = (URL[]) path.toArray(new URL[path.size()]);
061 if (parentClassLoaders != null) {
062 parentClassLoaders.add(parent);
063 ClassLoader[] parents = (ClassLoader[]) parentClassLoaders.toArray(new ClassLoader[parentClassLoaders.size()]);
064 webLoader = new MultiParentClassLoader(null, urls, parents);
065 } else {
066 webLoader = new URLClassLoader(urls, parent);
067 }
068 }
069
070 public ClassLoader getModuleLoader() {
071 return webLoader;
072 }
073 }