[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Annotations scanning part 2

alesj do-not-reply at jboss.com
Thu May 22 16:55:03 EDT 2008


"alesj" wrote : 
  | I've added a deployer that knows how to scan newly added @Bean and @BeanFactory annotations - corresponding to MC beans and beanfactories.
  | 
I've added this code to be able to easily remove added bean components in BeanScanningDeployer:

  |     public void deploy(DeploymentUnit unit, AnnotationEnvironment env) throws DeploymentException
  |     {
  |        Map<String, DeploymentUnit> components = null;
  | +      Set<String> beanNames = null;
  |  
  |        Set<Class<?>> beans = env.classIsAnnotatedWith(Bean.class);
  |        if (beans != null && beans.isEmpty() == false)
  |        {
  |           components = new HashMap<String, DeploymentUnit>();
  | +         beanNames = new HashSet<String>();
  |           mapComponents(unit, components);
  |  
  |           for (Class<?> beanClass : beans)
  | @@ -107,6 +109,7 @@
  |                        .setAutowireCandidate(bean.autowireCandidate());
  |  
  |                 KernelDeploymentDeployer.addBeanComponent(unit, builder.getBeanMetaData());
  | +               beanNames.add(name);
  |              }
  |              else
  |              {
  | @@ -123,6 +126,7 @@
  |           {
  |              components = new HashMap<String, DeploymentUnit>();
  |              mapComponents(unit, components);
  | +            beanNames = new HashSet<String>();
  |           }
  |  
  |           for (Class<?> beanFactoryClass : beanFactories)
  | @@ -157,7 +161,10 @@
  |  
  |                 List<BeanMetaData> bfBeans = gbfmd.getBeans();
  |                 for (BeanMetaData bfb : bfBeans)
  | +               {
  |                    KernelDeploymentDeployer.addBeanComponent(unit, bfb);
  | +                  beanNames.add(name);
  | +               }
  |              }
  |              else
  |              {
  | @@ -165,10 +172,22 @@
  |                 log.info("BeanMetaData with such name already exists: " + bmd + ", scanned: " + beanFactoryClass);
  |              }
  |           }
  | +
  | +         if (beanNames != null && beanNames.isEmpty() == false)
  | +            unit.addAttachment(getClass() + ".Beans", beanNames);
  |        }
  |     }
  |  
  | -   // TODO - undeploy!!
  | +   public void undeploy(DeploymentUnit unit, AnnotationEnvironment deployment)
  | +   {
  | +      @SuppressWarnings("unchecked")
  | +      Set<String> beanNames = unit.getAttachment(getClass() + ".Beans", Set.class);
  | +      if (beanNames != null)
  | +      {
  | +         for(String name : beanNames)
  | +            unit.removeComponent(name);
  | +      }
  | +   }
  | 
Can we consider this legit? :-)


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

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



More information about the jboss-dev-forums mailing list