blob: a2bcf77e4a9114d6663fc44abffb5f41ba77ccf2 (
plain) (
blame)
1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*******************************************************************************
* Copyright (c) 2004 Peter Nehrer and Composent, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Peter Nehrer - initial API and implementation
*******************************************************************************/
package org.eclipse.ecf.provider.util;
import java.io.*;
/**
* Restores Java objects from the underlying stream by using the classloader
* returned from the call to given IClassLoaderMapper with the Namespace/ID
* specified by the associated IdentifiableObjectOutputStream.
*
*/
public class IdentifiableObjectInputStream extends ObjectInputStream {
IClassLoaderMapper mapper;
public IdentifiableObjectInputStream(IClassLoaderMapper map, InputStream ins) throws IOException {
super(ins);
this.mapper = map;
}
/*
* (non-Javadoc)
*
* @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
*/
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
String name = readUTF();
if (name == null || mapper == null) {
return super.resolveClass(desc);
}
ClassLoader cl = mapper.mapNameToClassLoader(name);
if (cl == null)
return super.resolveClass(desc);
return Class.forName(desc.getName(), true, cl);
}
}
|