View Javadoc

1   /*
2    * $Id: AbstractRedeliveryHandler.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.jms;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleException;
15  import org.mule.api.MuleMessage;
16  
17  import javax.jms.JMSException;
18  import javax.jms.Message;
19  
20  public abstract class AbstractRedeliveryHandler implements RedeliveryHandler
21  {
22      protected JmsConnector connector;
23  
24      public abstract void handleRedelivery(Message message) throws JMSException, MuleException;
25  
26      /**
27       * The connector associated with this handler is set before
28       * <code>handleRedelivery()</code> is called
29       * 
30       * @param connector the connector associated with this handler
31       */
32      public void setConnector(JmsConnector connector)
33      {
34          this.connector = connector;
35      }
36      
37      protected MuleMessage createMuleMessage(Message message)
38      {
39          try
40          {
41              String encoding = connector.getMuleContext().getConfiguration().getDefaultEncoding();
42              return connector.createMuleMessageFactory().create(message, encoding);
43          }
44          catch (Exception e)
45          {
46              return new DefaultMuleMessage(message, connector.getMuleContext());
47          }
48      }
49  }