KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > tc6 > WebAppLoader


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.web.tomcat.tc6;
23
24 import java.net.URL JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.catalina.LifecycleException;
28 import org.apache.catalina.loader.WebappLoader;
29 import org.jboss.logging.Logger;
30
31 /**
32  * Override the tomcat WebappLoader to set the default class loader to the
33  * WebAppClassLoader and pass the filtered packages to the WebAppClassLoader.
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision: 58290 $
37  */

38 public class WebAppLoader extends WebappLoader
39 {
40    private static final Logger log = Logger.getLogger(WebAppLoader.class);
41
42    private String JavaDoc[] filteredPackages = {
43            "org.apache.commons.logging"
44    };
45    private List JavaDoc<URL JavaDoc> classpath;
46
47    private TomcatInjectionContainer injectionContainer;
48
49    public WebAppLoader()
50    {
51       super();
52       setLoaderClass(WebAppClassLoader.class.getName());
53    }
54
55    public WebAppLoader(ClassLoader JavaDoc parent, String JavaDoc[] filteredPackages)
56    {
57       this(parent, filteredPackages, null);
58    }
59    public WebAppLoader(ClassLoader JavaDoc parent, String JavaDoc[] filteredPackages, TomcatInjectionContainer container)
60    {
61       super(parent);
62       setLoaderClass(WebAppClassLoader.class.getName());
63       this.filteredPackages = filteredPackages;
64       injectionContainer = container;
65    }
66
67    /**
68     * Use an explicit classpath
69     *
70     * @param classpath
71     */

72    public void setClasspath(List JavaDoc<URL JavaDoc> classpath)
73    {
74       this.classpath = classpath;
75    }
76
77    /**
78     * Override to apply the filteredPackages to the jboss WebAppClassLoader
79     *
80     * @throws LifecycleException
81     */

82    public void start() throws LifecycleException
83    {
84       super.start();
85       ClassLoader JavaDoc loader = getClassLoader();
86       if (loader instanceof WebAppClassLoader)
87       {
88          WebAppClassLoader webLoader = (WebAppClassLoader) loader;
89          webLoader.setFilteredPackages(filteredPackages);
90          if( classpath != null )
91          {
92             for(URL JavaDoc url : classpath)
93             {
94                webLoader.addURL(url);
95             }
96          }
97       }
98       if (injectionContainer != null)
99       {
100          log.debug("injectionContainer enabled and processing beginning with Tomcat WebAppLoader");
101          // we need to do this because the classloader is initialize by the web container and
102
// the injection container needs the classloader so that it can build up Injectors and ENC populators
103
injectionContainer.setClassLoader(getClassLoader());
104          injectionContainer.processMetadata();
105       }
106    }
107 }
108
Popular Tags