1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.InputStream;
25
26 import java.net.MalformedURLException;
27 import java.net.URL;
28
29 import javassist.ClassPath;
30 import javassist.ClassPool;
31 import javassist.CtClass;
32
33
34 /***
35 * DOCUMENT ME!
36 *
37 * @author $author$
38 * @version $Revision: 1.3 $
39 */
40 public class EmptyClassClassPath implements ClassPath {
41 /***
42 * Creates a new EmptyClassClassPath object.
43 */
44 public EmptyClassClassPath() {
45 }
46
47 /***
48 * DOCUMENT ME!
49 *
50 * @param className DOCUMENT ME!
51 *
52 * @return DOCUMENT ME!
53 */
54 public InputStream openClassfile(String className) {
55 return new ByteArrayInputStream(createEmptyClass(className));
56 }
57
58 /***
59 * DOCUMENT ME!
60 *
61 * @param className DOCUMENT ME!
62 *
63 * @return DOCUMENT ME!
64 */
65 private static byte[] createEmptyClass(String className) {
66 try {
67 ClassPool pool = new ClassPool(null);
68 pool.appendSystemPath();
69
70 CtClass clazz = pool.makeClass(className);
71
72 return clazz.toBytecode();
73 } catch (Exception e) {
74
75 throw new RuntimeException(e.getMessage());
76 }
77 }
78
79 /***
80 * DOCUMENT ME!
81 *
82 * @param classname DOCUMENT ME!
83 *
84 * @return DOCUMENT ME!
85 */
86 public URL find(String classname) {
87 String cname = classname.replace('.', '/') + ".class";
88
89 try {
90 return new URL("file:/ByteArrayClassPath/" + cname);
91 } catch (MalformedURLException e) {
92 }
93
94 return null;
95 }
96
97 /***
98 * DOCUMENT ME!
99 */
100 public void close() {
101 }
102 }