1 23 package org.objectweb.joram.client.connector; 24 25 import javax.resource.ResourceException ; 26 import javax.resource.spi.IllegalStateException ; 27 import javax.resource.spi.InvalidPropertyException ; 28 import javax.resource.spi.ResourceAdapter ; 29 30 import org.objectweb.util.monolog.api.BasicLevel; 31 32 36 public class ActivationSpecImpl 37 implements javax.resource.spi.ActivationSpec , 38 javax.resource.spi.ResourceAdapterAssociation , 39 java.io.Serializable 40 { 41 45 public static final String AUTO_ACKNOWLEDGE = "Auto-acknowledge"; 46 47 51 public static final String DUPS_OK_ACKNOWLEDGE = "Dups-ok-acknowledge"; 52 53 54 private String destinationType; 55 56 private String destination; 57 58 59 private String userName = "anonymous"; 60 61 private String password = "anonymous"; 62 63 64 private String messageSelector = null; 65 66 private String subscriptionDurability = null; 67 68 private String subscriptionName; 69 70 71 private String acknowledgeMode = AUTO_ACKNOWLEDGE; 72 73 74 private String maxNumberOfWorks = "0"; 75 76 81 private String maxMessages = "10"; 82 83 84 private transient ResourceAdapter ra = null; 85 86 87 90 public ActivationSpecImpl() 91 {} 92 93 94 101 public void validate() throws InvalidPropertyException 102 { 103 if (destinationType != null 104 && ! destinationType.equals("javax.jms.Queue") 105 && ! destinationType.equals("javax.jms.Topic")) 106 throw new InvalidPropertyException ("Invalid destination type: " 107 + destinationType); 108 109 if (destination == null) 110 throw new InvalidPropertyException ("Missing destination property."); 111 112 if (acknowledgeMode != null 113 && ! acknowledgeMode.equals(AUTO_ACKNOWLEDGE) 114 && ! acknowledgeMode.equals(DUPS_OK_ACKNOWLEDGE)) 115 throw new InvalidPropertyException ("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 ("Can't set a durable subscription " 123 + "on a JMS queue."); 124 125 if (subscriptionDurability.equals("Durable") 126 && subscriptionName == null) 127 throw new InvalidPropertyException ("Missing durable subscription name."); 128 } 129 } 130 131 132 133 public void setResourceAdapter(ResourceAdapter ra) throws ResourceException 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 ("Can not change resource adapter" 140 + " association."); 141 142 if (! (ra instanceof JoramAdapter)) 143 throw new ResourceException ("Provided resource adapter is not a JORAM " 144 + "resource adapter: " 145 + ra.getClass().getName()); 146 147 this.ra = (JoramAdapter) ra; 148 } 149 150 151 public ResourceAdapter 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 167 public void setDestinationType(String destinationType) 168 { 169 this.destinationType = destinationType; 170 } 171 172 173 public void setDestination(String destination) 174 { 175 this.destination = destination; 176 } 177 178 179 public void setUserName(String userName) 180 { 181 this.userName = userName; 182 } 183 184 185 public void setPassword(String password) 186 { 187 this.password = password; 188 } 189 190 191 public void setMessageSelector(String messageSelector) 192 { 193 this.messageSelector = messageSelector; 194 } 195 196 197 public void setSubscriptionDurability(String subscriptionDurability) 198 { 199 this.subscriptionDurability = subscriptionDurability; 200 } 201 202 203 public void setSubscriptionName(String subscriptionName) 204 { 205 this.subscriptionName = subscriptionName; 206 } 207 208 209 public void setAcknowledgeMode(String acknowledgeMode) 210 { 211 this.acknowledgeMode = acknowledgeMode; 212 } 213 214 215 public void setMaxNumberOfWorks(String maxNumberOfWorks) 216 { 217 this.maxNumberOfWorks = maxNumberOfWorks; 218 } 219 220 public void setMaxMessages(String maxMessages) { 221 this.maxMessages = maxMessages; 222 } 223 224 225 public String getDestinationType() 226 { 227 return destinationType; 228 } 229 230 231 public String getDestination() 232 { 233 return destination; 234 } 235 236 237 public String getUserName() 238 { 239 return userName; 240 } 241 242 243 public String getPassword() 244 { 245 return password; 246 } 247 248 249 public String getMessageSelector() 250 { 251 return messageSelector; 252 } 253 254 255 public String getSubscriptionDurability() 256 { 257 return subscriptionDurability; 258 } 259 260 261 public String getSubscriptionName() 262 { 263 return subscriptionName; 264 } 265 266 267 public String getAcknowledgeMode() 268 { 269 return acknowledgeMode; 270 } 271 272 273 public String getMaxNumberOfWorks() 274 { 275 return maxNumberOfWorks; 276 } 277 278 public String getMaxMessages() { 279 return maxMessages; 280 } 281 } 282 | Popular Tags |