User: chirino 
  Date: 01/08/17 16:32:26

  Modified:    src/main/org/jboss/mq SpyObjectMessage.java
  Log:
  Rolling back the changes.  Don't think they would have worked
  under different classloaders.
  
  Revision  Changes    Path
  1.4       +70 -83    jbossmq/src/main/org/jboss/mq/SpyObjectMessage.java
  
  Index: SpyObjectMessage.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/SpyObjectMessage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SpyObjectMessage.java     2001/08/17 22:12:50     1.3
  +++ SpyObjectMessage.java     2001/08/17 23:32:26     1.4
  @@ -1,5 +1,10 @@
  +/*
  + * JBossMQ, the OpenSource JMS implementation
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.mq;
  -
   import java.io.*;
   import javax.jms.JMSException;
   import javax.jms.MessageFormatException;
  @@ -12,54 +17,73 @@
    *
    * @author     Norbert Lataille ([EMAIL PROTECTED])
    * @created    August 16, 2001
  - * @version    $Revision: 1.3 $
  + * @version    $Revision: 1.4 $
    */
   public class SpyObjectMessage
          extends SpyMessage
          implements ObjectMessage, Externalizable {
   
      // Attributes ----------------------------------------------------
  -   // We may find out we have to wrap the object in a marshalled object..
  -   //java.rmi.MarshalledObject theObject;
  -   Serializable        theObject=null;
  -     boolean          isSerialized = false;
  -     boolean          isByteArray = false;
  +
  +   boolean          isByteArray = false;
      byte[]           objectBytes = null;
   
      private final static long serialVersionUID = 8809953915407712952L;
   
  -   public void clearBody()
  +   // Public --------------------------------------------------------
  +
  +   public void setObject( Serializable object )
         throws JMSException {
  -      objectBytes = null;
  -      theObject = null;
  -      isSerialized = false;
  -      super.clearBody();
  +      if ( msgReadOnly ) {
  +         throw new MessageNotWriteableException( "setObject" );
  +      }
  +      try {
  +         if ( object instanceof byte[] ) {
  +            //cheat for byte arrays
  +            isByteArray = true;
  +            objectBytes = new byte[( ( byte[] )object ).length];
  +            System.arraycopy( object, 0, objectBytes, 0, objectBytes.length );
  +         } else {
  +            ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
  +            ObjectOutputStream objectOut = new ObjectOutputStream( byteArray );
  +            objectOut.writeObject( object );
  +            objectBytes = byteArray.toByteArray();
  +            objectOut.close();
  +         }
  +      } catch ( IOException e ) {
  +         throw new MessageFormatException( "Object cannot be serialized" );
  +      }
      }
  +
      public Serializable getObject()
         throws JMSException {
  -        
  -        // Have we not deserialized the object yet??? 
  -             if( theObject==null && objectBytes!=null ) {
  -           try {
  -              if ( null != objectBytes ) {
  -                 if ( isByteArray ) {
  -                    theObject = new byte[objectBytes.length];
  -                    System.arraycopy( objectBytes, 0, theObject, 0, 
objectBytes.length );
  -                 } else {
  -                    ObjectInputStream input = new ObjectInputStream( new 
ByteArrayInputStream( objectBytes ) );
  -                    theObject = ( Serializable )input.readObject();
  -                    input.close();
  -                 }
  -              }
  -           } catch ( ClassNotFoundException e ) {
  -              throw new MessageFormatException( "ClassNotFoundException" );
  -           } catch ( IOException e ) {
  -              throw new MessageFormatException( "IOException" );
  -           }
  -             }
  -             
  -      return theObject;
  +
  +      Serializable retVal = null;
  +      try {
  +         if ( null != objectBytes ) {
  +            if ( isByteArray ) {
  +               retVal = new byte[objectBytes.length];
  +               System.arraycopy( objectBytes, 0, retVal, 0, objectBytes.length );
  +            } else {
  +               ObjectInputStream input = new ObjectInputStream( new 
ByteArrayInputStream( objectBytes ) );
  +               retVal = ( Serializable )input.readObject();
  +               input.close();
  +            }
  +         }
  +      } catch ( ClassNotFoundException e ) {
  +         throw new MessageFormatException( "ClassNotFoundException" );
  +      } catch ( IOException e ) {
  +         throw new MessageFormatException( "IOException" );
  +      }
  +      return retVal;
  +   }
  +
  +   public void clearBody()
  +      throws JMSException {
  +      objectBytes = null;
  +      super.clearBody();
      }
  +
      public SpyMessage myClone()
         throws JMSException {
         SpyObjectMessage result = new SpyObjectMessage();
  @@ -71,6 +95,19 @@
         }
         return result;
      }
  +
  +   public void writeExternal( java.io.ObjectOutput out )
  +      throws java.io.IOException {
  +      super.writeExternal( out );
  +      out.writeBoolean( isByteArray );
  +      if ( objectBytes == null ) {
  +         out.writeInt( -1 );
  +      } else {
  +         out.writeInt( objectBytes.length );
  +         out.write( objectBytes );
  +      }
  +   }
  +
      public void readExternal( java.io.ObjectInput in )
         throws java.io.IOException, ClassNotFoundException {
         super.readExternal( in );
  @@ -83,55 +120,5 @@
            in.readFully( objectBytes );
         }
      }
  -   // Public --------------------------------------------------------
  -
  -   public void setObject( Serializable object )
  -      throws JMSException {
  -      if ( msgReadOnly ) {
  -         throw new MessageNotWriteableException( "setObject" );
  -      }
  -      
  -      theObject = object;
  -      isSerialized = false;
  -      objectBytes = null;
  -      
  -   }
  -   public void writeExternal( java.io.ObjectOutput out )
  -      throws java.io.IOException {
  -      super.writeExternal( out );
   
  -        // Check to see if we need to serialize the object
  -        if ( !isSerialized && theObject!=null ) {
  -                
  -                Object object = theObject;
  -                /*
  -                try {
  -                     object = theObject.get();
  -                } catch ( ClassNotFoundException e ) {
  -                        throw new IOException(e.getMessage());
  -                }
  -                */
  -           if ( object instanceof byte[] ) {
  -              //cheat for byte arrays
  -              isByteArray = true;
  -              objectBytes = new byte[( ( byte[] )object ).length];
  -              System.arraycopy( object, 0, objectBytes, 0, objectBytes.length );
  -           } else {
  -              ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
  -              ObjectOutputStream objectOut = new ObjectOutputStream( byteArray );
  -              objectOut.writeObject( object );
  -              objectBytes = byteArray.toByteArray();
  -              objectOut.close();
  -           }
  -           
  -        }
  -         
  -      out.writeBoolean( isByteArray );
  -      if ( objectBytes == null ) {
  -         out.writeInt( -1 );
  -      } else {
  -         out.writeInt( objectBytes.length );
  -         out.write( objectBytes );
  -      }
  -   }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to