KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > bytecode > JavaClassLoader


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.bytecode;
31
32 import com.caucho.util.L10N;
33
34 import java.net.URL JavaDoc;
35 import java.util.logging.Logger JavaDoc;
36
37 /**
38  * Manages an introspected java classes.
39  */

40 public class JavaClassLoader extends JClassLoader {
41   protected static final L10N L = new L10N(JavaClassLoader.class);
42   protected static final Logger JavaDoc log =
43     Logger.getLogger(JavaClassLoader.class.getName());
44
45   private ClassLoader JavaDoc _loader;
46
47   public JavaClassLoader()
48   {
49     this(Thread.currentThread().getContextClassLoader());
50   }
51
52   public JavaClassLoader(ClassLoader JavaDoc loader)
53   {
54     _loader = loader;
55   }
56
57   /**
58    * Loads the class.
59    */

60   protected JClass loadClass(String JavaDoc name)
61   {
62     if (name.startsWith("java")) {
63       return getStaticClassLoader().forName(name);
64     }
65
66     String JavaDoc classPath = name.replace('.', '/') + ".class";
67     URL JavaDoc url = _loader.getResource(classPath);
68
69     if (url != null) {
70       JavaClass jClass = new JavaClass(this);
71       jClass.setURL(url);
72
73       jClass.setThisClass(name.replace('.', '/'));
74
75       return jClass;
76     }
77
78     return null;
79   }
80
81   /**
82    * Parses the parameterized type.
83    */

84   protected JType parseParameterizedType(String JavaDoc type)
85   {
86     return new TypeSignatureParser(this, type).nextType();
87   }
88
89   public String JavaDoc toString()
90   {
91     return "JavaClassLoader[]";
92   }
93 }
94
Popular Tags