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