Skip to content

Commit

Permalink
One more :-)
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1188 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 23, 2009
1 parent 5e78e04 commit 1eb5b88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
20 changes: 19 additions & 1 deletion webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -25,6 +25,7 @@
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -118,6 +119,8 @@ public class ManagerImpl implements Manager, Serializable

// The Naming (JNDI) access
private transient final NamingContext namingContext;

private final Map<Bean<?>, Bean<?>> specializedBeans;

/**
* Create a new manager
Expand All @@ -139,6 +142,7 @@ public ManagerImpl(NamingContext namingContext, EjbResolver ejbResolver, Resourc
this.eventManager = new EventManager();
this.ejbDescriptorCache = new EjbDescriptorCache();
this.injectionPointProvider = new InjectionPointProvider();
this.specializedBeans = new HashMap<Bean<?>, Bean<?>>();

List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
defaultEnabledDeploymentTypes.add(0, Standard.class);
Expand Down Expand Up @@ -523,7 +527,11 @@ public Context getBuiltInContext(Class<? extends Annotation> scopeType)
*/
public <T> T getInstance(Bean<T> bean)
{
if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
if (specializedBeans.containsKey(bean))
{
return getInstance((Bean<T>) specializedBeans.get(bean));
}
else if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
{
return (T) proxyPool.getClientProxy(bean, true);
}
Expand Down Expand Up @@ -784,6 +792,16 @@ public InjectionPointProvider getInjectionPointProvider()
{
return injectionPointProvider;
}

/**
*
* @return
*/
public Map<Bean<?>, Bean<?>> getSpecializedBeans()
{
// TODO make this unmodifiable after deploy!
return specializedBeans;
}

// Serialization

Expand Down
Expand Up @@ -132,7 +132,7 @@ protected void init()
{
preCheckSpecialization();
initSpecialization();
postCheckSpecialization();
postSpecialization();
}
initType();
initPrimitive();
Expand Down Expand Up @@ -324,12 +324,15 @@ protected void checkRequiredTypesImplemented()
}
}

protected void postCheckSpecialization()
protected void postSpecialization()
{
if (getAnnotatedItem().isAnnotationPresent(Named.class) && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
{
throw new DefinitionException("Cannot put name on specializing and specialized class");
}
// register the specialized bean
// TODO not sure this quite right
manager.getSpecializedBeans().put(getSpecializedBean(), this);
}

protected void preCheckSpecialization()
Expand Down Expand Up @@ -570,4 +573,14 @@ public boolean equals(Object other)
return false;
}
}

@Override
public int hashCode()
{
int result = 17;
result = 31 * result + getTypes().hashCode();
result = 31 * result + getBindings().hashCode();
return result;
}

}

0 comments on commit 1eb5b88

Please sign in to comment.