if (log.isTraceEnabled()) { log.trace("send"); }
if (log.isTraceEnabled()) log.trace("send");
   public Object invoke(Invocation invocation) throws Throwable   {      if (invocation instanceof MethodInvocation)      {         MethodInvocation mi = (MethodInvocation)invocation;               String methodName = mi.getMethod().getName();                  if ("createSessionDelegate".equals(methodName))         {            log.debug("createSessionDelegate");                        SessionDelegate sd = (SessionDelegate)invocation.invokeNext();                        //If we get here, the sesion has been created                        Boolean transacted = (Boolean)mi.getArguments()[0];                        log.debug("Transacted: " + transacted);                        if (transacted == null)               throw new IllegalStateException("Cannot find transacted argument");            if (transacted.booleanValue())            {               log.debug("Session is transacted");                              //Session has been created and is transacted so we start a tx                                             Object Xid = ResourceManager.instance().createLocalTx();                              log.debug("Created tx");                              //And set it on the meta-data of the returned delegate's invocation handler               JMSInvocationHandler sessionHandler = getHandler(sd);                              setMetaData(sessionHandler, JMSAdvisor.XID, Xid);                                             log.debug("Added Xid to meta-data");            }                        return sd;         }         else if ("close".equals(methodName))         {            //Rollback the session                        //Make sure this invocation is for the Session since other delegates have a close() method                        //TODO         }         else if ("commit".equals(methodName))         {            log.debug("commit");            Object Xid = getMetaData(mi, JMSAdvisor.XID);                                    SessionDelegate sd = (SessionDelegate)getDelegate(mi);                        Object newXid = ResourceManager.instance().commit(Xid, sd);            setMetaData(mi, JMSAdvisor.XID, newXid);                               }         else if ("rollback".equals(methodName))         {            log.debug("rollback");            Object Xid = mi.getMetaData().getMetaData(JMSAdvisor.JMS, JMSAdvisor.XID);                                 Object newXid = ResourceManager.instance().rollback(Xid);            setMetaData(mi, JMSAdvisor.XID, newXid);          }         else if ("send".equals(methodName))         {            if (log.isTraceEnabled()) { log.trace("send"); }            JMSInvocationHandler sessionInvocationHandler = getHandler(invocation).getParent();            if (log.isTraceEnabled()) { log.trace("sessionInvocationHandler: " + sessionInvocationHandler); }            Object Xid = getMetaData(sessionInvocationHandler, JMSAdvisor.XID);            if (Xid != null)            {               //Session is transacted - so we add message to tx instead of sending now               if (log.isTraceEnabled()) { log.trace("Session is transacted, storing mesage until commit"); }               Message m = (Message)mi.getArguments()[0];               ResourceManager.instance().addMessage(Xid, m);               //And we don't invoke any further interceptors in the stack               return null;                           }            else            {               if (log.isTraceEnabled()) { log.trace("Session is not transacted, sending message now"); }            }         }         else if ("recover".equals(methodName))         {            //TODO            //I'm not sure whether this needs to be handled here or in the SesionInterceptor         }               }                     return invocation.invokeNext();               }