View Javadoc

1   /***************************************************************************************
2    * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package org.codehaus.aspectwerkz;
9   
10  import java.io.IOException;
11  import java.io.InputStream;
12  import java.io.ObjectInputStream;
13  import java.io.ObjectStreamClass;
14  
15  /***
16   * Fixes the ObjectInputStream class, which does not always resolve the class correctly in complex 
17   * class loader hierarchies.
18   *
19   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér</a>
20   */
21  public class UnbrokenObjectInputStream extends ObjectInputStream {
22      
23      /***
24       * Creates a a new instance.
25       * 
26       * @throws IOException
27       * @throws SecurityException
28       */
29      public UnbrokenObjectInputStream() throws IOException, SecurityException {
30          super();
31      }
32  
33      /***
34       * Creates a new instance.
35       * 
36       * @param in the input stream to deserialize the object from.
37       * @throws IOException
38       */
39      public UnbrokenObjectInputStream(final InputStream in) throws IOException {
40          super(in);
41      }
42  
43      /***
44       * Overrides the parents resolveClass method and resolves the class using the context class loader
45       * instead of Class.forName().
46       */
47      protected Class resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
48          try {
49              return Thread.currentThread().getContextClassLoader().loadClass(desc.getName());
50          } catch (ClassNotFoundException ex) {
51              return super.resolveClass(desc);
52          }
53      }
54  }