1 25 26 package org.objectweb.jonas_ejb.deployment.api; 27 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.ListIterator ; 31 32 import org.objectweb.jonas_ejb.deployment.xml.ActivationConfig; 33 import org.objectweb.jonas_ejb.deployment.xml.ActivationConfigProperty; 34 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor; 35 import org.objectweb.jonas_ejb.deployment.xml.JonasMessageDriven; 36 import org.objectweb.jonas_ejb.deployment.xml.MessageDriven; 37 import org.objectweb.jonas_ejb.deployment.xml.MessageDrivenDestination; 38 import org.objectweb.jonas_ejb.lib.BeanNaming; 39 40 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 41 42 import org.objectweb.jonas_lib.deployment.xml.JLinkedList; 43 44 import org.objectweb.util.monolog.api.BasicLevel; 45 46 52 public class MessageDrivenDesc extends BeanDesc { 53 54 public final static int AUTO_ACKNOWLEDGE = 1; 55 public final static int DUPS_OK_ACKNOWLEDGE = 2; 56 protected static final String [] ACKMODE = {null, "AUTO_ACKNOWLEDGE", 57 "DUPS_OK_ACKNOWLEDGE"}; 58 59 public final static int SUBS_DURABLE = 1; 60 public final static int SUBS_NON_DURABLE = 2; 61 protected static final String [] SUBS_DURABILITY = {null, 62 "SUBSCRIPTION_DURABLE", "SUBSCRIPTION_NON_DURABLE"}; 63 64 public final static int DEFAULT_MAX_MESSAGES = 1; 65 66 protected String selector = null; 67 protected int acknowledgeMode; 68 protected int subscriptionDurability = SUBS_NON_DURABLE; 69 protected Class destinationType = null; 70 protected int txAttribute = MethodDesc.TX_NOT_SET; protected boolean isTopicDestination = false; 72 protected int transactionType; 73 protected String destinationJndiName = null; 74 protected String destinationLink = null; 75 76 protected String destination = null; 78 79 protected ActivationConfigDesc mdActivationConfigDesc = null; 80 81 protected ActivationConfigDesc mdJonasActivationConfigDesc = null; 82 83 86 MessageDrivenDesc(ClassLoader classLoader, MessageDriven md, 87 AssemblyDescriptor asd, JonasMessageDriven jMd, 88 JLinkedList jMDRList, String fileName) 89 throws DeploymentDescException { 90 91 super(classLoader, md, jMd, asd, jMDRList, fileName); 92 mdActivationConfigDesc = new ActivationConfigDesc(md.getActivationConfig()); 93 mdJonasActivationConfigDesc = new ActivationConfigDesc(jMd.getActivationConfig()); 94 95 if (jMd.getMinPoolSize() != null) { 97 String tstr = jMd.getMinPoolSize(); 98 Integer tval = new Integer (tstr); 99 poolMin = tval.intValue(); 100 } 101 102 if (jMd.getMaxCacheSize() != null) { 104 String tstr = jMd.getMaxCacheSize(); 105 Integer tval = new Integer (tstr); 106 cacheMax = tval.intValue(); 107 } 108 109 if (md.getEjbName() == null) { 111 throw new Error ("No ejb-name specified for a message-driven bean"); 112 } 113 114 if (md.getTransactionType().equals("Bean")) { 116 transactionType = BEAN_TRANSACTION_TYPE; 117 } else if (md.getTransactionType().equals("Container")) { 118 transactionType = CONTAINER_TRANSACTION_TYPE; 119 } else { 120 throw new DeploymentDescException( 121 "Invalid transaction-type content for ejb-name " + ejbName); 122 } 123 124 if (jMd.getJonasMessageDrivenDestination() != null) { 126 destinationJndiName = jMd.getJonasMessageDrivenDestination() 127 .getJndiName(); 128 } 129 130 133 selector = md.getMessageSelector(); 135 if (md.getAcknowledgeMode() == null) { 137 acknowledgeMode = AUTO_ACKNOWLEDGE; 138 } else { 139 if (md.getAcknowledgeMode().equals("Auto-acknowledge")) { 140 acknowledgeMode = AUTO_ACKNOWLEDGE; 141 } else if (md.getAcknowledgeMode().equals("Dups-ok-acknowledge")) { 142 acknowledgeMode = DUPS_OK_ACKNOWLEDGE; 143 } else { 144 throw new DeploymentDescException("Invalid acknowledge-mode content for ejb-name " + ejbName); 145 } 146 } 147 MessageDrivenDestination d = md.getMessageDrivenDestination(); 148 if (d != null && d.getDestinationType() != null) { 149 if (d.getDestinationType().equals("javax.jms.Queue")) { 150 destinationType = javax.jms.Queue .class; 151 } else if (d.getDestinationType().equals("javax.jms.Topic")) { 152 destinationType = javax.jms.Topic .class; 153 isTopicDestination = true; 154 } else { 155 try { 156 destinationType = classLoader.loadClass(d.getDestinationType()); 157 } catch (Exception ex) { 158 throw new DeploymentDescException("Invalid destination-type for ejb-name " + ejbName); 159 } 160 } 161 if (d.getSubscriptionDurability() != null) { 162 if (destinationType.equals(javax.jms.Queue .class)) { 163 throw new DeploymentDescException("subscription-durability of message-driven-destination for ejb-name " 164 + ejbName + " defined"); 165 } 166 if (d.getSubscriptionDurability().equals("Durable")) { 167 subscriptionDurability = SUBS_DURABLE; 168 } else if (d.getSubscriptionDurability().equals("NonDurable")) { 169 subscriptionDurability = SUBS_NON_DURABLE; 170 } else { 171 throw new DeploymentDescException("Invalid subscription-durability content for ejb-name " + ejbName); 172 } 173 } else { 174 if (destinationType.equals(javax.jms.Topic .class)) { 176 subscriptionDurability = SUBS_NON_DURABLE; 177 } 178 } 179 180 } 181 182 destinationLink = md.getMessageDestinationLink(); 183 184 if( mdActivationConfigDesc != null) { 185 configureAC(mdActivationConfigDesc, classLoader); 186 } 187 188 if( mdJonasActivationConfigDesc != null) { 189 configureAC(mdJonasActivationConfigDesc, classLoader); 190 } 191 192 if (destinationJndiName == null) { 193 throw new Error ("No destination specified for message-driven bean " + ejbName); 194 } 195 196 for (Iterator i = getMethodDescIterator(); i.hasNext();) { 198 MethodDesc methd = (MethodDesc) i.next(); 199 if (methd.getMethod().getName().equals("onMessage")) { 200 txAttribute = methd.getTxAttribute(); 201 } 202 if (methd.getMethod().getName().equals("ejbTimeout")) { 203 timerTxAttribute = methd.getTxAttribute(); 204 ejbTimeoutSignature = BeanNaming.getSignature(getEjbName(), methd.getMethod()); 205 } 206 } 207 } 208 209 215 public int getTransactionType() { 216 return transactionType; 217 } 218 219 224 public int getTxAttribute() { 225 return txAttribute; 226 } 227 228 231 public boolean isBeanManagedTransaction() { 232 return (transactionType == BeanDesc.BEAN_TRANSACTION_TYPE); 233 } 234 235 239 public String getDestination() { 240 return(destination); 241 } 242 243 248 public String getDestinationJndiName() { 249 return (destinationJndiName); 250 } 251 252 257 public String getDestinationLink() { 258 return (destinationLink); 259 } 260 261 266 public Class getDestinationType() { 267 return (destinationType); 268 } 269 270 273 public boolean isTopicDestination() { 274 return (isTopicDestination); 275 } 276 277 282 public boolean hasSelector() { 283 return (selector != null); 284 } 285 286 291 public String getSelector() { 292 return (selector); 293 } 294 295 301 public int getAcknowledgeMode() { 302 return (acknowledgeMode); 303 } 304 305 311 public int getSubscriptionDurability() { 312 return (subscriptionDurability); 313 } 314 315 public boolean isSubscriptionDurable() { 316 return (subscriptionDurability == SUBS_DURABLE); 317 } 318 319 322 public boolean isRequired() { 323 return (txAttribute == MethodDesc.TX_REQUIRED); 324 } 325 326 330 public int getMaxMessages() { 331 return DEFAULT_MAX_MESSAGES; 332 } 333 334 337 protected void checkTxAttribute(MethodDesc md) 338 throws DeploymentDescException { 339 java.lang.reflect.Method m = md.getMethod(); 340 if (getTransactionType() == CONTAINER_TRANSACTION_TYPE) { 341 if (md.getTxAttribute() == MethodDesc.TX_NOT_SET) { 342 logger.log(BasicLevel.WARN, 345 "trans-attribute missing for method " 346 + m.toString() + " in message driven bean " 347 + getEjbName() 348 + " (set to the default value " 349 + MethodDesc.TX_STR_DEFAULT_VALUE_4_MDB 350 + ")"); 351 md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE_4_MDB); 352 } 353 if ((md.getTxAttribute() != MethodDesc.TX_REQUIRED) 354 && (md.getTxAttribute() != MethodDesc.TX_NOT_SUPPORTED)) { 355 if (!"ejbTimeout".equals(md.getMethod().getName())) { 356 throw new DeploymentDescException(md.getTxAttributeName() 357 + " is not a valid trans-attribute for method " 358 + m.toString() + " in message driven bean " 359 + getEjbName()); 360 } 361 } 362 } else { 363 if (md.getTxAttribute() != MethodDesc.TX_NOT_SET) { 364 throw new DeploymentDescException( 365 "trans-attribute for message driven bean " 366 + getEjbName() 367 + " must not be defined (transaction bean managed)"); 368 } 369 } 370 } 371 372 378 public void check() throws DeploymentDescException { 379 super.check(); 380 } 381 382 387 public String toString() { 388 StringBuffer ret = new StringBuffer (); 389 ret.append(super.toString()); 390 ret.append("\ngetTransactionType()=" + TRANS[getTransactionType()]); 391 if (hasSelector()) { 392 ret.append("\ngetSelector()=\"" + getSelector() + "\""); 393 } 394 ret.append("\ngetAcknowledgeMode()=" + ACKMODE[getAcknowledgeMode()]); 395 if (getDestinationType() != null) { 396 ret.append("\ngetDestinationType()=" 397 + getDestinationType().getName()); 398 } 399 ret.append("\ngetSubscriptionDurability()=" 400 + SUBS_DURABILITY[getSubscriptionDurability()]); 401 ret.append("\ngetDestinationJndiName()=" + getDestinationJndiName()); 402 return ret.toString(); 403 } 404 405 406 409 public ActivationConfigDesc getMdActivationConfigDesc() { 410 return mdActivationConfigDesc; 411 } 412 413 416 public ActivationConfigDesc getJonasMdActivationConfigDesc() { 417 return mdJonasActivationConfigDesc; 418 } 419 420 private void configureAC(ActivationConfigDesc ac, ClassLoader curLoader) throws DeploymentDescException{ 421 try { 422 List acpl = ac.getActivationConfigPropertyList(); 423 for (ListIterator lit = acpl.listIterator();lit.hasNext();) { 424 ActivationConfigPropertyDesc el = (ActivationConfigPropertyDesc)lit.next(); 425 if (el.getActivationConfigPropertyName().equals("destinationType")) { 426 if (el.getActivationConfigPropertyValue().equals("javax.jms.Queue")) { 427 destinationType = javax.jms.Queue .class; 428 } else if (el.getActivationConfigPropertyValue().equals("javax.jms.Topic")) { 429 destinationType = javax.jms.Topic .class; 430 isTopicDestination = true; 431 } else { 432 try { 433 destinationType = curLoader.loadClass(el.getActivationConfigPropertyValue()); 434 } catch (Exception ex) { 435 throw new DeploymentDescException("Invalid destination-type of " 436 + el.getActivationConfigPropertyValue() 437 + "for ejb-name" + ejbName); 438 } 439 } 440 } else if (el.getActivationConfigPropertyName().equals("messageSelector")) { 441 selector = el.getActivationConfigPropertyValue(); 442 } else if (el.getActivationConfigPropertyName().equals("acknowledgeMode")) { 443 if (el.getActivationConfigPropertyValue().equals("Auto-acknowledge")) { 444 acknowledgeMode = AUTO_ACKNOWLEDGE; 445 } else if (el.getActivationConfigPropertyValue().equals("Dups-ok-acknowledge")) { 446 acknowledgeMode = DUPS_OK_ACKNOWLEDGE; 447 } 448 } else if (el.getActivationConfigPropertyName().equals("subscriptionDurability")) { 449 if (el.getActivationConfigPropertyValue().equals("Durable")) { 450 subscriptionDurability = SUBS_DURABLE; 451 } else { 452 subscriptionDurability = SUBS_NON_DURABLE; 453 } 454 } else if (el.getActivationConfigPropertyName().equals("destination")) { 455 destination = el.getActivationConfigPropertyValue(); 456 } 457 } 458 } catch (Exception ex) { 459 ex.printStackTrace(); 460 } 461 } 462 463 464 } 465 466 | Popular Tags |