001: /*
002: * $Id: ConnectionFactoryWrapper.java 10590 2008-01-29 01:39:47Z tcarlson $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.transport.jms.xa;
012:
013: import java.lang.reflect.Proxy;
014:
015: import javax.jms.Connection;
016: import javax.jms.ConnectionFactory;
017: import javax.jms.JMSException;
018: import javax.jms.QueueConnection;
019: import javax.jms.QueueConnectionFactory;
020: import javax.jms.TopicConnection;
021: import javax.jms.TopicConnectionFactory;
022: import javax.jms.XAConnection;
023: import javax.jms.XAConnectionFactory;
024: import javax.jms.XAQueueConnection;
025: import javax.jms.XAQueueConnectionFactory;
026: import javax.jms.XATopicConnection;
027: import javax.jms.XATopicConnectionFactory;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031:
032: public class ConnectionFactoryWrapper implements ConnectionFactory,
033: QueueConnectionFactory, TopicConnectionFactory {
034: /**
035: * logger used by this class
036: */
037: protected static final transient Log logger = LogFactory
038: .getLog(ConnectionFactoryWrapper.class);
039:
040: protected final Object factory;
041:
042: public ConnectionFactoryWrapper(Object factory) {
043: this .factory = factory;
044: }
045:
046: /*
047: * (non-Javadoc)
048: *
049: * @see javax.jms.ConnectionFactory#createConnection()
050: */
051: public Connection createConnection() throws JMSException {
052: XAConnection xac = ((XAConnectionFactory) factory)
053: .createXAConnection();
054: Connection proxy = (Connection) Proxy.newProxyInstance(
055: Connection.class.getClassLoader(),
056: new Class[] { Connection.class },
057: new ConnectionInvocationHandler(xac));
058: return proxy;
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see javax.jms.ConnectionFactory#createConnection(java.lang.String,
065: * java.lang.String)
066: */
067: public Connection createConnection(String username, String password)
068: throws JMSException {
069: XAConnection xac = ((XAConnectionFactory) factory)
070: .createXAConnection(username, password);
071: Connection proxy = (Connection) Proxy.newProxyInstance(
072: Connection.class.getClassLoader(),
073: new Class[] { Connection.class },
074: new ConnectionInvocationHandler(xac));
075: return proxy;
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see javax.jms.QueueConnectionFactory#createQueueConnection()
082: */
083: public QueueConnection createQueueConnection() throws JMSException {
084: XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory)
085: .createXAQueueConnection();
086: QueueConnection proxy = (QueueConnection) Proxy
087: .newProxyInstance(Connection.class.getClassLoader(),
088: new Class[] { QueueConnection.class },
089: new ConnectionInvocationHandler(xaqc));
090: return proxy;
091: }
092:
093: /*
094: * (non-Javadoc)
095: *
096: * @see javax.jms.QueueConnectionFactory#createQueueConnection(java.lang.String,
097: * java.lang.String)
098: */
099: public QueueConnection createQueueConnection(String username,
100: String password) throws JMSException {
101: XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory)
102: .createXAQueueConnection(username, password);
103: QueueConnection proxy = (QueueConnection) Proxy
104: .newProxyInstance(Connection.class.getClassLoader(),
105: new Class[] { QueueConnection.class },
106: new ConnectionInvocationHandler(xaqc));
107: return proxy;
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see javax.jms.TopicConnectionFactory#createTopicConnection()
114: */
115: public TopicConnection createTopicConnection() throws JMSException {
116: XATopicConnection xatc = ((XATopicConnectionFactory) factory)
117: .createXATopicConnection();
118: TopicConnection proxy = (TopicConnection) Proxy
119: .newProxyInstance(Connection.class.getClassLoader(),
120: new Class[] { TopicConnection.class },
121: new ConnectionInvocationHandler(xatc));
122: return proxy;
123: }
124:
125: /*
126: * (non-Javadoc)
127: *
128: * @see javax.jms.TopicConnectionFactory#createTopicConnection(java.lang.String,
129: * java.lang.String)
130: */
131: public TopicConnection createTopicConnection(String username,
132: String password) throws JMSException {
133: XATopicConnection xatc = ((XATopicConnectionFactory) factory)
134: .createXATopicConnection(username, password);
135: TopicConnection proxy = (TopicConnection) Proxy
136: .newProxyInstance(Connection.class.getClassLoader(),
137: new Class[] { TopicConnection.class },
138: new ConnectionInvocationHandler(xatc));
139: return proxy;
140: }
141:
142: }
|