if (log.isTraceEnabled()) { log.trace("ConnectionInterceptor, methodName=" + methodName); }
if (log.isTraceEnabled()) { log.trace("handling " + methodName); }
   public Object invoke(Invocation invocation) throws Throwable   {      if (!(invocation instanceof MethodInvocation))      {         return invocation.invokeNext();      }            MethodInvocation mi = (MethodInvocation)invocation;      String methodName = mi.getMethod().getName();                        if (log.isTraceEnabled())      {         log.trace("ConnectionInterceptor, methodName=" + methodName);      }            if ("createConnectionDelegate".equals(methodName))      {         ConnectionDelegate connectionDelegate = (ConnectionDelegate)invocation.invokeNext();         ResourceManager rm = new ResourceManager(connectionDelegate);         connectionDelegate.setResourceManager(rm);         return connectionDelegate;      }              if ("getClientID".equals(methodName))      {                    justCreated = false;         if (clientID == null)                   {            //Get from server            clientID = (String)invocation.invokeNext();         }         return clientID;      }      else if ("setClientID".equals(methodName))      {                     if (clientID != null)         {            throw new IllegalStateException("Client id has already been set");         }         if (!justCreated)         {            throw new IllegalStateException("setClientID can only be called directly after the connection is created");         }         clientID = (String)mi.getArguments()[0];                  justCreated = false;                  //This gets invoked on the server too         return invocation.invokeNext();      }      else if ("getExceptionListener".equals(methodName))      {                     justCreated = false;         return exceptionListener;      }      else if ("setExceptionListener".equals(methodName))      {         justCreated = false;         exceptionListener = (ExceptionListener)mi.getArguments()[0];                  Client client = (Client)invocation.getMetaData(RemotingClientInterceptor.REMOTING, RemotingClientInterceptor.CLIENT);                           if (client == null)         {            throw new java.lang.IllegalStateException("Cannot find remoting client");         }                  if (exceptionListener != null)         {            client.addConnectionListener(this);            listenerAdded = true;         }         else         {                        if (listenerAdded)            {               client.removeConnectionListener(this);            }         }         return null;      }      else if ("getConnectionMetaData".equals(methodName))      {         justCreated = false;         return connMetaData;      }      else if ("getResourceManager".equals(methodName))      {         return rm;      }      else if ("setResourceManager".equals(methodName))      {         this.rm = (ResourceManager)mi.getArguments()[0];         return null;      }      else if ("createSessionDelegate".equals(methodName))      {         justCreated = false;         return invocation.invokeNext();      }      else      {         return invocation.invokeNext();      }   }