MessageDrivenDesc.java

00001 
00026 package org.objectweb.jonas_ejb.deployment.api;
00027 
00028 import java.util.Iterator;
00029 import java.util.List;
00030 import java.util.ListIterator;
00031 
00032 import org.objectweb.jonas_ejb.deployment.xml.ActivationConfig;
00033 import org.objectweb.jonas_ejb.deployment.xml.ActivationConfigProperty;
00034 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
00035 import org.objectweb.jonas_ejb.deployment.xml.JonasMessageDriven;
00036 import org.objectweb.jonas_ejb.deployment.xml.MessageDriven;
00037 import org.objectweb.jonas_ejb.deployment.xml.MessageDrivenDestination;
00038 import org.objectweb.jonas_ejb.lib.BeanNaming;
00039 
00040 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00041 
00042 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
00043 
00044 import org.objectweb.util.monolog.api.BasicLevel;
00045 
00052 public class MessageDrivenDesc extends BeanDesc {
00053 
00054     public final static int AUTO_ACKNOWLEDGE = 1;
00055     public final static int DUPS_OK_ACKNOWLEDGE = 2;
00056     protected static final String[] ACKMODE = {null, "AUTO_ACKNOWLEDGE",
00057             "DUPS_OK_ACKNOWLEDGE"};
00058 
00059     public final static int SUBS_DURABLE = 1;
00060     public final static int SUBS_NON_DURABLE = 2;
00061     protected static final String[] SUBS_DURABILITY = {null,
00062             "SUBSCRIPTION_DURABLE", "SUBSCRIPTION_NON_DURABLE"};
00063 
00064     public final static int DEFAULT_MAX_MESSAGES = 1;
00065 
00066     protected String selector = null;
00067     protected int acknowledgeMode;
00068     protected int subscriptionDurability = SUBS_NON_DURABLE;
00069     protected Class destinationType = null;
00070     protected int txAttribute = MethodDesc.TX_NOT_SET; // for onMessage method
00071     protected boolean isTopicDestination = false;
00072     protected int transactionType;
00073     protected String destinationJndiName = null;
00074     protected String destinationLink = null;
00075     
00076     // Used with JMS Rars
00077     protected String destination = null;
00078 
00079     protected ActivationConfigDesc mdActivationConfigDesc = null;
00080 
00081     protected ActivationConfigDesc mdJonasActivationConfigDesc = null;
00082 
00086     MessageDrivenDesc(ClassLoader classLoader, MessageDriven md,
00087             AssemblyDescriptor asd, JonasMessageDriven jMd,
00088             JLinkedList jMDRList, String fileName)
00089             throws DeploymentDescException {
00090 
00091         super(classLoader, md, jMd, asd, jMDRList, fileName);
00092         mdActivationConfigDesc = new ActivationConfigDesc(md.getActivationConfig());
00093         mdJonasActivationConfigDesc = new ActivationConfigDesc(jMd.getActivationConfig());
00094 
00095         // min-pool-size
00096         if (jMd.getMinPoolSize() != null) {
00097             String tstr = jMd.getMinPoolSize();
00098             Integer tval = new Integer(tstr);
00099             poolMin = tval.intValue();
00100         }
00101 
00102         // max-cache-size
00103         if (jMd.getMaxCacheSize() != null) {
00104             String tstr = jMd.getMaxCacheSize();
00105             Integer tval = new Integer(tstr);
00106             cacheMax = tval.intValue();
00107         }
00108 
00109         // necessary check
00110         if (md.getEjbName() == null) {
00111             throw new Error("No ejb-name specified for a message-driven bean");
00112         }
00113 
00114         // transaction-type
00115         if (md.getTransactionType().equals("Bean")) {
00116             transactionType = BEAN_TRANSACTION_TYPE;
00117         } else if (md.getTransactionType().equals("Container")) {
00118             transactionType = CONTAINER_TRANSACTION_TYPE;
00119         } else {
00120             throw new DeploymentDescException(
00121                     "Invalid transaction-type content for ejb-name " + ejbName);
00122         }
00123 
00124         // message driven destination
00125         if (jMd.getJonasMessageDrivenDestination() != null) {
00126             destinationJndiName = jMd.getJonasMessageDrivenDestination()
00127                     .getJndiName();
00128         }
00129 
00130         // Set values can be from old 2.0 way, ActivationConfig in std xml, 
00131         //  or ActivationConfig in jonas xml
00132         
00133         // message selector
00134         selector = md.getMessageSelector();
00135         // acknowledge mode
00136         if (md.getAcknowledgeMode() == null) {
00137             acknowledgeMode = AUTO_ACKNOWLEDGE;
00138         } else {
00139             if (md.getAcknowledgeMode().equals("Auto-acknowledge")) {
00140                 acknowledgeMode = AUTO_ACKNOWLEDGE;
00141             } else  if (md.getAcknowledgeMode().equals("Dups-ok-acknowledge")) {
00142                 acknowledgeMode = DUPS_OK_ACKNOWLEDGE;
00143             } else {
00144                 throw new DeploymentDescException("Invalid acknowledge-mode content for ejb-name " + ejbName);
00145             }
00146         }
00147         MessageDrivenDestination d = md.getMessageDrivenDestination();
00148         if (d != null && d.getDestinationType() != null) {
00149             if (d.getDestinationType().equals("javax.jms.Queue")) {
00150                 destinationType = javax.jms.Queue.class;
00151             } else  if (d.getDestinationType().equals("javax.jms.Topic")) {
00152                 destinationType = javax.jms.Topic.class;
00153                 isTopicDestination = true;
00154             } else {
00155                 try {
00156                     destinationType = classLoader.loadClass(d.getDestinationType());
00157                 } catch (Exception ex) {
00158                     throw new DeploymentDescException("Invalid destination-type for ejb-name " + ejbName);
00159                 }
00160             }
00161             if (d.getSubscriptionDurability() != null) {
00162                 if (destinationType.equals(javax.jms.Queue.class)) {
00163                     throw new DeploymentDescException("subscription-durability of message-driven-destination for ejb-name " 
00164                                                       + ejbName + " defined");
00165                 }
00166                 if (d.getSubscriptionDurability().equals("Durable")) {
00167                     subscriptionDurability = SUBS_DURABLE;
00168                 } else  if (d.getSubscriptionDurability().equals("NonDurable")) {
00169                     subscriptionDurability = SUBS_NON_DURABLE;
00170                 } else {
00171                     throw new DeploymentDescException("Invalid subscription-durability content for ejb-name " + ejbName);
00172                 }
00173             } else {
00174                 // non-durable subscription default value for topic
00175                 if (destinationType.equals(javax.jms.Topic.class)) {
00176                     subscriptionDurability = SUBS_NON_DURABLE;
00177                 }
00178             }
00179 
00180         }
00181 
00182         destinationLink = md.getMessageDestinationLink();
00183 
00184         if( mdActivationConfigDesc != null) {
00185             configureAC(mdActivationConfigDesc, classLoader);
00186         } 
00187         
00188         if( mdJonasActivationConfigDesc != null) {
00189             configureAC(mdJonasActivationConfigDesc, classLoader);
00190         } 
00191         
00192         if (destinationJndiName == null) {
00193             throw new Error("No destination specified for message-driven bean " + ejbName);
00194         }
00195 
00196         // cache TxAttribute for onMessage and ejbTimeout
00197         for (Iterator i = getMethodDescIterator(); i.hasNext();) {
00198             MethodDesc methd = (MethodDesc) i.next();
00199             if (methd.getMethod().getName().equals("onMessage")) {
00200                 txAttribute = methd.getTxAttribute();
00201             }
00202             if (methd.getMethod().getName().equals("ejbTimeout")) {
00203                 timerTxAttribute = methd.getTxAttribute();
00204                 ejbTimeoutSignature = BeanNaming.getSignature(getEjbName(), methd.getMethod());
00205             }
00206         }
00207     }
00208 
00215     public int getTransactionType() {
00216         return transactionType;
00217     }
00218 
00224     public int getTxAttribute() {
00225         return txAttribute;
00226     }
00227 
00231     public boolean isBeanManagedTransaction() {
00232         return (transactionType == BeanDesc.BEAN_TRANSACTION_TYPE);
00233     }
00234 
00239     public String getDestination() {
00240         return(destination);
00241     }
00242 
00248     public String getDestinationJndiName() {
00249         return (destinationJndiName);
00250     }
00251 
00257     public String getDestinationLink() {
00258         return (destinationLink);
00259     }
00260 
00266     public Class getDestinationType() {
00267         return (destinationType);
00268     }
00269 
00273     public boolean isTopicDestination() {
00274         return (isTopicDestination);
00275     }
00276 
00282     public boolean hasSelector() {
00283         return (selector != null);
00284     }
00285 
00291     public String getSelector() {
00292         return (selector);
00293     }
00294 
00301     public int getAcknowledgeMode() {
00302         return (acknowledgeMode);
00303     }
00304 
00311     public int getSubscriptionDurability() {
00312         return (subscriptionDurability);
00313     }
00314 
00315     public boolean isSubscriptionDurable() {
00316         return (subscriptionDurability == SUBS_DURABLE);
00317     }
00318 
00322     public boolean isRequired() {
00323         return (txAttribute == MethodDesc.TX_REQUIRED);
00324     }
00325 
00330     public int getMaxMessages() {
00331         return DEFAULT_MAX_MESSAGES;
00332     }
00333 
00337     protected void checkTxAttribute(MethodDesc md)
00338             throws DeploymentDescException {
00339         java.lang.reflect.Method m = md.getMethod();
00340         if (getTransactionType() == CONTAINER_TRANSACTION_TYPE) {
00341             if (md.getTxAttribute() == MethodDesc.TX_NOT_SET) {
00342                 // trans-attribute not set !
00343                 // trace a warning and set the tx-attribute with the default value
00344                 logger.log(BasicLevel.WARN,
00345                            "trans-attribute missing for method "
00346                            + m.toString() + " in message driven bean "
00347                            + getEjbName()
00348                            + " (set to the default value "
00349                            + MethodDesc.TX_STR_DEFAULT_VALUE_4_MDB
00350                            + ")");
00351                 md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE_4_MDB);
00352             }
00353             if ((md.getTxAttribute() != MethodDesc.TX_REQUIRED)
00354                     && (md.getTxAttribute() != MethodDesc.TX_NOT_SUPPORTED)) {
00355                 if (!"ejbTimeout".equals(md.getMethod().getName())) {
00356                     throw new DeploymentDescException(md.getTxAttributeName()
00357                             + " is not a valid trans-attribute for method "
00358                             + m.toString() + " in message driven bean "
00359                             + getEjbName());
00360                 }
00361             }
00362         } else {
00363             if (md.getTxAttribute() != MethodDesc.TX_NOT_SET) {
00364                 throw new DeploymentDescException(
00365                         "trans-attribute for message driven bean "
00366                                 + getEjbName()
00367                                 + " must not be defined (transaction bean managed)");
00368             }
00369         }
00370     }
00371 
00378     public void check() throws DeploymentDescException {
00379         super.check();
00380     }
00381 
00387     public String toString() {
00388         StringBuffer ret = new StringBuffer();
00389         ret.append(super.toString());
00390         ret.append("\ngetTransactionType()=" + TRANS[getTransactionType()]);
00391         if (hasSelector()) {
00392             ret.append("\ngetSelector()=\"" + getSelector() + "\"");
00393         }
00394         ret.append("\ngetAcknowledgeMode()=" + ACKMODE[getAcknowledgeMode()]);
00395         if (getDestinationType() != null) {
00396             ret.append("\ngetDestinationType()="
00397                     + getDestinationType().getName());
00398         }
00399         ret.append("\ngetSubscriptionDurability()="
00400                 + SUBS_DURABILITY[getSubscriptionDurability()]);
00401         ret.append("\ngetDestinationJndiName()=" + getDestinationJndiName());
00402         return ret.toString();
00403     }
00404 
00405 
00409     public ActivationConfigDesc getMdActivationConfigDesc() {
00410         return mdActivationConfigDesc;
00411     }
00412 
00416     public ActivationConfigDesc getJonasMdActivationConfigDesc() {
00417         return mdJonasActivationConfigDesc;
00418     }
00419     
00420     private void configureAC(ActivationConfigDesc ac, ClassLoader curLoader) throws DeploymentDescException{
00421         try {
00422             List acpl = ac.getActivationConfigPropertyList();
00423             for (ListIterator lit = acpl.listIterator();lit.hasNext();) {
00424                 ActivationConfigPropertyDesc el = (ActivationConfigPropertyDesc)lit.next();
00425                 if (el.getActivationConfigPropertyName().equals("destinationType")) {
00426                     if (el.getActivationConfigPropertyValue().equals("javax.jms.Queue")) {
00427                         destinationType = javax.jms.Queue.class;
00428                     } else if (el.getActivationConfigPropertyValue().equals("javax.jms.Topic")) {
00429                         destinationType = javax.jms.Topic.class;
00430                         isTopicDestination = true;
00431                     } else {
00432                         try {
00433                             destinationType = curLoader.loadClass(el.getActivationConfigPropertyValue());
00434                         } catch (Exception ex) {
00435                             throw new DeploymentDescException("Invalid destination-type of " 
00436                                                   + el.getActivationConfigPropertyValue() 
00437                                                   + "for ejb-name" + ejbName);
00438                         }
00439                     } 
00440                 } else if (el.getActivationConfigPropertyName().equals("messageSelector")) {
00441                     selector = el.getActivationConfigPropertyValue();
00442                 } else if (el.getActivationConfigPropertyName().equals("acknowledgeMode")) {
00443                     if (el.getActivationConfigPropertyValue().equals("Auto-acknowledge")) {
00444                         acknowledgeMode = AUTO_ACKNOWLEDGE;
00445                     } else  if (el.getActivationConfigPropertyValue().equals("Dups-ok-acknowledge")) {
00446                         acknowledgeMode = DUPS_OK_ACKNOWLEDGE;
00447                     }
00448                 } else if (el.getActivationConfigPropertyName().equals("subscriptionDurability")) {
00449                     if (el.getActivationConfigPropertyValue().equals("Durable")) {
00450                         subscriptionDurability = SUBS_DURABLE;
00451                     } else {
00452                         subscriptionDurability = SUBS_NON_DURABLE;
00453                     }
00454                 } else if (el.getActivationConfigPropertyName().equals("destination")) {
00455                     destination = el.getActivationConfigPropertyValue();
00456                 }
00457             }
00458         } catch (Exception ex) {
00459             ex.printStackTrace();
00460         }
00461     }
00462 
00463     
00464 }
00465 

Generated on Tue Feb 15 15:05:45 2005 for JOnAS by  doxygen 1.3.9.1