1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.services.io.ApplicationObjectInputStream |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.services.io; |
22 | |
23 | import org.apache.derby.iapi.services.loader.ClassFactory; |
24 | |
25 | import java.io.ObjectStreamClass; |
26 | import java.io.ObjectInputStream; |
27 | import java.io.IOException; |
28 | import java.io.InputStream; |
29 | |
30 | /** |
31 | An object input stream that implements resolve class in order |
32 | to load the class through the ClassFactory.loadApplicationClass method. |
33 | */ |
34 | class ApplicationObjectInputStream extends ObjectInputStream |
35 | implements ErrorObjectInput |
36 | { |
37 | |
38 | protected ClassFactory cf; |
39 | protected ObjectStreamClass initialClass; |
40 | |
41 | ApplicationObjectInputStream(InputStream in, ClassFactory cf) |
42 | throws IOException { |
43 | super(in); |
44 | this.cf = cf; |
45 | } |
46 | |
47 | protected Class resolveClass(ObjectStreamClass v) |
48 | throws IOException, ClassNotFoundException { |
49 | |
50 | if (initialClass == null) |
51 | initialClass = v; |
52 | |
53 | if (cf != null) |
54 | return cf.loadApplicationClass(v); |
55 | |
56 | throw new ClassNotFoundException(v.getName()); |
57 | } |
58 | |
59 | public String getErrorInfo() { |
60 | if (initialClass == null) |
61 | return ""; |
62 | |
63 | return initialClass.getName() + " (serialVersionUID=" |
64 | + initialClass.getSerialVersionUID() + ")"; |
65 | } |
66 | |
67 | public Exception getNestedException() { |
68 | return null; |
69 | } |
70 | |
71 | } |