[Design the new POJO MicroContainer] - Re: ClassLoader injection Scope issue
by alesj
"adrian(a)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
16 years, 1 month
[Design the new POJO MicroContainer] - Re: ClassLoader injection Scope issue
by adrian@jboss.org
"alesj" wrote : "adrian(a)jboss.org" wrote :
| | So another fix would be to somehow make the Deployer's ScopeBuilder
| | somehow aware of the class scope when it creates the component scope.
| |
| ScopeBuilder per attachment type?
|
| | public static ScopeBuilder getScopeBuilder(DeploymentContext deploymentContext)
| | {
| | if (deploymentContext == null)
| | throw new IllegalArgumentException("Null deployment context");
| | ScopeBuilder builder = deploymentContext.getTransientAttachments().getAttachment(ScopeBuilder.class);
| | if (builder != null)
| | return builder;
| | DeploymentContext parent = deploymentContext.getParent();
| | if (parent != null)
| | return getScopeBuilder(parent);
| | return DefaultScopeBuilder.INSTANCE;
| | }
| |
| Setting BeanMD aware ScopeBuilder?
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);
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4185152#4185152
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4185152
16 years, 1 month
[Design the new POJO MicroContainer] - Re: ClassLoader injection Scope issue
by adrian@jboss.org
"alesj" wrote : "adrian(a)jboss.org" wrote :
| | I guess this is because it doesn't look like DefaultScopeBuilder in the deployers knows
| | anything about classes when creating component scopes?
| | It just adds the INSTANCE level to the DEPLOYMENT/APPLICATION
| Yup, my guess would be we're then missing this
|
| | public AbstractScopeInfo(Object name, String className)
| | {
| | if (name == null)
| | throw new IllegalArgumentException("Null scope");
| |
| | ScopeKey scopeKey = ScopeKey.DEFAULT_SCOPE.clone();
| | scopeKey.addScope(CommonLevels.INSTANCE, name.toString());
| | if (className != null)
| | scopeKey.addScope(CommonLevels.CLASS, className);
| | setScope(scopeKey);
| | setMutableScope(new ScopeKey(CommonLevels.INSTANCE, name.toString()));
| | }
| |
So another fix would be to somehow make the Deployer's ScopeBuilder
somehow aware of the class scope when it creates the component scope.
Then there's no need for any merge.
But there's probably a reason why I didn't do that in the first place
(other than I just forgot - which might actually be the real reason. :-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4185148#4185148
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4185148
16 years, 1 month