hammant     01/03/17 09:03:05

  Modified:    src/java/org/apache/cornerstone/blocks/masterstore
                        File_Persistent_Object_Repository.java
               src/java/org/apache/cornerstone/services/store
                        ObjectRepository.java
  Added:       src/java/org/apache/cornerstone/blocks/masterstore
                        FileStoreObjectInputStream.java
  Log:
  new get() method for ObjectRepository to allow the retrieval of serialized classes 
under very changable classloading situations.
  
  Revision  Changes    Path
  1.3       +39 -8     
jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/File_Persistent_Object_Repository.java
  
  Index: File_Persistent_Object_Repository.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/File_Persistent_Object_Repository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- File_Persistent_Object_Repository.java    2001/03/13 04:51:56     1.2
  +++ File_Persistent_Object_Repository.java    2001/03/17 17:03:04     1.3
  @@ -11,6 +11,8 @@
   import java.io.InputStream;
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
  +import java.io.StreamCorruptedException;
  +import java.io.ObjectStreamClass;
   import java.io.OutputStream;
   import org.apache.cornerstone.services.Store;
   import org.apache.cornerstone.services.store.ObjectRepository;
  @@ -23,11 +25,11 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Paul Hammant</a>
    */
  -public class File_Persistent_Object_Repository 
  -    extends AbstractFileRepository  
  +public class File_Persistent_Object_Repository
  +    extends AbstractFileRepository
       implements Store.ObjectRepository, ObjectRepository
   {
  -    protected String getExtensionDecorator() 
  +    protected String getExtensionDecorator()
       {
           return ".FileObjectStore";
       }
  @@ -45,7 +47,7 @@
               {
                   final ObjectInputStream stream = new ObjectInputStream( inputStream 
);
                   final Object object = stream.readObject();
  -                if( DEBUG ) 
  +                if( DEBUG )
                   {
                       getLogger().debug( "returning object " + object + " for key " + 
key );
                   }
  @@ -55,16 +57,44 @@
               {
                   inputStream.close();
               }
  -        } 
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new RuntimeException( "Exception caught while retrieving an 
object: " + e );
  +        }
  +    }
  +
  +    public synchronized Object get( final String key , final ClassLoader 
classLoader )
  +    {
  +        try
  +        {
  +            final InputStream inputStream = getInputStream( key );
  +
  +            try
  +            {
  +                final ObjectInputStream stream = new FileStoreObjectInputStream( 
classLoader, inputStream );
  +                final Object object = stream.readObject();
  +                if( DEBUG )
  +                {
  +                    getLogger().debug( "returning object " + object + " for key " + 
key );
  +                }
  +                return object;
  +            }
  +            finally
  +            {
  +                inputStream.close();
  +            }
  +        }
           catch( final Exception e )
           {
               throw new RuntimeException( "Exception caught while retrieving an 
object: " + e );
           }
  +
       }
  -   
  +
       /**
        * Store the given object and associates it to the given key
  -     */ 
  +     */
       public synchronized void put( final String key, final Object value )
       {
           try
  @@ -81,10 +111,11 @@
               {
                   outputStream.close();
               }
  -        } 
  +        }
           catch( final Exception e )
           {
               throw new RuntimeException( "Exception caught while storing an object: 
" + e );
           }
       }
  +
   }
  
  
  
  1.1                  
jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/FileStoreObjectInputStream.java
  
  Index: FileStoreObjectInputStream.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.cornerstone.blocks.masterstore;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.StreamCorruptedException;
  import java.io.ObjectStreamClass;
  import java.io.OutputStream;
  
  /**
   * A special ObjectInputStream to handle highly transient classes hosted
   * by Avalon components that are juggling many classloaders.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Paul Hammant</a>
   */
  
  class FileStoreObjectInputStream extends ObjectInputStream
  {
      private ClassLoader classLoader;
      private FileStoreObjectInputStream(ClassLoader classLoader, InputStream in) 
throws IOException, StreamCorruptedException
      {
          super(in);
          this.classLoader = classLoader;
      }
      protected Class resolveClass(ObjectStreamClass v) throws IOException, 
ClassNotFoundException
      {
          Class cl = Class.forName(v.getName(), false, classLoader);
          if (cl !=null)
          {
              return cl; // the classloader knows of the class
          }
          else
          {
              return super.resolveClass(v); // classloader knows not of class, let the 
super classloader do it
          }
      }
  }
  
  
  1.2       +3 -1      
jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/services/store/ObjectRepository.java
  
  Index: ObjectRepository.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/services/store/ObjectRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectRepository.java     2001/03/13 04:52:01     1.1
  +++ ObjectRepository.java     2001/03/17 17:03:04     1.2
  @@ -14,10 +14,12 @@
    *
    * @author Federico Barbieri <[EMAIL PROTECTED]>
    */
  -public interface ObjectRepository 
  +public interface ObjectRepository
       extends Repository
   {
       Object get( String key );
  +
  +    Object get( String key , ClassLoader classLoader );
   
       void put( String key, Object value );
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to