01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.deployment.tools.loader;
17:
18: import java.net.URL;
19: import java.net.URLClassLoader;
20: import java.util.ArrayList;
21: import java.util.Enumeration;
22: import java.util.List;
23: import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
24: import javax.enterprise.deploy.shared.ModuleType;
25:
26: import org.apache.geronimo.kernel.config.MultiParentClassLoader;
27:
28: /**
29: *
30: *
31: * @version $Rev: 594759 $ $Date: 2007-11-13 20:32:35 -0800 (Tue, 13 Nov 2007) $
32: */
33: public class WebDeployable extends AbstractDeployable {
34: private final ClassLoader webLoader;
35:
36: public WebDeployable(URL moduleURL) throws DDBeanCreateException {
37: this (moduleURL, null);
38: }
39:
40: public WebDeployable(URL moduleURL, List parentClassLoaders)
41: throws DDBeanCreateException {
42: super (ModuleType.WAR, moduleURL, "WEB-INF/web.xml");
43: ClassLoader parent = super .getModuleLoader();
44: List path = new ArrayList();
45: URL url = parent.getResource("WEB-INF/classes/");
46: if (url != null) {
47: path.add(url);
48: }
49: Enumeration e = entries();
50: while (e.hasMoreElements()) {
51: String entry = (String) e.nextElement();
52: if (entry.startsWith("WEB-INF/lib/")) {
53: String jarName = entry.substring(12);
54: if (jarName.indexOf('/') == -1
55: && (jarName.endsWith(".jar") || jarName
56: .endsWith(".zip"))) {
57: path.add(parent.getResource(entry));
58: }
59: }
60: }
61: URL[] urls = (URL[]) path.toArray(new URL[path.size()]);
62: if (parentClassLoaders != null) {
63: parentClassLoaders.add(parent);
64: ClassLoader[] parents = (ClassLoader[]) parentClassLoaders
65: .toArray(new ClassLoader[parentClassLoaders.size()]);
66: webLoader = new MultiParentClassLoader(null, urls, parents);
67: } else {
68: webLoader = new URLClassLoader(urls, parent);
69: }
70: }
71:
72: public ClassLoader getModuleLoader() {
73: return webLoader;
74: }
75: }
|