1 22 package org.jboss.ejb3.mdb; 23 24 import java.lang.reflect.Field ; 25 import java.lang.reflect.Method ; 26 import org.jboss.aop.advice.Interceptor; 27 import org.jboss.aop.joinpoint.Invocation; 28 import org.jboss.logging.Logger; 29 30 36 public class CurrentMessageInjectorInterceptor implements Interceptor 37 { 38 protected final static Logger log = Logger.getLogger(CurrentMessageInjectorInterceptor.class); 39 40 private Field [] fields; 41 private Method [] methods; 42 43 public CurrentMessageInjectorInterceptor(Field [] fields, Method [] methods) 44 { 45 this.fields = fields; 46 if (fields != null) 47 { 48 for (Field field : fields) 49 { 50 field.setAccessible(true); 51 } 52 } 53 this.methods = methods; 54 if (methods != null) 55 { 56 for (Method method : methods) 57 { 58 method.setAccessible(true); 59 } 60 } 61 } 62 63 64 public String getName() 65 { 66 return this.getClass().getName(); 67 } 68 69 public Object invoke(Invocation invocation) throws Throwable 70 { 71 Object target = invocation.getTargetObject(); 72 Object message = invocation.getMetaData().getMetaData(ConsumerContainer.CONSUMER_MESSAGE, ConsumerContainer.CONSUMER_MESSAGE); 73 if (fields != null) 74 { 75 for (Field field : fields) 76 { 77 field.set(target, message); 78 } 79 } 80 if (methods != null) 81 { 82 for (Method method : methods) 83 { 84 method.invoke(target, message); 85 } 86 87 } 88 try 89 { 90 return invocation.invokeNext(); 91 } 92 finally 93 { 94 if (fields != null) 96 { 97 for (Field field : fields) 98 { 99 field.set(target, null); 100 } 101 } 102 if (methods != null) 103 { 104 for (Method method : methods) 105 { 106 Object [] args = new Object [method.getParameterTypes().length]; 107 for (int i = 0 ; i < args.length; ++i) 108 args[i] = null; 109 method.invoke(target, args); 110 } 111 } 112 } 113 } 114 } 115 | Popular Tags |