1 package org.apache.fulcrum.pool; 2 3 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 */ 22 23 24 import java.io.InputStream; 25 import java.io.ObjectInputStream; 26 import java.io.ObjectStreamClass; 27 import java.io.IOException; 28 29 /** 30 * A deserialization stream for a specific class loader context. 31 * 32 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a> 33 * @version $Id$ 34 */ 35 public class ObjectInputStreamForContext extends ObjectInputStream 36 { 37 /** 38 * The class loader of the context. 39 */ 40 private ClassLoader classLoader; 41 42 public ObjectInputStreamForContext() 43 throws IOException 44 { 45 // this is to make the proxy happy. 46 } 47 48 /** 49 * Contructs a new object stream for a context. 50 * 51 * @param in the serialized input stream. 52 * @param loader the class loader of the context. 53 * @throws IOException on errors. 54 */ 55 public ObjectInputStreamForContext(InputStream in, 56 ClassLoader loader) 57 throws IOException 58 { 59 super(in); 60 classLoader = loader; 61 } 62 63 protected Class resolveClass(ObjectStreamClass v) 64 throws IOException, 65 ClassNotFoundException 66 { 67 return classLoader == null ? 68 super.resolveClass(v) : classLoader.loadClass(v.getName()); 69 } 70 }