1 22 package org.jboss.ejb3.mdb; 23 24 import java.lang.reflect.Field ; 25 import java.lang.reflect.Method ; 26 import java.util.ArrayList ; 27 import org.jboss.aop.advice.AspectFactory; 28 import org.jboss.aop.Advisor; 29 import org.jboss.aop.InstanceAdvisor; 30 import org.jboss.aop.joinpoint.Joinpoint; 31 import org.jboss.annotation.ejb.CurrentMessage; 32 33 import org.jboss.ejb3.Container; 34 35 41 public class CurrentMessageInjectorInterceptorFactory implements AspectFactory 42 { 43 public Object createPerVM() 44 { 45 return null; 46 } 47 48 public Object createPerClass(Advisor advisor) 49 { 50 Class clazz = advisor.getClazz(); 51 ArrayList <Field > fs = new ArrayList <Field >(); 52 ArrayList <Method > ms = new ArrayList <Method >(); 53 54 search(advisor,clazz, fs, ms); 55 56 Method [] methods = ms.toArray(new Method [ms.size()]); 57 Field [] fields = fs.toArray(new Field [fs.size()]); 58 if (methods.length == 0) methods = null; 59 if (fields.length == 0) fields = null; 60 return new CurrentMessageInjectorInterceptor(fields, methods); 61 } 62 63 protected void search(Advisor advisor, Class clazz, ArrayList <Field > fs, ArrayList <Method > ms) 64 { 65 Method [] methods = clazz.getDeclaredMethods(); 66 Field [] fields = clazz.getDeclaredFields(); 67 for (Field field : fields) 68 { 69 if (advisor.resolveAnnotation(field, CurrentMessage.class) != null) 70 fs.add(field); 71 } 72 for (Method method : methods) 73 { 74 if (advisor.resolveAnnotation(method, CurrentMessage.class) != null) 75 ms.add(method); 76 } 77 if (clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object .class)) 78 { 79 search(advisor, clazz.getSuperclass(), fs, ms); 80 } 81 } 82 83 public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor) 84 { 85 throw new IllegalArgumentException ("NOT LEGAL"); 86 } 87 88 public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) 89 { 90 throw new IllegalArgumentException ("NOT LEGAL"); 91 } 92 93 public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp) 94 { 95 throw new IllegalArgumentException ("NOT LEGAL"); 96 } 97 98 public String getName() 99 { 100 return CurrentMessageInjectorInterceptor.class.getName(); 101 } 102 } 103 | Popular Tags |