001 package org.apache.fulcrum.pool; 002 003 004 /* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024 import java.io.InputStream; 025 import java.io.ObjectInputStream; 026 import java.io.ObjectStreamClass; 027 import java.io.IOException; 028 029 /** 030 * A deserialization stream for a specific class loader context. 031 * 032 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a> 033 * @version $Id: ObjectInputStreamForContext.java 670330 2008-06-22 09:37:21Z tv $ 034 */ 035 public class ObjectInputStreamForContext extends ObjectInputStream 036 { 037 /** 038 * The class loader of the context. 039 */ 040 private ClassLoader classLoader; 041 042 public ObjectInputStreamForContext() 043 throws IOException 044 { 045 // this is to make the proxy happy. 046 } 047 048 /** 049 * Contructs a new object stream for a context. 050 * 051 * @param in the serialized input stream. 052 * @param loader the class loader of the context. 053 * @throws IOException on errors. 054 */ 055 public ObjectInputStreamForContext(InputStream in, 056 ClassLoader loader) 057 throws IOException 058 { 059 super(in); 060 classLoader = loader; 061 } 062 063 protected Class resolveClass(ObjectStreamClass v) 064 throws IOException, 065 ClassNotFoundException 066 { 067 return classLoader == null ? 068 super.resolveClass(v) : classLoader.loadClass(v.getName()); 069 } 070 }