KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jndi > browser > model > jms > ConnectionFactoryProxy


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.jndi.browser.model.jms;
8
9 import java.beans.beancontext.BeanContextServiceRevokedEvent JavaDoc;
10 import java.beans.beancontext.BeanContextServices JavaDoc;
11
12 import javax.jms.QueueConnectionFactory JavaDoc;
13 import javax.jms.TopicConnectionFactory JavaDoc;
14 import javax.naming.Context JavaDoc;
15 import javax.rmi.PortableRemoteObject JavaDoc;
16
17 import org.apache.log4j.Logger;
18 import org.ejtools.jndi.browser.model.JNDIEntry;
19 import org.ejtools.jndi.browser.model.service.JMSConnectionService;
20
21 /**
22  * Description of the Class
23  *
24  * @author letiemble
25  * @created 13 décembre 2001
26  * @version $Revision: 1.2 $
27  * @todo Javadoc to complete
28  * @todo Add log4j logs
29  * @todo Review the exception raised
30  * @javabean:class displayName="Connection Factory"
31  * shortDescription="Connection Factory"
32  * @javabean:icons color16="/toolbarButtonGraphics/development/JMSResource16.gif"
33  * @javabean:property name="name"
34  * class="java.lang.String"
35  * displayName="Name"
36  * shortDescription="Name of the Connection Factory"
37  * @javabean:property name="className"
38  * class="java.lang.String"
39  * displayName="Class"
40  * shortDescription="Class of the Connection Factory"
41  * @javabean:property name="queueConnectionFactory"
42  * class="boolean"
43  * displayName="Can Create QueueConnection"
44  * shortDescription="Ability to create QueueConnection objects"
45  * @javabean:property name="topicConnectionFactory"
46  * class="boolean"
47  * displayName="Can Create TopicConnection"
48  * shortDescription="Ability to create TopicConnection objects"
49  */

50 public class ConnectionFactoryProxy extends JNDIEntry
51 {
52    /** Description of the Field */
53    protected boolean isDefault = false;
54    /** Description of the Field */
55    protected boolean isQueueConnectionFactory = false;
56    /** Description of the Field */
57    protected boolean isTopicConnectionFactory = false;
58    /** Description of the Field */
59    protected QueueConnectionFactory JavaDoc queueConnectionFactory = null;
60    /** Description of the Field */
61    protected TopicConnectionFactory JavaDoc topicConnectionFactory = null;
62    /** Description of the Field */
63    private static Logger logger = Logger.getLogger(ConnectionFactoryProxy.class);
64
65
66    /**
67     * Constructor for the JMSQueue object
68     *
69     * @param context Description of the Parameter
70     * @param jndiName Description of the Parameter
71     * @exception Exception Description of Exception
72     */

73    public ConnectionFactoryProxy(Context JavaDoc context, String JavaDoc jndiName)
74       throws Exception JavaDoc
75    {
76       // Try to narrow to an EJBHome class
77
Object JavaDoc o = context.lookup(jndiName);
78
79       setName(jndiName);
80       setClassName(o.getClass().getName());
81
82       if (o instanceof QueueConnectionFactory JavaDoc)
83       {
84          this.queueConnectionFactory = (QueueConnectionFactory JavaDoc) PortableRemoteObject.narrow(o, QueueConnectionFactory JavaDoc.class);
85          this.isQueueConnectionFactory = true;
86       }
87       if (o instanceof TopicConnectionFactory JavaDoc)
88       {
89          this.topicConnectionFactory = (TopicConnectionFactory JavaDoc) PortableRemoteObject.narrow(o, TopicConnectionFactory JavaDoc.class);
90          this.isTopicConnectionFactory = true;
91       }
92       if (!(this.isQueueConnectionFactory || this.isTopicConnectionFactory))
93       {
94          throw new Exception JavaDoc("Not Available");
95       }
96    }
97
98
99    /**
100     * Getter for the queueConnectionFactory attribute
101     *
102     * @return The value of queueConnectionFactory attribute
103     */

104    public QueueConnectionFactory JavaDoc getQueueConnectionFactory()
105    {
106       return this.queueConnectionFactory;
107    }
108
109
110    /**
111     * Getter for the topicConnectionFactory attribute
112     *
113     * @return The value of topicConnectionFactory attribute
114     */

115    public TopicConnectionFactory JavaDoc getTopicConnectionFactory()
116    {
117       return this.topicConnectionFactory;
118    }
119
120
121    /**
122     * Gets the count attribute of the JMSQueue object
123     *
124     * @return The count value
125     */

126    public boolean isQueueConnectionFactory()
127    {
128       return this.isQueueConnectionFactory;
129    }
130
131
132    /**
133     * Getter for the topicConnectionFactory attribute
134     *
135     * @return The value
136     */

137    public boolean isTopicConnectionFactory()
138    {
139       return this.isTopicConnectionFactory;
140    }
141
142
143    /**
144     * Description of the Method
145     *
146     * @param bcsre Description of Parameter
147     */

148    public void serviceRevoked(BeanContextServiceRevokedEvent JavaDoc bcsre)
149    {
150       try
151       {
152          BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
153          context.releaseService(this, this, JMSConnectionService.class);
154       }
155       catch (Exception JavaDoc e)
156       {
157          logger.error("Error during release of service ConnectionService (" + e.getMessage() + ")");
158       }
159    }
160
161
162    /**
163     * Description of the Method
164     *
165     * @return Description of the Returned Value
166     */

167    public String JavaDoc toString()
168    {
169       return name == null ? "Undefined" : name;
170    }
171
172
173    /** Description of the Method */
174    protected void initializeBeanContextResources()
175    {
176       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
177       if (context.hasService(JMSConnectionService.class))
178       {
179          try
180          {
181             JMSConnectionService service = (JMSConnectionService) context.getService(this, this, JMSConnectionService.class, this, this);
182          }
183          catch (Exception JavaDoc e)
184          {
185             logger.error("Error during utilisation of service ConnectionService (" + e.getMessage() + ")");
186          }
187       }
188    }
189 }
190
191
Popular Tags