KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > mdb > MDBConfig


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.ejb3.mdb;
8
9 import java.beans.BeanInfo JavaDoc;
10 import java.beans.Introspector JavaDoc;
11 import java.beans.IntrospectionException JavaDoc;
12 import java.beans.PropertyDescriptor JavaDoc;
13 import java.beans.PropertyEditor JavaDoc;
14 import java.beans.PropertyEditorManager JavaDoc;
15
16 /**
17  * Comment
18  *
19  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
20  * @version $Revision: 1.3.6.1 $
21  */

22 public class MDBConfig
23 {
24    protected int minPoolSize = 1;
25    protected int maxPoolSize = 15;
26    protected int keepAlive = 30000;
27    protected int maxMessages = 1;
28    protected String JavaDoc serverSessionPoolFactoryJNDI = "java:/StdJMSPool";
29    protected String JavaDoc providerAdapterJNDI = "java:/DefaultJMSProvider";
30    protected long reconnectInterval = 10000;
31
32    protected boolean useDLQ = true;
33    protected String JavaDoc dlq = "queue/DLQ";
34    protected int dlqMaxTimesRedelivered = 10;
35    protected int dlqTimeToLive = 0;
36    protected String JavaDoc dlqUser;
37    protected String JavaDoc dlqPassword;
38
39    protected String JavaDoc messageSelector;
40    protected String JavaDoc destinationType;
41    protected String JavaDoc user;
42    protected String JavaDoc password;
43    protected String JavaDoc destination;
44    protected String JavaDoc acknowledgeMode;
45    protected String JavaDoc clientID;
46    protected String JavaDoc durability;
47    protected String JavaDoc subscriptionName;
48
49    public String JavaDoc getDlqUser()
50    {
51       return dlqUser;
52    }
53
54    public void setDlqUser(String JavaDoc dlqUser)
55    {
56       this.dlqUser = dlqUser;
57    }
58
59    public String JavaDoc getDlqPassword()
60    {
61       return dlqPassword;
62    }
63
64    public void setDlqPassword(String JavaDoc dlqPassword)
65    {
66       this.dlqPassword = dlqPassword;
67    }
68
69    /**
70     * Use a Dead-letter queue for undeliverable messages?
71     * @return
72     */

73    public boolean isUseDLQ()
74    {
75       return useDLQ;
76    }
77
78    public void setUseDLQ(boolean useDLQ)
79    {
80       this.useDLQ = useDLQ;
81    }
82
83    /**
84     * JNDI name of the DLQ
85     *
86     * @return
87     */

88    public String JavaDoc getDlq()
89    {
90       return dlq;
91    }
92
93    public void setDlq(String JavaDoc dlq)
94    {
95       this.dlq = dlq;
96    }
97
98    /**
99     * How many times should a message be redelivered before it is put into the DLQ
100     *
101     * @return
102     */

103    public int getDlqMaxTimesRedelivered()
104    {
105       return dlqMaxTimesRedelivered;
106    }
107
108    public void setDlqMaxTimesRedelivered(int dlqMaxTimesRedelivered)
109    {
110       this.dlqMaxTimesRedelivered = dlqMaxTimesRedelivered;
111    }
112
113    public int getDlqTimeToLive()
114    {
115       return dlqTimeToLive;
116    }
117
118    public void setDlqTimeToLive(int dlqTimeToLive)
119    {
120       this.dlqTimeToLive = dlqTimeToLive;
121    }
122
123    public String JavaDoc getProviderAdapterJNDI()
124    {
125       return providerAdapterJNDI;
126    }
127
128    public void setProviderAdapterJNDI(String JavaDoc providerAdapterJNDI)
129    {
130       this.providerAdapterJNDI = providerAdapterJNDI;
131    }
132
133    public String JavaDoc getAcknowledgeMode()
134    {
135       return acknowledgeMode;
136    }
137
138    public void setAcknowledgeMode(String JavaDoc acknowledgeMode)
139    {
140       this.acknowledgeMode = acknowledgeMode;
141    }
142
143    public String JavaDoc getClientID()
144    {
145       return clientID;
146    }
147
148    public void setClientID(String JavaDoc clientID)
149    {
150       this.clientID = clientID;
151    }
152
153    /**
154     * Set to "Durable" or "NonDurable"
155     *
156     * Specify wether or not the topic should be durable.
157     *
158     * @return
159     */

160    public String JavaDoc getDurability()
161    {
162       return durability;
163    }
164
165    public void setDurability(String JavaDoc durability)
166    {
167       this.durability = durability;
168    }
169
170    public String JavaDoc getSubscriptionName()
171    {
172       return subscriptionName;
173    }
174
175    public void setSubscriptionName(String JavaDoc subscriptionName)
176    {
177       this.subscriptionName = subscriptionName;
178    }
179
180    public String JavaDoc getDestination()
181    {
182       return destination;
183    }
184
185    public void setDestination(String JavaDoc destination)
186    {
187       this.destination = destination;
188    }
189
190    public String JavaDoc getUser()
191    {
192       return user;
193    }
194
195    public void setUser(String JavaDoc user)
196    {
197       this.user = user;
198    }
199
200    public String JavaDoc getPassword()
201    {
202       return password;
203    }
204
205    public void setPassword(String JavaDoc password)
206    {
207       this.password = password;
208    }
209
210    public String JavaDoc getMessageSelector()
211    {
212       return messageSelector;
213    }
214
215    public void setMessageSelector(String JavaDoc messageSelector)
216    {
217       this.messageSelector = messageSelector;
218    }
219
220    public String JavaDoc getDestinationType()
221    {
222       return destinationType;
223    }
224
225    public void setDestinationType(String JavaDoc destinationType)
226    {
227       this.destinationType = destinationType;
228    }
229
230    public int getMinPoolSize()
231    {
232       return minPoolSize;
233    }
234
235    public void setMinPoolSize(int minPoolSize)
236    {
237       this.minPoolSize = minPoolSize;
238    }
239
240    public int getMaxPoolSize()
241    {
242       return maxPoolSize;
243    }
244
245    public void setMaxPoolSize(int maxPoolSize)
246    {
247       this.maxPoolSize = maxPoolSize;
248    }
249
250    public int getKeepAlive()
251    {
252       return keepAlive;
253    }
254
255    public void setKeepAlive(int keepAlive)
256    {
257       this.keepAlive = keepAlive;
258    }
259
260    public int getMaxMessages()
261    {
262       return maxMessages;
263    }
264
265    public void setMaxMessages(int maxMessages)
266    {
267       this.maxMessages = maxMessages;
268    }
269
270    public String JavaDoc getServerSessionPoolFactoryJNDI()
271    {
272       return serverSessionPoolFactoryJNDI;
273    }
274
275    public void setServerSessionPoolFactoryJNDI(String JavaDoc serverSessionPoolFactoryJNDI)
276    {
277       this.serverSessionPoolFactoryJNDI = serverSessionPoolFactoryJNDI;
278    }
279
280    public long getReconnectInterval()
281    {
282       return reconnectInterval;
283    }
284
285    public void setReconnectInterval(long reconnectInterval)
286    {
287       this.reconnectInterval = reconnectInterval;
288    }
289
290    public static MDBConfig createMDBConfig(ActivationSpec spec)
291    {
292       MDBConfig instance = new MDBConfig();
293       BeanInfo JavaDoc beanInfo = null;
294       try
295       {
296          beanInfo = Introspector.getBeanInfo(MDBConfig.class);
297       }
298       catch (IntrospectionException JavaDoc e)
299       {
300          throw new RuntimeException JavaDoc(e.getMessage(), e);
301       }
302       PropertyDescriptor JavaDoc[] descriptors = beanInfo.getPropertyDescriptors();
303       if (descriptors == null)
304       {
305          descriptors = new PropertyDescriptor JavaDoc[0];
306       }
307
308       for (String JavaDoc name : spec.keySet())
309       {
310          setAttribute(instance, descriptors, name, spec.get(name));
311
312       }
313       return instance;
314    }
315
316    private static void setAttribute(Object JavaDoc instance, PropertyDescriptor JavaDoc[] descriptors, String JavaDoc attributeName, String JavaDoc attributeText)
317    {
318       for (int i = 0; i < descriptors.length; i++)
319       {
320          if (attributeName.equalsIgnoreCase(descriptors[i].getName()))
321          {
322             Class JavaDoc typeClass = descriptors[i].getPropertyType();
323
324             Object JavaDoc value;
325             PropertyEditor JavaDoc editor = PropertyEditorManager.findEditor(typeClass);
326             if (editor == null)
327             {
328                throw new RuntimeException JavaDoc
329                        ("No property editor for attribute: " + attributeName +
330                        "; type=" + typeClass);
331             }
332
333             editor.setAsText(attributeText);
334             value = editor.getValue();
335             try
336             {
337                descriptors[i].getWriteMethod().invoke(instance, new Object JavaDoc[]{value});
338             }
339             catch (Exception JavaDoc e)
340             {
341                throw new RuntimeException JavaDoc("Error setting attribute '" +
342                        attributeName + "' in MDBConfig", e);
343             }
344             break;
345          }
346       }//for descriptors
347
}
348
349 }
350
Popular Tags