diff options
| author | slewis | 2005-03-15 06:39:19 +0000 |
|---|---|---|
| committer | slewis | 2005-03-15 06:39:19 +0000 |
| commit | 862d3f0097f894c8d9c320bd2b205b463c55313b (patch) | |
| tree | 8654d1018b479afa79b6d9700f970dbe65d78bcb | |
| parent | bd77f9e6d2db3a71ce349c1dcd8f79d78a3ff5eb (diff) | |
| download | org.eclipse.ecf-862d3f0097f894c8d9c320bd2b205b463c55313b.tar.gz org.eclipse.ecf-862d3f0097f894c8d9c320bd2b205b463c55313b.tar.xz org.eclipse.ecf-862d3f0097f894c8d9c320bd2b205b463c55313b.zip | |
Added IdentifiableObjectInputStream and IdentifiableOutputStream. These two stream classes are designed to allow the dynamic lookup of classloader from and ID
2 files changed, 97 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/util/IdentifiableObjectInputStream.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/util/IdentifiableObjectInputStream.java new file mode 100644 index 000000000..1ca8f187e --- /dev/null +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/util/IdentifiableObjectInputStream.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.core.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; +import org.eclipse.ecf.core.identity.ID; + +/** + * 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. + * + * @author pnehrer + * @author slewis + */ +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 { + + ID annotateID = (ID) readObject(); + if (annotateID == null || mapper == null) { + return super.resolveClass(desc); + } else { + ClassLoader cl = mapper.mapIDToClassLoader(annotateID); + if (cl == null) return super.resolveClass(desc); + else return cl.loadClass(desc.getName()); + } + } + +} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/util/IdentifiableObjectOutputStream.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/util/IdentifiableObjectOutputStream.java new file mode 100644 index 000000000..07b6db021 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/util/IdentifiableObjectOutputStream.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.core.util; + +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import org.eclipse.ecf.core.identity.ID; + +/** + * Stores Java objects in the underlying stream in an manner that allows corresponding + * input stream to use ID to lookup appropriate associated classloader (via IClassLoaderMapper). + * + * @author pnehrer + * @author slewis + */ +public class IdentifiableObjectOutputStream extends ObjectOutputStream { + + ID objectID = null; + + public IdentifiableObjectOutputStream(ID id, OutputStream outs) throws IOException { + super(outs); + this.objectID = id; + } + + /* + * (non-Javadoc) + * + * @see java.io.ObjectOutputStream#annotateClass(java.lang.Class) + */ + protected void annotateClass(Class cl) throws IOException { + writeObject(objectID); + } + +} |
