001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ConnectionManagerFactory.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.proxy.connection;
030:
031: import com.sun.jbi.binding.proxy.LocalStringKeys;
032:
033: import com.sun.jbi.binding.proxy.util.Translator;
034:
035: import com.sun.jbi.binding.proxy.jms.JMSConnectionManager;
036: import com.sun.jbi.binding.proxy.jms.IMQConnectionHelper;
037: import com.sun.jbi.binding.proxy.jms.JMSConnectionHelper;
038: import com.sun.jbi.binding.proxy.jms.JBossMQConnectionHelper;
039:
040: import javax.naming.InitialContext;
041:
042: /**
043: * Factory for different remote connection managers.
044: * @author Sun Microsystems, Inc
045: */
046: public class ConnectionManagerFactory {
047: /**
048: * ConnectionManagerFactory singleton.
049: */
050: private static ConnectionManagerFactory sCMF;
051: private final InitialContext mContext;
052:
053: /**
054: * Constructor
055: * Private constructor to facilitate a singleton.
056: */
057: private ConnectionManagerFactory(InitialContext context) {
058: mContext = context;
059: }
060:
061: /**
062: * Returns a singleton instance of the ConnectionManagerFactory class.
063: * @return The instance of the ConnectionManagerFactory
064: */
065: public static ConnectionManagerFactory getInstance(
066: InitialContext context) {
067: if (null == sCMF) {
068: sCMF = new ConnectionManagerFactory(context);
069: }
070: return sCMF;
071: }
072:
073: /**
074: * Returns an ConnectionManager instance using the the named provider.
075: * @param id to assign to this connection
076: * @return The requested ConnectionManager.
077: * @throws ConnectionException if provider is not found or failure to create.
078: */
079: public ConnectionManager getConnectionManager(String id)
080: throws ConnectionException {
081: String provider;
082: String[] pieces;
083:
084: provider = System.getProperty(
085: "com.sun.jbi.binding.proxy.connection", "JMS::");
086: pieces = provider.split(":");
087: if (pieces.length == 3) {
088: if (pieces[0].equals("IMQ")) {
089: //
090: // Hard code this for the moment.
091: //
092: return (new JMSConnectionManager(id,
093: new IMQConnectionHelper(pieces[1], pieces[2])));
094: } else if (pieces[0].equals("JBOSSMQ")) {
095: return (new JMSConnectionManager(id,
096: new JBossMQConnectionHelper(pieces[1],
097: pieces[2])));
098: }
099:
100: } else if (pieces.length == 1) {
101: if (pieces[0].equals("JMS")) {
102: return (new JMSConnectionManager(id,
103: new JMSConnectionHelper(mContext)));
104: }
105: }
106: throw new ConnectionException(Translator.translate(
107: LocalStringKeys.UNKNOWN_CONNECTION_PROVIDER, provider));
108:
109: }
110: }
|