01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.faces.loader;
23:
24: import org.apache.log4j.Logger;
25:
26: import java.net.URL;
27: import java.net.URLClassLoader;
28: import java.util.HashMap;
29: import java.util.Map;
30:
31: /**
32: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
33: * @version $Revision: 8784 $
34: */
35: public class FacesClassLoader extends URLClassLoader {
36:
37: /** . */
38: private final Logger log = Logger.getLogger(FacesClassLoader.class);
39:
40: public FacesClassLoader(URL[] urls, ClassLoader classLoader) {
41: super (urls, classLoader);
42: }
43:
44: private final Map cache = new HashMap();
45:
46: protected synchronized Class loadClass(String name, boolean resolve)
47: throws ClassNotFoundException {
48: if (name.startsWith("javax.faces")
49: || name.startsWith("org.apache.myfaces")) {
50: log.debug("Want to load " + name + " locally");
51: return locateClass(name);
52: }
53:
54: //
55: try {
56: log.debug("Want to load " + name + " will delegate");
57: return super .loadClass(name, resolve);
58: } catch (ClassNotFoundException e) {
59: log.debug("Not found in the parent will try to load "
60: + name + " locally");
61: return locateClass(name);
62: }
63: }
64:
65: private Class locateClass(String name)
66: throws ClassNotFoundException {
67: //
68: Class clazz = (Class) cache.get(name);
69:
70: //
71: if (clazz == null) {
72: clazz = findClass(name);
73: cache.put(name, clazz);
74: }
75:
76: //
77: return clazz;
78: }
79:
80: }
|