2
|
1 |
/*
|
|
2 |
* Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.management.loading;
|
|
27 |
|
|
28 |
|
|
29 |
// java import
|
|
30 |
|
|
31 |
import java.io.*;
|
|
32 |
import java.lang.reflect.Array;
|
|
33 |
|
|
34 |
|
|
35 |
/**
|
|
36 |
* This subclass of ObjectInputStream delegates loading of classes to
|
|
37 |
* an existing MLetClassLoader.
|
|
38 |
*
|
|
39 |
* @since 1.5
|
|
40 |
*/
|
|
41 |
class MLetObjectInputStream extends ObjectInputStream {
|
|
42 |
|
|
43 |
private MLet loader;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Loader must be non-null;
|
|
47 |
*/
|
|
48 |
public MLetObjectInputStream(InputStream in, MLet loader)
|
|
49 |
throws IOException, StreamCorruptedException {
|
|
50 |
|
|
51 |
super(in);
|
|
52 |
if (loader == null) {
|
|
53 |
throw new IllegalArgumentException("Illegal null argument to MLetObjectInputStream");
|
|
54 |
}
|
|
55 |
this.loader = loader;
|
|
56 |
}
|
|
57 |
|
1510
|
58 |
private Class<?> primitiveType(char c) {
|
2
|
59 |
switch(c) {
|
1510
|
60 |
case 'B':
|
2
|
61 |
return Byte.TYPE;
|
|
62 |
|
1510
|
63 |
case 'C':
|
2
|
64 |
return Character.TYPE;
|
|
65 |
|
1510
|
66 |
case 'D':
|
2
|
67 |
return Double.TYPE;
|
|
68 |
|
1510
|
69 |
case 'F':
|
2
|
70 |
return Float.TYPE;
|
|
71 |
|
1510
|
72 |
case 'I':
|
2
|
73 |
return Integer.TYPE;
|
|
74 |
|
1510
|
75 |
case 'J':
|
2
|
76 |
return Long.TYPE;
|
|
77 |
|
1510
|
78 |
case 'S':
|
2
|
79 |
return Short.TYPE;
|
|
80 |
|
1510
|
81 |
case 'Z':
|
2
|
82 |
return Boolean.TYPE;
|
|
83 |
}
|
|
84 |
return null;
|
|
85 |
}
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Use the given ClassLoader rather than using the system class
|
|
89 |
*/
|
1510
|
90 |
@Override
|
|
91 |
protected Class<?> resolveClass(ObjectStreamClass objectstreamclass)
|
2
|
92 |
throws IOException, ClassNotFoundException {
|
|
93 |
|
|
94 |
String s = objectstreamclass.getName();
|
|
95 |
if (s.startsWith("[")) {
|
|
96 |
int i;
|
|
97 |
for (i = 1; s.charAt(i) == '['; i++);
|
1510
|
98 |
Class<?> class1;
|
2
|
99 |
if (s.charAt(i) == 'L') {
|
|
100 |
class1 = loader.loadClass(s.substring(i + 1, s.length() - 1));
|
|
101 |
} else {
|
|
102 |
if (s.length() != i + 1)
|
|
103 |
throw new ClassNotFoundException(s);
|
|
104 |
class1 = primitiveType(s.charAt(i));
|
|
105 |
}
|
|
106 |
int ai[] = new int[i];
|
|
107 |
for (int j = 0; j < i; j++)
|
|
108 |
ai[j] = 0;
|
|
109 |
|
|
110 |
return Array.newInstance(class1, ai).getClass();
|
|
111 |
} else {
|
|
112 |
return loader.loadClass(s);
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Returns the ClassLoader being used
|
|
118 |
*/
|
|
119 |
public ClassLoader getClassLoader() {
|
|
120 |
return loader;
|
|
121 |
}
|
|
122 |
}
|