1 22 package org.jboss.metadata; 23 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 27 import javax.jms.Message ; 28 import javax.jms.Session ; 29 30 import org.w3c.dom.Element ; 31 32 import org.jboss.invocation.InvocationType; 33 import org.jboss.deployment.DeploymentException; 34 35 46 public class MessageDrivenMetaData 47 extends BeanMetaData 48 { 49 51 public static final int AUTO_ACKNOWLEDGE_MODE = Session.AUTO_ACKNOWLEDGE; 52 public static final int DUPS_OK_ACKNOWLEDGE_MODE = Session.DUPS_OK_ACKNOWLEDGE; 53 public static final int CLIENT_ACKNOWLEDGE_MODE = Session.CLIENT_ACKNOWLEDGE; 54 public static final byte DURABLE_SUBSCRIPTION = 0; 55 public static final byte NON_DURABLE_SUBSCRIPTION = 1; 56 public static final byte TX_UNSET = 9; 57 public static final String DEFAULT_MESSAGE_DRIVEN_BEAN_INVOKER_PROXY_BINDING = "message-driven-bean"; 58 59 public static final String DEFAULT_MESSAGING_TYPE = "javax.jms.MessageListener"; 60 61 63 private int acknowledgeMode = AUTO_ACKNOWLEDGE_MODE; 64 private byte subscriptionDurability = NON_DURABLE_SUBSCRIPTION; 65 private byte methodTransactionType = TX_UNSET; 66 private String messagingType = DEFAULT_MESSAGING_TYPE; 67 private String destinationType; 68 private String destinationLink; 69 private String messageSelector; 70 private String destinationJndiName; 71 private String user; 72 private String passwd; 73 private String clientId; 74 private String subscriptionId; 75 76 private HashMap activationConfigProperties = new HashMap (); 77 78 private String resourceAdapterName; 79 80 82 84 public MessageDrivenMetaData(ApplicationMetaData app) 85 { 86 super(app, BeanMetaData.MDB_TYPE); 87 } 88 89 91 98 public int getAcknowledgeMode() 99 { 100 110 113 119 if (getMethodTransactionType() == TX_REQUIRED) 120 { 121 return CLIENT_ACKNOWLEDGE_MODE; 122 } 123 else 124 { 125 return acknowledgeMode; 126 } 127 } 128 129 public void setAcknowledgeMode(String ack) 130 { 131 if( ack == null || ack.equalsIgnoreCase("Auto-acknowledge") || 132 ack.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) 133 { 134 acknowledgeMode = AUTO_ACKNOWLEDGE_MODE; 135 } 136 else if (ack.equalsIgnoreCase("Dups-ok-acknowledge") || 137 ack.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) 138 { 139 acknowledgeMode = DUPS_OK_ACKNOWLEDGE_MODE; 140 } 141 else 142 { 143 throw new IllegalStateException ("invalid acknowledge-mode: " + ack); 144 } 145 } 146 147 public String getMessagingType() 148 { 149 return messagingType; 150 } 151 152 public void setMessagingType(String messagingType) 153 { 154 this.messagingType = messagingType; 155 } 156 157 public boolean isJMSMessagingType() 158 { 159 return DEFAULT_MESSAGING_TYPE.equals(messagingType); 160 } 161 162 public String getDestinationType() 163 { 164 return destinationType; 165 } 166 167 public void setDestinationType(String destinationType) 168 { 169 this.destinationType = destinationType; 170 } 171 172 public String getDestinationLink() 173 { 174 return destinationLink; 175 } 176 177 public void setDestinationLink(String destinationLink) 178 { 179 this.destinationLink = destinationLink; 180 } 181 182 public String getMessageSelector() 183 { 184 return messageSelector; 185 } 186 187 public void setMessageSelector(String selector) 188 { 189 this.messageSelector = selector; 190 if( messageSelector != null ) 191 { 192 int i = -1; 194 while( ( i = messageSelector.indexOf( "\r\n" ) ) >= 0 ) 196 { 197 messageSelector = ( i == 0 ? "" : messageSelector.substring( 0, i ) ) + 199 " " + 200 ( i >= messageSelector.length() - 2 ? "" : messageSelector.substring( i + 2 ) ); 201 } 202 i = -1; 203 while( ( i = messageSelector.indexOf( "\r" ) ) >= 0 ) 204 { 205 messageSelector = ( i == 0 ? "" : messageSelector.substring( 0, i ) ) + 207 " " + 208 ( i >= messageSelector.length() - 1 ? "" : messageSelector.substring( i + 1 ) ); 209 } 210 i = -1; 211 while( ( i = messageSelector.indexOf( "\n" ) ) >= 0 ) 212 { 213 messageSelector = ( i == 0 ? "" : messageSelector.substring( 0, i ) ) + 215 " " + 216 ( i >= messageSelector.length() - 1 ? "" : messageSelector.substring( i + 1 ) ); 217 } 218 messageSelector = messageSelector.trim(); 221 if( "".equals( messageSelector ) ) 222 { 223 messageSelector = null; 224 } 225 } 226 } 227 228 public String getDestinationJndiName() 229 { 230 return destinationJndiName; 231 } 232 233 public void setDestinationJndiName(String destinationJndiName) 234 { 235 this.destinationJndiName = destinationJndiName; 236 } 237 238 public String getUser() 239 { 240 return user; 241 } 242 243 public void setUser(String user) 244 { 245 this.user = user; 246 } 247 248 public String getPasswd() 249 { 250 return passwd; 251 } 252 253 public void setPasswd(String passwd) 254 { 255 this.passwd = passwd; 256 } 257 258 public String getClientId() 259 { 260 return clientId; 261 } 262 263 public void setClientId(String clientId) 264 { 265 this.clientId = clientId; 266 } 267 268 public String getSubscriptionId() 269 { 270 return subscriptionId; 271 } 272 273 public void setSubscriptionId(String subscriptionId) 274 { 275 this.subscriptionId = subscriptionId; 276 } 277 278 281 public byte getMethodTransactionType() 282 { 283 if (methodTransactionType == TX_UNSET) 284 { 285 Class [] sig = { Message .class }; 286 methodTransactionType = getMethodTransactionType("onMessage", sig); 287 } 288 return methodTransactionType; 289 } 290 291 294 public byte getMethodTransactionType(String methodName, Class [] signature) 295 { 296 if (isContainerManagedTx()) 297 { 298 if (super.getMethodTransactionType(methodName, signature, null) == MetaData.TX_NOT_SUPPORTED) 299 return TX_NOT_SUPPORTED; 300 else 301 return TX_REQUIRED; 302 } 303 else 304 return TX_UNKNOWN; 305 } 306 307 311 public byte getMethodTransactionType(String methodName, Class [] params, InvocationType iface) 312 { 313 if (isJMSMessagingType()) 315 return getMethodTransactionType(); 316 else 317 return getMethodTransactionType(methodName, params); 318 } 319 320 326 public byte getSubscriptionDurability() 327 { 328 return subscriptionDurability; 329 } 330 331 public void setSubscriptionDurability(String subscr) 332 { 333 if( subscr != null && subscr.equals("Durable") ) 335 { 336 subscriptionDurability = DURABLE_SUBSCRIPTION; 337 } 338 else 339 { 340 subscriptionDurability = NON_DURABLE_SUBSCRIPTION; } 342 } 343 344 public String getDefaultConfigurationName() 345 { 346 if (isJMSMessagingType() == false) 347 return ConfigurationMetaData.MESSAGE_INFLOW_DRIVEN; 348 else 349 return ConfigurationMetaData.MESSAGE_DRIVEN_13; 350 } 351 352 357 public HashMap getActivationConfigProperties() 358 { 359 return activationConfigProperties; 360 } 361 362 368 public ActivationConfigPropertyMetaData getActivationConfigProperty(String name) 369 { 370 return (ActivationConfigPropertyMetaData) activationConfigProperties.get(name); 371 } 372 373 378 public String getResourceAdapterName() 379 { 380 return resourceAdapterName; 381 } 382 383 public void setResourceAdapterName(String resourceAdapterName) 384 { 385 this.resourceAdapterName = resourceAdapterName; 386 } 387 388 public void importEjbJarXml(Element element) throws DeploymentException 389 { 390 super.importEjbJarXml(element); 391 392 setMessageSelector(getOptionalChildContent(element, "message-selector")); 393 394 messagingType = getOptionalChildContent(element, "messaging-type", DEFAULT_MESSAGING_TYPE); 396 397 Element destination = getOptionalChild(element, "message-driven-destination"); 399 if (destination != null) 400 { 401 destinationType = getUniqueChildContent(destination, "destination-type"); 402 if (destinationType.equals("javax.jms.Topic")) 403 { 404 String subscr = getOptionalChildContent(destination, "subscription-durability"); 405 setSubscriptionDurability(subscr); 406 } 407 } 408 409 String ejb21DestinationType = getOptionalChildContent(element, "message-destination-type"); 411 if (ejb21DestinationType != null) 412 destinationType = ejb21DestinationType; 413 414 destinationLink = getOptionalChildContent(element, "message-destination-link"); 416 417 String transactionType = getUniqueChildContent(element, "transaction-type"); 419 if (transactionType.equals("Bean")) 420 { 421 containerManagedTx = false; 422 String ack = getOptionalChildContent(element, "acknowledge-mode"); 423 setAcknowledgeMode(ack); 424 } 425 else if (transactionType.equals("Container")) 426 { 427 containerManagedTx = true; 428 } 429 else 430 { 431 throw new DeploymentException 432 ("transaction type should be 'Bean' or 'Container'"); 433 } 434 435 Element activationConfig = getOptionalChild(element, "activation-config"); 437 if (activationConfig != null) 438 { 439 Iterator iterator = getChildrenByTagName(activationConfig, "activation-config-property"); 440 while (iterator.hasNext()) 441 { 442 Element resourceRef = (Element ) iterator.next(); 443 ActivationConfigPropertyMetaData metaData = new ActivationConfigPropertyMetaData(); 444 metaData.importXml(resourceRef); 445 if (activationConfigProperties.containsKey(metaData.getName())) 446 throw new DeploymentException("Duplicate activation-config-property-name: " + metaData.getName()); 447 activationConfigProperties.put(metaData.getName(), metaData); 448 } 449 } 450 } 451 452 public void importJbossXml(Element element) throws DeploymentException 453 { 454 super.importJbossXml(element); 455 456 destinationJndiName = getOptionalChildContent(element, "destination-jndi-name"); 458 user = getOptionalChildContent(element, "mdb-user"); 459 passwd = getOptionalChildContent(element,"mdb-passwd"); 460 clientId = getOptionalChildContent(element,"mdb-client-id"); 461 subscriptionId = getOptionalChildContent(element,"mdb-subscription-id"); 462 resourceAdapterName = getOptionalChildContent(element,"resource-adapter-name"); 463 464 Element activationConfig = getOptionalChild(element, "activation-config"); 466 if (activationConfig != null) 467 { 468 Iterator iterator = getChildrenByTagName(activationConfig, "activation-config-property"); 469 while (iterator.hasNext()) 470 { 471 Element resourceRef = (Element ) iterator.next(); 472 ActivationConfigPropertyMetaData metaData = new ActivationConfigPropertyMetaData(); 473 metaData.importXml(resourceRef); 474 activationConfigProperties.put(metaData.getName(), metaData); 475 } 476 } 477 } 478 479 public void defaultInvokerBindings() 480 { 481 this.invokerBindings = new HashMap (); 482 this.invokerBindings.put(DEFAULT_MESSAGE_DRIVEN_BEAN_INVOKER_PROXY_BINDING, getJndiName()); 483 } 484 485 487 489 491 } 493 494 | Popular Tags |