KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > ActivationSpecImpl


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - Bull SA
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Frederic Maistre (Bull SA)
21  * Contributor(s): Nicolas Tachker (Bull SA)
22  */

23 package org.objectweb.joram.client.connector;
24
25 import javax.resource.ResourceException JavaDoc;
26 import javax.resource.spi.IllegalStateException JavaDoc;
27 import javax.resource.spi.InvalidPropertyException JavaDoc;
28 import javax.resource.spi.ResourceAdapter JavaDoc;
29
30 import org.objectweb.util.monolog.api.BasicLevel;
31
32 /**
33  * An <code>ActivationSpecImpl</code> instance holds configuration information
34  * related to an endpoint deployment.
35  */

36 public class ActivationSpecImpl
37        implements javax.resource.spi.ActivationSpec JavaDoc,
38                   javax.resource.spi.ResourceAdapterAssociation JavaDoc,
39                   java.io.Serializable JavaDoc
40 {
41   /**
42    * Value for the property <code>acknowledgeMode</code>
43    * defined in the MDB deployment descriptor.
44    */

45   public static final String JavaDoc AUTO_ACKNOWLEDGE = "Auto-acknowledge";
46   
47   /**
48    * Value for the property <code>acknowledgeMode</code>
49    * defined in the MDB deployment descriptor.
50    */

51   public static final String JavaDoc DUPS_OK_ACKNOWLEDGE = "Dups-ok-acknowledge";
52   
53   /** The type of the destination to get messages from. */
54   private String JavaDoc destinationType;
55   /** The name of the destination to get messages from. */
56   private String JavaDoc destination;
57
58   /** User identification. */
59   private String JavaDoc userName = "anonymous";
60   /** User password. */
61   private String JavaDoc password = "anonymous";
62
63   /** Message selector. */
64   private String JavaDoc messageSelector = null;
65   /** Subscription durability. */
66   private String JavaDoc subscriptionDurability = null;
67   /** Durable subscription name, if any. */
68   private String JavaDoc subscriptionName;
69
70   /** Acknowledgement mode. */
71   private String JavaDoc acknowledgeMode = AUTO_ACKNOWLEDGE;
72
73   /** Maximum number of work instances to be submitted (0 for infinite). */
74   private String JavaDoc maxNumberOfWorks = "0";
75   
76   /**
77    * The maximum number of messages that can be assigned
78    * to a server session at one time
79    * Default is 10.
80    */

81   private String JavaDoc maxMessages = "10";
82
83   /** Resource adapter central authority. */
84   private transient ResourceAdapter JavaDoc ra = null;
85
86
87   /**
88    * Constructs an <code>ActivationSpecImpl</code> instance.
89    */

90   public ActivationSpecImpl()
91   {}
92
93  
94   /**
95    * Checks if the configuration information is valid.
96    *
97    * @exception InvalidPropertyException If a parameter is missing, incorrect,
98    * or not consistent with other
99    * parameters.
100    */

101   public void validate() throws InvalidPropertyException JavaDoc
102   {
103     if (destinationType != null
104         && ! destinationType.equals("javax.jms.Queue")
105         && ! destinationType.equals("javax.jms.Topic"))
106       throw new InvalidPropertyException JavaDoc("Invalid destination type: "
107                                          + destinationType);
108
109     if (destination == null)
110       throw new InvalidPropertyException JavaDoc("Missing destination property.");
111
112     if (acknowledgeMode != null
113         && ! acknowledgeMode.equals(AUTO_ACKNOWLEDGE)
114         && ! acknowledgeMode.equals(DUPS_OK_ACKNOWLEDGE))
115       throw new InvalidPropertyException JavaDoc("Invalid acknowledge mode: "
116                                          + acknowledgeMode);
117
118     if (subscriptionDurability != null) {
119
120       if (subscriptionDurability.equals("Durable")
121           && destinationType.equals("javax.jms.Queue"))
122         throw new InvalidPropertyException JavaDoc("Can't set a durable subscription "
123                                            + "on a JMS queue.");
124
125       if (subscriptionDurability.equals("Durable")
126           && subscriptionName == null)
127         throw new InvalidPropertyException JavaDoc("Missing durable subscription name.");
128     }
129   }
130
131
132   /** Sets the resource adapter central authority. */
133   public void setResourceAdapter(ResourceAdapter JavaDoc ra) throws ResourceException JavaDoc
134   {
135     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
136       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " setResourceAdapter(" + ra + ")");
137
138     if (this.ra != null)
139       throw new IllegalStateException JavaDoc("Can not change resource adapter"
140                                       + " association.");
141
142     if (! (ra instanceof JoramAdapter))
143       throw new ResourceException JavaDoc("Provided resource adapter is not a JORAM "
144                                   + "resource adapter: "
145                                   + ra.getClass().getName());
146
147     this.ra = (JoramAdapter) ra;
148   }
149
150   /** Returns the resource adapter central authority instance. */
151   public ResourceAdapter JavaDoc getResourceAdapter()
152   {
153     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
154       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getResourceAdapter = " + ra);
155
156     return ra;
157   }
158
159
160   // ------------------------------------------
161
// --- JavaBean setter and getter methods ---
162
// ------------------------------------------
163
/**
164    * Sets the destination type (either "javax.jms.Queue" or
165    * "javax.jms.Topic").
166    */

167   public void setDestinationType(String JavaDoc destinationType)
168   {
169     this.destinationType = destinationType;
170   }
171
172   /** Sets the destination name. */
173   public void setDestination(String JavaDoc destination)
174   {
175     this.destination = destination;
176   }
177
178   /** Sets the user identification. */
179   public void setUserName(String JavaDoc userName)
180   {
181     this.userName = userName;
182   }
183
184   /** Sets the user password. */
185   public void setPassword(String JavaDoc password)
186   {
187     this.password = password;
188   }
189
190   /** Sets the message selector. */
191   public void setMessageSelector(String JavaDoc messageSelector)
192   {
193     this.messageSelector = messageSelector;
194   }
195
196   /** Sets the durability of the subscription. */
197   public void setSubscriptionDurability(String JavaDoc subscriptionDurability)
198   {
199     this.subscriptionDurability = subscriptionDurability;
200   }
201
202   /** Sets the name of the durable subscription. */
203   public void setSubscriptionName(String JavaDoc subscriptionName)
204   {
205     this.subscriptionName = subscriptionName;
206   }
207
208   /** Sets the acknowledgement mode. */
209   public void setAcknowledgeMode(String JavaDoc acknowledgeMode)
210   {
211     this.acknowledgeMode = acknowledgeMode;
212   }
213
214   /** Sets the maximum number of work instances to be submitted. */
215   public void setMaxNumberOfWorks(String JavaDoc maxNumberOfWorks)
216   {
217     this.maxNumberOfWorks = maxNumberOfWorks;
218   }
219   
220   public void setMaxMessages(String JavaDoc maxMessages) {
221     this.maxMessages = maxMessages;
222   }
223
224   /** Returns the destination type. */
225   public String JavaDoc getDestinationType()
226   {
227     return destinationType;
228   }
229
230   /** Returns the destination name. */
231   public String JavaDoc getDestination()
232   {
233     return destination;
234   }
235
236   /** Returns the user identification. */
237   public String JavaDoc getUserName()
238   {
239     return userName;
240   }
241
242   /** Returns the user password. */
243   public String JavaDoc getPassword()
244   {
245     return password;
246   }
247
248   /** Returns the message selector. */
249   public String JavaDoc getMessageSelector()
250   {
251     return messageSelector;
252   }
253
254   /** Returns the subscription durabbility. */
255   public String JavaDoc getSubscriptionDurability()
256   {
257     return subscriptionDurability;
258   }
259
260   /** Returns the name of the durable subscription. */
261   public String JavaDoc getSubscriptionName()
262   {
263     return subscriptionName;
264   }
265
266   /** Returns the acknowledgement mode. */
267   public String JavaDoc getAcknowledgeMode()
268   {
269     return acknowledgeMode;
270   }
271
272   /** Returns the maximum number of work instances to be submitted. */
273   public String JavaDoc getMaxNumberOfWorks()
274   {
275     return maxNumberOfWorks;
276   }
277   
278   public String JavaDoc getMaxMessages() {
279     return maxMessages;
280   }
281 }
282
Popular Tags