⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionfactoryimpl.java

📁 Java实现的Socket框架
💻 JAVA
字号:
/**
 * Project:ms4j
 * Date:2007-2-15 
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */
package com.sunjob.ms4j.client;

import java.io.Serializable;
import java.util.Hashtable;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.XAConnection;
import javax.jms.XAConnectionFactory;
import javax.jms.XAQueueConnection;
import javax.jms.XAQueueConnectionFactory;
import javax.jms.XATopicConnection;
import javax.jms.XATopicConnectionFactory;

/**
 * @author sunjob
 *
 */
public class ConnectionFactoryImpl implements 
        ConnectionFactory,QueueConnectionFactory, TopicConnectionFactory,
        XAConnectionFactory,XAQueueConnectionFactory, XATopicConnectionFactory, 
        Serializable {
	
	private final static long serialVersionUID = -2810634789345348999L;

	private Hashtable env = null;
	
	public ConnectionFactoryImpl(Hashtable env)
	{
		this.env = env;
	}
	/* (non-Javadoc)
	 * @see javax.jms.ConnectionFactory#createConnection()
	 */
	public Connection createConnection() throws JMSException {
		return createConnection(null,null);
	}

	/* (non-Javadoc)
	 * @see javax.jms.ConnectionFactory#createConnection(java.lang.String, java.lang.String)
	 */
	public Connection createConnection(String username, String password)
			throws JMSException {
		return this.createInternalConnection(username , password, ConnectionImpl.GENERATE_CONNECTION_TYPE, false);
	}

	/* (non-Javadoc)
	 * @see javax.jms.QueueConnectionFactory#createQueueConnection()
	 */
	public QueueConnection createQueueConnection() throws JMSException {
		return createQueueConnection(null,null);
	}

	/* (non-Javadoc)
	 * @see javax.jms.QueueConnectionFactory#createQueueConnection(java.lang.String, java.lang.String)
	 */
	public QueueConnection createQueueConnection(String username, String password)
			throws JMSException {
		return this.createInternalConnection(username , password, ConnectionImpl.QUEUE_CONNECTION_TYPE, false);
	}

	/* (non-Javadoc)
	 * @see javax.jms.TopicConnectionFactory#createTopicConnection()
	 */
	public TopicConnection createTopicConnection() throws JMSException {
		return createTopicConnection(null,null);
	}

	/* (non-Javadoc)
	 * @see javax.jms.TopicConnectionFactory#createTopicConnection(java.lang.String, java.lang.String)
	 */
	public TopicConnection createTopicConnection(String username, String password)
			throws JMSException {
		return this.createInternalConnection(username , password, ConnectionImpl.TOPIC_CONNECTION_TYPE, false);
	}

	/* (non-Javadoc)
	 * @see javax.jms.XAConnectionFactory#createXAConnection()
	 */
	public XAConnection createXAConnection() throws JMSException {
		return createXAConnection(null,null);
	}

	/* (non-Javadoc)
	 * @see javax.jms.XAConnectionFactory#createXAConnection(java.lang.String, java.lang.String)
	 */
	public XAConnection createXAConnection(String username, String password)
			throws JMSException {
		return this.createInternalConnection(username , password, ConnectionImpl.GENERATE_CONNECTION_TYPE, true);
	}

	/* (non-Javadoc)
	 * @see javax.jms.XAQueueConnectionFactory#createXAQueueConnection()
	 */
	public XAQueueConnection createXAQueueConnection() throws JMSException {
		return createXAQueueConnection(null,null);
	}

	/* (non-Javadoc)
	 * @see javax.jms.XAQueueConnectionFactory#createXAQueueConnection(java.lang.String, java.lang.String)
	 */
	public XAQueueConnection createXAQueueConnection(String username, String password)
			throws JMSException {
		return this.createInternalConnection(username , password, ConnectionImpl.QUEUE_CONNECTION_TYPE, true);
	}

	/* (non-Javadoc)
	 * @see javax.jms.XATopicConnectionFactory#createXATopicConnection()
	 */
	public XATopicConnection createXATopicConnection() throws JMSException {
		return createXATopicConnection(null,null);
	}

	/* (non-Javadoc)
	 * @see javax.jms.XATopicConnectionFactory#createXATopicConnection(java.lang.String, java.lang.String)
	 */
	public XATopicConnection createXATopicConnection(String username, String password)
			throws JMSException {
		return this.createInternalConnection(username , password, ConnectionImpl.TOPIC_CONNECTION_TYPE, true);
	}
	///////////////////////////////////////////////////////////////////////
    /**
     * 
     * @param username
     * @param password
     * @param connType
     * @param supportXA
     * @return
     */
	private ConnectionImpl createInternalConnection(String username, String password, int connType, boolean supportXA)
	throws JMSException 
	{
		ConnectionImpl conn = null;
		if(supportXA)
		{
			throw new JMSException("Not support XA.");
		}
		else
		{
			conn = new ConnectionImpl(username, password, connType, supportXA, this.env);
		}
		return conn;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -