package org.realityforge.jml;

import java.util.Enumeration;
import javax.jms.JMSException;
import javax.jms.Message;

/**
 * Class containing utility methods.
 */
final class MessageUtil
{
  @SuppressWarnings( { "unchecked" } )
  static <T> T castToType( final Message message, final Class<T> type )
    throws Exception
  {
    if( type.isInstance( message ) )
    {
      return (T)message;
    }
    else
    {
      final String errorMessage =
        "is not of the expected type " + type.getName() + ". Actual Message Type: " + message.getClass().getName();
      throw exceptionFor( message, errorMessage, null );
    }
  }

  static Exception exceptionFor( final Message message, final String description, final Exception e )
    throws Exception
  {
    return new Exception( "Message with ID = " + message.getJMSMessageID() + " " + description, e );
  }

  static void copyMessageHeaders( final Message from, final Message to )
    throws JMSException
  {
    //set the developer assigned headers
    to.setJMSCorrelationID( from.getJMSCorrelationID() );
    to.setJMSReplyTo( from.getJMSReplyTo() );
    to.setJMSType( from.getJMSType() );

    // these are not used by the JMS provider ... but we use them to keep
    // track of values and then explicitly pass them to send method.
    to.setJMSDeliveryMode( from.getJMSDeliveryMode() );
    to.setJMSPriority( from.getJMSPriority() );
    to.setJMSExpiration( from.getJMSExpiration() );

    // copy all the application specific properties to new message
    final Enumeration propertyNames = from.getPropertyNames();
    while( propertyNames.hasMoreElements() )
    {
      final String name = (String)propertyNames.nextElement();
      final Object value = from.getObjectProperty( name );
      to.setObjectProperty( name, value );
    }
  }
}

@@ -157,16 +157,23 @@
 ds.%0A */%0A
+public 
 final cl
@@ -864,24 +864,31 @@
 e );%0A  %7D%0A%0A  
+public 
 static void 

Make copyMessageHeaders public