KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > tc5 > WebAppClassLoader


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.web.tomcat.tc5;
8
9 import org.apache.catalina.loader.WebappClassLoader;
10 import org.jboss.logging.Logger;
11
12 /**
13  * Subclass the tomcat web app class loader to override the filter method
14  * to exclude classes which cannot be override by the web app due to their
15  * use in the tomcat web container/integration.
16  *
17  * @author Scott.Stark@jboss.org
18  * @version $Revision: 1.1 $
19  */

20 public class WebAppClassLoader extends WebappClassLoader
21 {
22    static Logger log = Logger.getLogger(WebAppClassLoader.class);
23    private String JavaDoc[] filteredPackages = {
24       "org.apache.commons.logging"
25    };
26
27    public WebAppClassLoader()
28    {
29    }
30
31    public WebAppClassLoader(ClassLoader JavaDoc parent)
32    {
33       super(parent);
34    }
35
36    public String JavaDoc[] getFilteredPackages()
37    {
38       return filteredPackages;
39    }
40    public void setFilteredPackages(String JavaDoc[] pkgs)
41    {
42       this.filteredPackages = pkgs;
43    }
44
45    /**
46     * Overriden to filter out classes in the packages listed in the
47     * filteredPackages settings.
48     *
49     * @param name
50     * @return true if the class should be loaded from the parent class loader,
51     * false if it can be loaded from this class loader.
52     */

53    protected boolean filter(String JavaDoc name)
54    {
55       boolean excludeClass = super.filter(name);
56       if( excludeClass == false )
57       {
58          // Check class against our filtered packages
59
int length = filteredPackages != null ? filteredPackages.length : 0;
60          for(int n = 0; n < length; n ++)
61          {
62             String JavaDoc pkg = filteredPackages[n];
63             if( name.startsWith(pkg) )
64             {
65                excludeClass = true;
66                break;
67             }
68          }
69       }
70       log.trace("filter name="+name+", exclude="+excludeClass);
71       return excludeClass;
72    }
73 }
74
Popular Tags