[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: ClassLoader injection Scope issue
alesj
do-not-reply at jboss.com
Tue Oct 28 12:18:36 EDT 2008
"adrian at jboss.org" wrote :
| Those sound overly complicated.
| The simplest fix would be in the component visitor, something like:
|
|
| | protected static void addBeanComponent(DeploymentUnit unit, BeanMetaData bean)
| | {
| | DeploymentUnit component = unit.addComponent(bean.getName());
| | component.addAttachment(BeanMetaData.class.getName(), bean);
| | + String className = bean.getBean();
| | + if (className != null)
| | + component.getScope().addScope(CommonLevels.CLASS, className);
| | }
| |
This is the code
+
| + unit.addAttachment(ScopeBuilder.class, BeanMetaDataScopeBuilder.INSTANCE);
| +
| KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
| ScopeInfo scopeInfo = context.getScopeInfo();
| - if (scopeInfo != null)
| - {
| - mergeScopes(scopeInfo.getScope(), unit.getScope());
| - mergeScopes(scopeInfo.getMutableScope(), unit.getMutableScope());
| - }
| + scopeInfo.setScope(unit.getScope());
| + scopeInfo.setMutableScope(unit.getMutableScope());
| try
| {
| controller.install(context);
| @@ -190,4 +194,18 @@
| return new AbstractValueMetaData(unit.getClassLoader());
| }
| }
| +
| + private static class BeanMetaDataScopeBuilder extends DefaultScopeBuilder
| + {
| + private static final ScopeBuilder INSTANCE = new BeanMetaDataScopeBuilder();
| +
| + public ScopeKey getComponentScope(DeploymentContext context)
| + {
| + BeanMetaData bmd = context.getDeploymentUnit().getAttachment(BeanMetaData.class);
| + ScopeKey scopeKey = super.getComponentScope(context);
| + if (bmd != null && bmd.getBean() != null)
| + scopeKey.addScope(CommonLevels.CLASS, bmd.getBean());
| + return scopeKey;
| + }
| + }
| }
But you're right, yours looks easier. :-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4185153#4185153
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4185153
More information about the jboss-dev-forums
mailing list