1 package org.codehaus.classworlds;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.net.URL;
30 import java.util.Enumeration;
31
32 @Deprecated
33 public class DefaultClassRealm implements ClassRealm {
34 private ClassRealmAdapter adapter;
35
36 public DefaultClassRealm(ClassWorld world, String id) {
37 this(world, id, null);
38 }
39
40 public DefaultClassRealm(ClassWorld world, String id, ClassLoader foreignClassLoader) {
41 this.adapter = ClassRealmAdapter.getInstance(new org.codehaus.plexus.classworlds.realm.ClassRealm(
42 ClassWorldReverseAdapter.getInstance(world), id, foreignClassLoader));
43 }
44
45 public URL[] getConstituents() {
46 return adapter.getConstituents();
47 }
48
49 public ClassRealm getParent() {
50 return adapter.getParentRealm();
51 }
52
53 public void setParent(ClassRealm parent) {
54 adapter.setParent(parent);
55 }
56
57 public String getId() {
58 return adapter.getId();
59 }
60
61 public ClassWorld getWorld() {
62 return adapter.getWorld();
63 }
64
65 public void importFrom(String realmId, String packageName) throws NoSuchRealmException {
66 adapter.importFrom(realmId, packageName);
67 }
68
69 public void addConstituent(URL constituent) {
70 adapter.addConstituent(constituent);
71 }
72
73
74
75
76
77
78
79
80
81
82
83 public void addConstituent(String constituent, byte[] b) throws ClassNotFoundException {
84 try {
85 File path, file;
86 if (constituent.lastIndexOf('.') != -1) {
87 path = new File("byteclass/"
88 + constituent
89 .substring(0, constituent.lastIndexOf('.') + 1)
90 .replace('.', File.separatorChar));
91
92 file = new File(path, constituent.substring(constituent.lastIndexOf('.') + 1) + ".class");
93 } else {
94 path = new File("byteclass/");
95
96 file = new File(path, constituent + ".class");
97 }
98
99 addConstituent(new URL(null, file.toURI().toURL().toExternalForm(), new BytesURLStreamHandler(b)));
100 } catch (java.io.IOException e) {
101 throw new ClassNotFoundException("Couldn't load byte stream.", e);
102 }
103 }
104
105 public ClassRealm locateSourceRealm(String classname) {
106 return adapter.locateSourceRealm(classname);
107 }
108
109 public ClassLoader getClassLoader() {
110 return adapter.getClassLoader();
111 }
112
113 public ClassRealm createChildRealm(String id) throws DuplicateRealmException {
114 return adapter.createChildRealm(id);
115 }
116
117
118
119
120
121 public Class loadClass(String name) throws ClassNotFoundException {
122 return adapter.loadClass(name);
123 }
124
125 public URL getResource(String name) {
126 return adapter.getResource(name);
127 }
128
129 public InputStream getResourceAsStream(String name) {
130 return adapter.getResourceAsStream(name);
131 }
132
133 public Enumeration findResources(String name) throws IOException {
134 return adapter.findResources(name);
135 }
136
137 public void display() {
138 adapter.display();
139 }
140 }