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: * @(#)JMSConnectionHelper.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.jms;
030:
031: import com.sun.enterprise.ComponentInvocation;
032: import com.sun.enterprise.InvocationManager;
033: import com.sun.enterprise.Switch;
034:
035: import com.sun.jbi.binding.proxy.connection.ConnectionHelper;
036: import com.sun.jbi.binding.proxy.connection.ConnectionException;
037:
038: import javax.jms.ConnectionFactory;
039: import javax.jms.Queue;
040: import javax.jms.Topic;
041:
042: import javax.naming.InitialContext;
043:
044: /**
045: * Helper for ConnectionManagers
046: * @author Sun Microsystems, Inc
047: */
048: public class JMSConnectionHelper implements ConnectionHelper {
049: InitialContext mContext;
050: ConnectionFactory mFactory;
051:
052: public JMSConnectionHelper(InitialContext context) {
053: mContext = context;
054: }
055:
056: public void prepare() {
057: InvocationManager im;
058:
059: im = Switch.getSwitch().getInvocationManager();
060: if (im.getCurrentInvocation() == null) {
061: im.preInvoke(new ComponentInvocation(this , this ));
062: }
063: }
064:
065: /**
066: * Return a JMS ConnectionFactory.
067: * @return ConnectionFactory
068: */
069: public synchronized ConnectionFactory getConnectionFactory()
070: throws ConnectionException {
071: try {
072: prepare();
073: mFactory = (ConnectionFactory) mContext
074: .lookup("jms/SunJbiProxyBindingConnection");
075: } catch (javax.naming.NamingException nEx) {
076: throw new ConnectionException(nEx);
077: }
078:
079: return (mFactory);
080: }
081:
082: /**
083: * Return a JMS Queue.
084: * @return Queue.
085: */
086: public Queue getQueue(String name) throws ConnectionException {
087: try {
088: return ((Queue) mContext.lookup("jms/" + name));
089: } catch (javax.naming.NamingException nEx) {
090: throw new ConnectionException(nEx);
091: }
092: }
093:
094: /**
095: * Return a JMS Topic.
096: * @return Topic.
097: */
098: public Topic getTopic(String name) throws ConnectionException {
099: try {
100: return ((Topic) mContext.lookup("jms/" + name));
101: } catch (javax.naming.NamingException nEx) {
102: throw new ConnectionException(nEx);
103: }
104: }
105:
106: }
|