View Javadoc

1   /*
2    * $Id: ConnectionFactoryWrapper.java 10465 2008-01-22 20:17:19Z akuzmin $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.jms.xa;
12  
13  import java.lang.reflect.Proxy;
14  
15  import javax.jms.Connection;
16  import javax.jms.ConnectionFactory;
17  import javax.jms.JMSException;
18  import javax.jms.QueueConnection;
19  import javax.jms.QueueConnectionFactory;
20  import javax.jms.TopicConnection;
21  import javax.jms.TopicConnectionFactory;
22  import javax.jms.XAConnection;
23  import javax.jms.XAConnectionFactory;
24  import javax.jms.XAQueueConnection;
25  import javax.jms.XAQueueConnectionFactory;
26  import javax.jms.XATopicConnection;
27  import javax.jms.XATopicConnectionFactory;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  
32  public class ConnectionFactoryWrapper
33          implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory
34  {
35      /**
36       * logger used by this class
37       */
38      protected static final transient Log logger = LogFactory.getLog(ConnectionFactoryWrapper.class);
39  
40      protected final Object factory;
41  
42      public ConnectionFactoryWrapper(Object factory)
43      {
44          this.factory = factory;
45      }
46  
47      /*
48       * (non-Javadoc)
49       * 
50       * @see javax.jms.ConnectionFactory#createConnection()
51       */
52      public Connection createConnection() throws JMSException
53      {
54          XAConnection xac = ((XAConnectionFactory) factory).createXAConnection();
55          Connection proxy = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
56                                                                 new Class[]{Connection.class}, new ConnectionInvocationHandler(xac));
57          return proxy;
58      }
59  
60      /*
61       * (non-Javadoc)
62       * 
63       * @see javax.jms.ConnectionFactory#createConnection(java.lang.String,
64       *      java.lang.String)
65       */
66      public Connection createConnection(String username, String password) throws JMSException
67      {
68          XAConnection xac = ((XAConnectionFactory) factory).createXAConnection(username, password);
69          Connection proxy = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
70                                                                 new Class[]{Connection.class}, new ConnectionInvocationHandler(xac));
71          return proxy;
72      }
73  
74      /*
75       * (non-Javadoc)
76       * 
77       * @see javax.jms.QueueConnectionFactory#createQueueConnection()
78       */
79      public QueueConnection createQueueConnection() throws JMSException
80      {
81          XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory).createXAQueueConnection();
82          QueueConnection proxy = (QueueConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
83                                                                           new Class[]{QueueConnection.class}, new ConnectionInvocationHandler(xaqc));
84          return proxy;
85      }
86  
87      /*
88       * (non-Javadoc)
89       * 
90       * @see javax.jms.QueueConnectionFactory#createQueueConnection(java.lang.String,
91       *      java.lang.String)
92       */
93      public QueueConnection createQueueConnection(String username, String password) throws JMSException
94      {
95          XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory).createXAQueueConnection(username,
96                                                                                                password);
97          QueueConnection proxy = (QueueConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
98                                                                           new Class[]{QueueConnection.class}, new ConnectionInvocationHandler(xaqc));
99          return proxy;
100     }
101 
102     /*
103      * (non-Javadoc)
104      * 
105      * @see javax.jms.TopicConnectionFactory#createTopicConnection()
106      */
107     public TopicConnection createTopicConnection() throws JMSException
108     {
109         XATopicConnection xatc = ((XATopicConnectionFactory) factory).createXATopicConnection();
110         TopicConnection proxy = (TopicConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
111                                                                          new Class[]{TopicConnection.class}, new ConnectionInvocationHandler(xatc));
112         return proxy;
113     }
114 
115     /*
116      * (non-Javadoc)
117      * 
118      * @see javax.jms.TopicConnectionFactory#createTopicConnection(java.lang.String,
119      *      java.lang.String)
120      */
121     public TopicConnection createTopicConnection(String username, String password) throws JMSException
122     {
123         XATopicConnection xatc = ((XATopicConnectionFactory) factory).createXATopicConnection(username,
124                                                                                               password);
125         TopicConnection proxy = (TopicConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
126                                                                          new Class[]{TopicConnection.class}, new ConnectionInvocationHandler(xatc));
127         return proxy;
128     }
129 
130 }