[Ejtools-cvs] CVS: applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/jms
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-04-22 17:59:08
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/jms In directory usw-pr-cvs1:/tmp/cvs-serv1451/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/jms Added Files: TopicProxy.java Log Message: Initial Import --- NEW FILE: TopicProxy.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.jndibrowser.model.jms; // Standard Imports import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicPublisher; import javax.jms.TopicSession; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; // Other Imports import net.sourceforge.ejtools.jndibrowser.model.JNDIEntry; import org.apache.log4j.Category; /** *Description of the Class * * @author letiembl * @created 13 décembre 2001 * @todo Javadoc to complete * @todo Add log4j logs */ public class TopicProxy extends JNDIEntry { /** Description of the Field */ private Topic topic = null; /** *Constructor for the JMSTopic object * * @param o Description of Parameter * @exception Exception Description of Exception */ public TopicProxy(Object o) throws Exception { this.topic = (Topic) PortableRemoteObject.narrow(o, Topic.class); // this.topic = (Topic) o; } /** *Description of the Method * * @param text Description of Parameter */ public void createTextMessage(String text) { Context jndiContext = null; TopicConnectionFactory topicConnectionFactory = null; TopicConnection topicConnection = null; TopicSession topicSession = null; TopicPublisher topicPublisher = null; TextMessage message = null; // TO MODIFY try { jndiContext = new InitialContext(); topicConnectionFactory = (TopicConnectionFactory) jndiContext.lookup("ConnectionFactory"); } catch (NamingException e) { System.out.println("JNDI lookup failed: " + e.toString()); } // TO MODIFY try { topicConnection = topicConnectionFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topicPublisher = topicSession.createPublisher(topic); message = topicSession.createTextMessage(); message.setText(text); topicPublisher.publish(message); topicSession.close(); } catch (JMSException e) { System.out.println("Exception occurred: " + e.toString()); } finally { if (topicConnection != null) { try { topicConnection.close(); } catch (JMSException e) { } } } } } |