1 7 package org.jboss.jms.client.container; 8 9 import org.jboss.aop.advice.Interceptor; 10 import org.jboss.aop.joinpoint.Invocation; 11 import org.jboss.aop.joinpoint.MethodInvocation; 12 13 19 public class ClientIDInterceptor 20 implements Interceptor 21 { 22 24 26 27 private String clientID; 28 29 30 private boolean determinedClientID = false; 31 32 34 36 38 40 public String getName() 41 { 42 return "ClientIDInterceptor"; 43 } 44 45 public Object invoke(Invocation invocation) throws Throwable 46 { 47 String methodName = ((MethodInvocation) invocation).getMethod().getName(); 48 if (methodName.equals("getClientID")) 49 return clientID; 50 51 if (methodName.equals("setClientID")) 52 { 53 setClientID(invocation); 54 return null; 55 } 56 57 addClientID(invocation); 58 try 59 { 60 return invocation.invokeNext(); 61 } 62 finally 63 { 64 if (determinedClientID == false) 65 { 66 clientID = (String ) invocation.getResponseAttachment("JMSClientID"); 67 if (clientID == null) 68 throw new IllegalStateException ("Unable to determine clientID"); 69 determinedClientID = true; 70 } 71 } 72 } 73 74 76 82 protected void addClientID(Invocation invocation) 83 throws Throwable 84 { 85 if (determinedClientID) 86 invocation.getMetaData().addMetaData("JMS", "clientID", clientID); 87 else 88 invocation.getMetaData().addMetaData("JMS", "clientID", null); 89 } 90 91 96 protected void setClientID(Invocation invocation) 97 throws Throwable 98 { 99 if (determinedClientID) 100 throw new IllegalStateException ("Client id is already set"); 101 102 MethodInvocation mi = (MethodInvocation) invocation; 103 clientID = (String ) mi.getArguments()[0]; 104 if (clientID == null) 105 throw new IllegalArgumentException ("Null client id"); 106 107 invocation.invokeNext(); 108 determinedClientID = true; 109 } 110 111 113 115 117 } 118 | Popular Tags |