Seam annotation processing
asookazian Nov 8, 2009 7:45 PMHow does the Seam container process all the annotations in a Seam application?
I did not find any answer to this question in DAllen or Yuan books.
I don't think the Java Reflection API is being used in the framework codebase. I'm guessing there's an interceptor that is responsible for the annotation processing?
I wrote this simple class that outputs some annotation-related info:
package org.jboss.seam.example.booking; import java.lang.reflect.Method; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Create; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.Startup; import org.jboss.seam.log.Log; @Name("testReflections") @Startup @Scope(ScopeType.APPLICATION) public class TestReflections { @Logger private Log log; @Create public void init(){ getAnnotations("org.jboss.seam.Component"); getAnnotations("org.jboss.seam.example.booking.BookingListAction"); } private void getAnnotations(String myClass) { try { Class clazz = Class.forName(myClass); Method[] methods = clazz.getMethods(); java.lang.annotation.Annotation[] annotations = null; for (int i = 0; i < methods.length; i++) { log.info("methods[i].toString(): "+methods[i].toString()); annotations = methods[i].getAnnotations(); for(int j = 0; j < annotations.length; j++){ java.lang.annotation.Annotation annotation = annotations[j]; log.info("annotation.toString() = "+annotation.toString()); } } log.info("***********************************************************************************"); } catch (ClassNotFoundException e) { log.error("error found: ", e); } } }
results:
10:02:45,145 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isInstance(java.lang.Object) 10:02:45,145 INFO [TestReflections] methods[i].toString(): public static org.jboss.seam.Component org.jboss.seam.Component.forName(java.lang.String) 10:02:45,145 INFO [TestReflections] methods[i].toString(): public java.lang.String org.jboss.seam.Component.getName() 10:02:45,145 INFO [TestReflections] methods[i].toString(): public java.lang.String org.jboss.seam.Component.toString() 10:02:45,145 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.String,org.jboss.seam.ScopeType,boolean) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.String,boolean,boolean) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.String,boolean) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.String) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.String,org.jboss.seam.ScopeType) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.String,org.jboss.seam.ScopeType,boolean,boolean) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.Class,org.jboss.seam.ScopeType,boolean) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.Class,org.jboss.seam.ScopeType) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.Class,boolean) 10:02:45,147 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstance(java.lang.Class) 10:02:45,150 INFO [TestReflections] methods[i].toString(): public java.lang.Object org.jboss.seam.Component.newInstance() 10:02:45,151 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.destroy(java.lang.Object) 10:02:45,151 INFO [TestReflections] methods[i].toString(): public org.jboss.seam.ComponentType org.jboss.seam.Component.getType() 10:02:45,151 INFO [TestReflections] methods[i].toString(): public java.lang.Object org.jboss.seam.Component.wrap(java.lang.Object,javassist.util.proxy.MethodHandler) throws java.lang.Exception 10:02:45,151 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.initialize(java.lang.Object) throws java.lang.Exception 10:02:45,151 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.getInterceptors(org.jboss.seam.annotations.intercept.InterceptorType) 10:02:45,151 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.inject(java.lang.Object,boolean) 10:02:45,151 INFO [TestReflections] methods[i].toString(): public org.jboss.seam.Namespace org.jboss.seam.Component.getNamespace() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public long org.jboss.seam.Component.getTimeout() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public org.jboss.seam.ScopeType org.jboss.seam.Component.getScope() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.addInterceptor(org.jboss.seam.intercept.Interceptor) 10:02:45,153 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.addInterceptor(java.lang.Object) 10:02:45,153 INFO [TestReflections] methods[i].toString(): public java.lang.String[] org.jboss.seam.Component.getDependencies() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public java.util.Collection org.jboss.seam.Component.getImports() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isSecure() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public java.util.Collection org.jboss.seam.Component.getRemoveMethods() 10:02:45,153 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getCreateMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public static java.lang.String org.jboss.seam.Component.getComponentName(java.lang.Class) 10:02:45,156 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.createUserInterceptors(org.jboss.seam.annotations.intercept.InterceptorType) 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isInterceptionEnabled() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.beanClassHasAnnotation(java.lang.String) 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.beanClassHasAnnotation(java.lang.Class) 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.businessInterfaceHasAnnotation(java.lang.Class) 10:02:45,156 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.getServerSideInterceptors() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.getClientSideInterceptors() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getDestroyMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getRemoveMethod(java.lang.String) 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasPreDestroyMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasPostConstructMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasPrePassivateMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasPostActivateMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasDestroyMethod() 10:02:45,156 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasCreateMethod() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasUnwrapMethod() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getUnwrapMethod() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.getOutAttributes() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.getInAttributes() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.needsInjection() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.needsOutjection() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.disinject(java.lang.Object) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.outject(java.lang.Object,boolean) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public java.util.Set org.jboss.seam.Component.getBusinessInterfaces() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public static java.util.Set org.jboss.seam.Component.getBusinessInterfaces(java.lang.Class) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public static java.lang.Object org.jboss.seam.Component.getInstanceFromFactory(java.lang.String) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasDefaultRemoveMethod() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getDefaultRemoveMethod() 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.callCreateMethod(java.lang.Object) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.callDestroyMethod(java.lang.Object) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.callPreDestroyMethod(java.lang.Object) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.callPostConstructMethod(java.lang.Object) 10:02:45,158 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.callPrePassivateMethod(java.lang.Object) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.Component.callPostActivateMethod(java.lang.Object) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getPostActivateMethod() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getPrePassivateMethod() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getPostConstructMethod() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public java.lang.reflect.Method org.jboss.seam.Component.getPreDestroyMethod() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public transient java.lang.Object org.jboss.seam.Component.callComponentMethod(java.lang.Object,java.lang.reflect.Method,java.lang.Object[]) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public static java.lang.Class org.jboss.seam.Component.createProxyFactory(org.jboss.seam.ComponentType,java.lang.Class,java.util.Collection) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isStartup() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isSynchronize() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isLifecycleMethod(java.lang.reflect.Method) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isConversationManagementMethod(java.lang.reflect.Method) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public java.util.List org.jboss.seam.Component.getPersistenceContextAttributes() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.isPerNestedConversation() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public boolean org.jboss.seam.Component.hasConversationManagementMethods() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public static org.jboss.seam.Model org.jboss.seam.Model.forClass(java.lang.Class) 10:02:45,161 INFO [TestReflections] methods[i].toString(): public final java.lang.Class org.jboss.seam.Model.getBeanClass() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public native int java.lang.Object.hashCode() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public final native java.lang.Class java.lang.Object.getClass() 10:02:45,161 INFO [TestReflections] methods[i].toString(): public final void java.lang.Object.wait() throws java.lang.InterruptedException 10:02:45,161 INFO [TestReflections] methods[i].toString(): public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException 10:02:45,161 INFO [TestReflections] methods[i].toString(): public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException 10:02:45,163 INFO [TestReflections] methods[i].toString(): public boolean java.lang.Object.equals(java.lang.Object) 10:02:45,163 INFO [TestReflections] methods[i].toString(): public final native void java.lang.Object.notify() 10:02:45,163 INFO [TestReflections] methods[i].toString(): public final native void java.lang.Object.notifyAll() 10:02:45,163 INFO [TestReflections] *********************************************************************************** 10:02:45,163 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.example.booking.BookingListAction.destroy() 10:02:45,163 INFO [TestReflections] annotation.toString() = @javax.ejb.Remove(retainIfException=false) 10:02:45,163 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.example.booking.BookingListAction.cancel() 10:02:45,163 INFO [TestReflections] methods[i].toString(): public void org.jboss.seam.example.booking.BookingListAction.getBookings() 10:02:45,163 INFO [TestReflections] annotation.toString() = @org.jboss.seam.annotations.Factory(value=, autoCreate=false, scope=UNSPECIFIED) 10:02:45,163 INFO [TestReflections] annotation.toString() = @org.jboss.seam.annotations.Observer(value=[bookingConfirmed], create=true) 10:02:45,166 INFO [TestReflections] methods[i].toString(): public org.jboss.seam.example.booking.Booking org.jboss.seam.example.booking.BookingListAction.getBooking() 10:02:45,166 INFO [TestReflections] methods[i].toString(): public native int java.lang.Object.hashCode() 10:02:45,166 INFO [TestReflections] methods[i].toString(): public final native java.lang.Class java.lang.Object.getClass() 10:02:45,166 INFO [TestReflections] methods[i].toString(): public final void java.lang.Object.wait() throws java.lang.InterruptedException 10:02:45,166 INFO [TestReflections] methods[i].toString(): public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException 10:02:45,166 INFO [TestReflections] methods[i].toString(): public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException 10:02:45,166 INFO [TestReflections] methods[i].toString(): public boolean java.lang.Object.equals(java.lang.Object) 10:02:45,166 INFO [TestReflections] methods[i].toString(): public final native void java.lang.Object.notify() 10:02:45,166 INFO [TestReflections] methods[i].toString(): public final native void java.lang.Object.notifyAll() 10:02:45,166 INFO [TestReflections] methods[i].toString(): public java.lang.String java.lang.Object.toString() 10:02:45,166 INFO [TestReflections] ***********************************************************************************