1 22 package org.jboss.mx.interceptor; 23 24 import org.jboss.mx.server.Invocation; 25 import org.jboss.mx.server.MBeanInvoker; 26 27 34 public class DynamicInterceptor extends AbstractInterceptor 35 { 36 37 public static final String ADD_INTERCEPTOR = "addOperationInterceptor"; 38 public static final String REMOVE_INTERCEPTOR = "removeOperationInterceptor"; 39 40 41 MBeanInvoker invoker; 42 43 46 public DynamicInterceptor(MBeanInvoker invoker) 47 { 48 super(); 50 setName("DynamicInterceptor"); 51 52 this.invoker = invoker; 53 } 54 55 58 public Object invoke(Invocation invocation) 59 throws Throwable 60 { 61 String type = invocation.getType(); 62 63 if (type.equals(Invocation.OP_INVOKE)) 65 { 66 String name = invocation.getName(); 67 68 if (name.equals(ADD_INTERCEPTOR)) 69 { 70 Object args[] = invocation.getArgs(); 71 Object retn = invocation.getReturnTypeClass(); 72 73 if ((args.length == 1) && (args[0] instanceof Interceptor) && (retn == null)) 74 { 75 invoker.addOperationInterceptor((Interceptor)args[0]); 76 return null; 77 } 78 } 79 else if (name.equals(REMOVE_INTERCEPTOR)) 80 { 81 Object args[] = invocation.getArgs(); 82 Object retn = invocation.getReturnTypeClass(); 83 84 if ((args.length == 1) && (args[0] instanceof Interceptor) && (retn == null)) 85 { 86 invoker.removeOperationInterceptor((Interceptor)args[0]); 87 return null; 88 } 89 } 90 } 91 92 Interceptor next = invocation.nextInterceptor(); 95 if (next != null) 96 { 97 return next.invoke(invocation); 98 } 99 else 100 { 101 return invocation.dispatch(); 102 } 103 } 104 } 105 | Popular Tags |