aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/LoaderClassPath.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-23 17:13:13 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-23 17:13:13 +0000
commit345ac1e04e6aa481c530d9312e4055a853830b3c (patch)
treea38af5eafa91c21690c7495c65932f13794a98aa /src/main/javassist/LoaderClassPath.java
parentcdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6 (diff)
downloadjavassist-345ac1e04e6aa481c530d9312e4055a853830b3c.tar.gz
javassist-345ac1e04e6aa481c530d9312e4055a853830b3c.zip
new files for version 2.5.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@10 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/LoaderClassPath.java')
-rw-r--r--src/main/javassist/LoaderClassPath.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/javassist/LoaderClassPath.java b/src/main/javassist/LoaderClassPath.java
new file mode 100644
index 00000000..6407e46d
--- /dev/null
+++ b/src/main/javassist/LoaderClassPath.java
@@ -0,0 +1,72 @@
+/*
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package javassist;
+
+import java.io.InputStream;
+import java.lang.ref.WeakReference;
+
+/**
+ * A class search-path representing a class loader.
+ *
+ * <p>It is used for obtaining a class file from the given
+ * class loader by <code>getResourceAsStream()</code>.
+ * The <code>LoaderClassPath</code> refers to the class loader through
+ * <code>WeakReference</code>. If the class loader is garbage collected,
+ * the other search pathes are examined.
+ *
+ * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
+ * @author Shigeru Chiba
+ *
+ * @see javassist.ClassPath
+ * @see ClassPool#insertClassPath(ClassPath)
+ * @see ClassPool#appendClassPath(ClassPath)
+ */
+public class LoaderClassPath implements ClassPath {
+ private WeakReference clref;
+
+ /**
+ * Creates a search path representing a class loader.
+ */
+ public LoaderClassPath(ClassLoader cl) {
+ clref = new WeakReference(cl);
+ }
+
+ public String toString() {
+ Object cl = null;
+ if (clref != null)
+ cl = clref.get();
+
+ return cl == null ? "<null>" : cl.toString();
+ }
+
+ /**
+ * Obtains a class file from the class loader.
+ */
+ public InputStream openClassfile(String classname) {
+ String cname = classname.replace('.', '/') + ".class";
+ ClassLoader cl = (ClassLoader)clref.get();
+ if (cl == null)
+ return null; // not found
+ else
+ return cl.getResourceAsStream(cname);
+ }
+
+ /**
+ * Closes this class path.
+ */
+ public void close() {
+ clref = null;
+ }
+}