KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import org.apache.catalina.loader.WebappClassLoader;
27 import org.jboss.logging.Logger;
28
29 /**
30  * Subclass the tomcat web app class loader to override the filter method
31  * to exclude classes which cannot be override by the web app due to their
32  * use in the tomcat web container/integration.
33  *
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 58290 $
36  */

37 public class WebAppClassLoader extends WebappClassLoader
38 {
39    static Logger log = Logger.getLogger(WebAppClassLoader.class);
40    private String JavaDoc[] filteredPackages = {
41       "org.apache.commons.logging"
42    };
43
44    public WebAppClassLoader()
45    {
46    }
47
48    public WebAppClassLoader(ClassLoader JavaDoc parent)
49    {
50       super(parent);
51    }
52
53    public String JavaDoc[] getFilteredPackages()
54    {
55       return filteredPackages;
56    }
57    public void setFilteredPackages(String JavaDoc[] pkgs)
58    {
59       this.filteredPackages = pkgs;
60    }
61
62    @Override JavaDoc
63    public void addURL(URL JavaDoc url)
64    {
65       super.addURL(url);
66    }
67
68    /**
69     * Overriden to filter out classes in the packages listed in the
70     * filteredPackages settings.
71     *
72     * @param name
73     * @return true if the class should be loaded from the parent class loader,
74     * false if it can be loaded from this class loader.
75     */

76    protected boolean filter(String JavaDoc name)
77    {
78       boolean excludeClass = super.filter(name);
79       if( excludeClass == false )
80       {
81          // Check class against our filtered packages
82
int length = filteredPackages != null ? filteredPackages.length : 0;
83          for(int n = 0; n < length; n ++)
84          {
85             String JavaDoc pkg = filteredPackages[n];
86             if( name.startsWith(pkg) )
87             {
88                excludeClass = true;
89                break;
90             }
91          }
92       }
93       log.trace("filter name="+name+", exclude="+excludeClass);
94       return excludeClass;
95    }
96 }
97
Popular Tags