[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: EAR structure mock scanning

alesj do-not-reply at jboss.com
Fri May 23 06:16:05 EDT 2008


"alesj" wrote : 
  | So, someone needs to explain me now what is the logic behind JEE annotations and how the modules are marked.
  | e.g. what annotations mark some type (OK, I know the EJB3 one's, but have no clue about the others)
OK, I've added this mock kind of type matching.
It will do :-), since it's not really about what you return, it's about how you do it - via annotations scanning.


  |    private Integer determineType(VirtualFile archive)
  |    {
  |       ClassLoader classLoader = getClass().getClassLoader();
  |       GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(classLoader);
  |       ClassFilter included = null;
  |       ClassFilter excluded = null;
  |       ResourceFilter filter = org.jboss.classloading.spi.visitor.ClassFilter.INSTANCE;
  |       VFSResourceVisitor.visit(new VirtualFile[]{archive}, included, excluded, classLoader, visitor, filter);
  |       AnnotationEnvironment env = visitor.getEnv();
  | 
  |       Integer ejbs = getType(env, Stateless.class, J2eeModuleMetaData.EJB);
  |       if (ejbs != null)
  |       {
  |          // check some conflicts - e.g. no @Servlet, ...?
  |          return ejbs;
  |       }
  | 
  |       Integer services = getType(env, Service.class, J2eeModuleMetaData.SERVICE);
  |       if (services != null)
  |       {
  |          // check some conflicts - e.g. no @Servlet, ...?
  |          return services;
  |       }
  | 
  |       Integer appc = getType(env, AppClient.class, J2eeModuleMetaData.CLIENT);
  |       if (appc != null)
  |       {
  |          // check some conflicts - e.g. no @Servlet, ...?
  |          return appc;
  |       }
  | 
  |       Integer wars = getType(env, Servlet.class, J2eeModuleMetaData.WEB);
  |       if (wars != null)
  |          return wars;
  | 
  |       return null;
  |    }
  | 
  |    private Integer getType(AnnotationEnvironment env, Class<? extends Annotation> annotation, int type)
  |    {
  |       Set<Class<?>> classes = env.classIsAnnotatedWith(annotation);
  |       return (classes != null && classes.isEmpty() == false) ? type : null;
  |    }
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152929#4152929

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152929



More information about the jboss-dev-forums mailing list