Thread: [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:38:45
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/jms In directory usw-pr-cvs1:/tmp/cvs-serv28897/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/jms Added Files: ConnectionFactoryProxy.java ConnectionService.java ConnectionServiceProvider.java Log Message: Initial Import --- NEW FILE: ConnectionFactoryProxy.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 java.beans.beancontext.BeanContextServiceRevokedEvent; import java.beans.beancontext.BeanContextServices; import javax.jms.JMSException; import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnectionFactory; 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 * @todo Review the exception raised */ public class ConnectionFactoryProxy extends JNDIEntry { /** Description of the Field */ protected QueueConnectionFactory queueConnectionFactory = null; /** Description of the Field */ protected TopicConnectionFactory topicConnectionFactory = null; /** Description of the Field */ protected boolean isQueueConnectionFactory = false; /** Description of the Field */ protected boolean isTopicConnectionFactory = false; /** Description of the Field */ protected boolean isDefault = false; /** * Constructor for the JMSQueue object * * @param o Description of Parameter * @exception Exception Description of Exception */ public ConnectionFactoryProxy(Object o) throws Exception { if (o instanceof QueueConnectionFactory) { this.queueConnectionFactory = (QueueConnectionFactory) PortableRemoteObject.narrow(o, QueueConnectionFactory.class); this.isQueueConnectionFactory = true; } if (o instanceof TopicConnectionFactory) { this.topicConnectionFactory = (TopicConnectionFactory) PortableRemoteObject.narrow(o, TopicConnectionFactory.class); this.isTopicConnectionFactory = true; } if (!(this.isQueueConnectionFactory || this.isTopicConnectionFactory)) { throw new Exception("Not Available"); } } /** * Getter for the queueConnectionFactory attribute * * @return The value of queueConnectionFactory attribute */ public QueueConnectionFactory getQueueConnectionFactory() { return this.queueConnectionFactory; } /** * Getter for the topicConnectionFactory attribute * * @return The value of topicConnectionFactory attribute */ public TopicConnectionFactory getTopicConnectionFactory() { return this.topicConnectionFactory; } /** * Gets the count attribute of the JMSQueue object * * @return The count value */ public boolean isQueueConnectionFactory() { return this.isQueueConnectionFactory; } /** * Getter for the topicConnectionFactory attribute * * @return The value */ public boolean isTopicConnectionFactory() { return this.isTopicConnectionFactory; } /** * Description of the Method * * @return Description of the Returned Value */ public String toString() { return name == null ? "Undefined" : name; } /** * Description of the Method * * @param bcsre Description of Parameter */ public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) { try { BeanContextServices context = (BeanContextServices) getBeanContext(); context.releaseService(this, this, ConnectionService.class); } catch (Exception e) { System.out.println("Error during release of service ConnectionService (" + e.getMessage() + ")"); e.printStackTrace(); } } /** Description of the Method */ protected void initializeBeanContextResources() { BeanContextServices context = (BeanContextServices) getBeanContext(); if (context.hasService(ConnectionService.class)) { try { ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this); } catch (Exception e) { System.out.println("Error during utilisation of service ConnectionService (" + e.getMessage() + ")"); e.printStackTrace(); } } } } --- NEW FILE: ConnectionService.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.QueueConnectionFactory; import javax.jms.TopicConnectionFactory; /** * Description of the Interface * * @author letiembl * @created 3 avril 2002 * @todo Javadoc to complete */ public interface ConnectionService { /** Description of the Field */ public final static String QUEUE_CONNECTION_FACTORY = "QUEUE"; /** Description of the Field */ public final static String TOPIC_CONNECTION_FACTORY = "TOPIC"; /** * Getter for the defaultQueueConnectionFactory attribute * * @return The value of defaultQueueConnectionFactory attribute */ public QueueConnectionFactory getDefaultQueueConnectionFactory(); /** * Getter for the defaultConnectionFactory attribute * * @return The value of defaultConnectionFactory attribute */ public TopicConnectionFactory getDefaultTopicConnectionFactory(); } --- NEW FILE: ConnectionServiceProvider.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 java.beans.beancontext.BeanContextServiceProvider; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import java.util.Iterator; import java.util.ResourceBundle; import java.util.Vector; import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnectionFactory; import javax.swing.JOptionPane; import javax.swing.JPanel; // Other Imports import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 13 décembre 2001 * @todo Javadoc to complete * @todo Add log4j logs * @todo I18N to check * @todo int argument for selectFactory */ public class ConnectionServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider, ConnectionService { /** Description of the Field */ protected int defaultQueueConnectionFactory = 0; /** Description of the Field */ protected int defaultTopicConnectionFactory = 0; /** Description of the Field */ protected JPanel panel = null; /** Description of the Field */ protected Vector queueConnectionFactories = new Vector(); /** Description of the Field */ protected Vector topicConnectionFactories = new Vector(); /** Description of the Field */ private final static ResourceBundle res = ResourceBundle.getBundle("ApplicationResources"); /** * Getter for the currentServiceSelectors attribute * * @param bcs Description of Parameter * @param serviceClass Description of Parameter * @return The value */ public Iterator getCurrentServiceSelectors(BeanContextServices bcs, java.lang.Class serviceClass) { return (new Vector()).iterator(); } /** * Getter for the defaultQueueConnectionFactory attribute * * @return The value of defaultQueueConnectionFactory attribute */ public QueueConnectionFactory getDefaultQueueConnectionFactory() { if (queueConnectionFactories.size() == 0) { JOptionPane.showMessageDialog(null, res.getString("text.information.noDefaultFactory.queue"), res.getString("title.information.defaultFactory.queue"), JOptionPane.INFORMATION_MESSAGE); } else { ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) queueConnectionFactories.elementAt(defaultQueueConnectionFactory); return proxy.getQueueConnectionFactory(); } return null; } /** * Getter for the defaultTopicConnectionFactory attribute * * @return The value of defaultTopicConnectionFactory attribute */ public TopicConnectionFactory getDefaultTopicConnectionFactory() { if (topicConnectionFactories.size() == 0) { JOptionPane.showMessageDialog(null, res.getString("text.information.noDefaultFactory.topic"), res.getString("title.information.defaultFactory.topic"), JOptionPane.INFORMATION_MESSAGE); } else { ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) topicConnectionFactories.elementAt(defaultTopicConnectionFactory); return proxy.getTopicConnectionFactory(); } return null; } /** * Getter for the service attribute * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param serviceClass Description of Parameter * @param serviceSelector Description of Parameter * @return The value */ public Object getService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector) { if (requestor instanceof ConnectionFactoryProxy) { ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) requestor; if (proxy.isQueueConnectionFactory()) { queueConnectionFactories.add(proxy); } if (proxy.isTopicConnectionFactory()) { topicConnectionFactories.add(proxy); } } return this; } /** * Description of the Method * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param service Description of Parameter */ public void releaseService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Object service) { if (requestor instanceof ConnectionFactoryProxy) { ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) requestor; if (proxy.isQueueConnectionFactory()) { queueConnectionFactories.remove(proxy); if ((this.defaultQueueConnectionFactory >= queueConnectionFactories.size()) && (this.defaultQueueConnectionFactory > 0)) { this.defaultQueueConnectionFactory = queueConnectionFactories.size() - 1; } } if (proxy.isTopicConnectionFactory()) { topicConnectionFactories.remove(proxy); if ((this.defaultTopicConnectionFactory >= topicConnectionFactories.size()) && (this.defaultTopicConnectionFactory > 0)) { this.defaultTopicConnectionFactory = topicConnectionFactories.size() - 1; } } } } /** * Description of the Method * * @param type Description of the Parameter */ public void selectFactory(String type) { if (ConnectionService.QUEUE_CONNECTION_FACTORY.equals(type)) { selectQueueConnectionFactory(); } if (ConnectionService.TOPIC_CONNECTION_FACTORY.equals(type)) { selectTopicConnectionFactory(); } } /** Description of the Method */ public void selectQueueConnectionFactory() { if (queueConnectionFactories.size() > 0) { Object selectedValue = JOptionPane.showInputDialog(null, res.getString("text.question.defaultFactory.queue"), res.getString("title.question.defaultFactory.queue"), JOptionPane.QUESTION_MESSAGE, null, queueConnectionFactories.toArray(), queueConnectionFactories.elementAt(defaultQueueConnectionFactory)); if (selectedValue != null) { defaultQueueConnectionFactory = queueConnectionFactories.indexOf(selectedValue); } else { return; } } else { JOptionPane.showMessageDialog(null, res.getString("text.information.noDefaultFactory.queue"), res.getString("title.information.defaultFactory.queue"), JOptionPane.INFORMATION_MESSAGE); } } /** Description of the Method */ public void selectTopicConnectionFactory() { if (topicConnectionFactories.size() > 0) { Object selectedValue = JOptionPane.showInputDialog(null, res.getString("text.question.defaultFactory.topic"), res.getString("title.question.defaultFactory.topic"), JOptionPane.QUESTION_MESSAGE, null, topicConnectionFactories.toArray(), topicConnectionFactories.elementAt(defaultTopicConnectionFactory)); if (selectedValue != null) { defaultTopicConnectionFactory = topicConnectionFactories.indexOf(selectedValue); } else { return; } } else { JOptionPane.showMessageDialog(null, res.getString("text.information.noDefaultFactory.topic"), res.getString("title.information.defaultFactory.topic"), JOptionPane.INFORMATION_MESSAGE); } } /** * Getter for the panel attribute * * @return The value of panel attribute */ protected JPanel getPanel() { if (this.panel == null) { } return this.panel; } /** Description of the Method */ protected void initializeBeanContextResources() { super.initializeBeanContextResources(); ((BeanContextServices) getBeanContext()).addService(ConnectionService.class, this); } /** Description of the Method */ protected void releaseBeanContextResources() { ((BeanContextServices) getBeanContext()).revokeService(ConnectionService.class, this, false); super.releaseBeanContextResources(); } } |