Skip to content

Commit

Permalink
get rid of some usages of the static
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@424 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
Gavin King authored and gavin.king@gmail.com committed Dec 6, 2008
1 parent 1daabb5 commit 58a6bbe
Show file tree
Hide file tree
Showing 43 changed files with 190 additions and 194 deletions.
14 changes: 7 additions & 7 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -75,11 +75,11 @@ public class ManagerImpl implements Manager
{
public static final String JNDI_KEY = "java:comp/Manager";

protected static ManagerImpl instance = new ManagerImpl();
protected static ManagerImpl rootManager = new ManagerImpl();

public static ManagerImpl instance()
public static ManagerImpl rootManager()
{
return instance;
return rootManager;
}

private List<Class<? extends Annotation>> enabledDeploymentTypes;
Expand All @@ -97,8 +97,8 @@ public ManagerImpl()
{
this.metaDataCache = new MetaDataCache();
this.beans = new CopyOnWriteArrayList<Bean<?>>();
this.eventManager = new EventManager();
this.resolver = new Resolver();
this.eventManager = new EventManager(this);
this.resolver = new Resolver(this);
this.proxyPool = new ProxyPool();
this.decorators = new HashSet<Decorator>();
this.interceptors = new HashSet<Interceptor>();
Expand All @@ -112,7 +112,7 @@ public ManagerImpl()
*/
protected void initStandardBeans()
{
addBean(new SimpleBean<DefaultEnterpriseBeanLookup>(DefaultEnterpriseBeanLookup.class));
addBean(new SimpleBean<DefaultEnterpriseBeanLookup>(DefaultEnterpriseBeanLookup.class, this));
}

/**
Expand Down Expand Up @@ -212,7 +212,7 @@ public <T> Set<AnnotatedMethod<Object>> resolveDisposalMethods(Class<T> apiType,
*/
public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
{
return eventManager.getObservers(metaDataCache, event, bindings);
return eventManager.getObservers(event, bindings);
}

/**
Expand Down
22 changes: 13 additions & 9 deletions webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
Expand Up @@ -91,12 +91,15 @@ public String toString()
private Set<AnnotatedItem<?, ?>> injectionPoints;

private ConcurrentCache<String, Set<Bean<?>>> resolvedNames;

private ManagerImpl manager;

public Resolver()
public Resolver(ManagerImpl manager)
{
this.injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
this.resolvedInjectionPoints = new ConcurrentCache<ResolvableAnnotatedItem<?,?>, Set<Bean<?>>>();
this.resolvedNames = new ConcurrentCache<String, Set<Bean<?>>>();
this.manager = manager;
}

/**
Expand All @@ -115,7 +118,7 @@ private <T, S> Set<Bean<T>> registerInjectionPoint(final ResolvableAnnotatedItem

public Set<Bean<T>> call() throws Exception
{
Set<Bean<T>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, ManagerImpl.instance().getBeans(), ManagerImpl.instance().getMetaDataCache()), ManagerImpl.instance().getEnabledDeploymentTypes());
Set<Bean<T>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans()), manager.getEnabledDeploymentTypes());
if (element.getType().isPrimitive())
{
for (Bean<?> bean : beans)
Expand Down Expand Up @@ -186,7 +189,7 @@ public AnnotatedItem<T, S> delegate()
if (element.getType().equals(Object.class))
{
// TODO Fix this cast
beans = new HashSet<Bean<T>>((List) ManagerImpl.instance().getBeans());
beans = new HashSet<Bean<T>>((List) manager.getBeans());
}
else
{
Expand All @@ -207,14 +210,14 @@ public Set<Bean<?>> get(final String name)
public Set<Bean<?>> call() throws Exception
{
Set<Bean<?>> beans = new HashSet<Bean<?>>();
for (Bean<?> bean : ManagerImpl.instance().getBeans())
for (Bean<?> bean : manager.getBeans())
{
if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
{
beans.add(bean);
}
}
return retainHighestPrecedenceBeans((Set) beans, ManagerImpl.instance().getEnabledDeploymentTypes());
return retainHighestPrecedenceBeans((Set) beans, manager.getEnabledDeploymentTypes());
}

});
Expand Down Expand Up @@ -252,24 +255,25 @@ private static <T> Set<Bean<T>> retainHighestPrecedenceBeans(Set<Bean<T>> beans,
}

@SuppressWarnings("unchecked")
private static <T> Set<Bean<T>> getMatchingBeans(AnnotatedItem<T, ?> element, List<Bean<?>> beans, MetaDataCache metaDataCache)
private <T> Set<Bean<T>> getMatchingBeans(AnnotatedItem<T, ?> element, List<Bean<?>> beans)
{
Set<Bean<T>> resolvedBeans = new HashSet<Bean<T>>();
for (Bean<?> bean : beans)
{
if (element.isAssignableFrom(bean.getTypes()) && containsAllBindingBindingTypes(element, bean.getBindingTypes(), metaDataCache))
if (element.isAssignableFrom(bean.getTypes()) && containsAllBindingBindingTypes(element, bean.getBindingTypes()))
{
resolvedBeans.add((Bean<T>) bean);
}
}
return resolvedBeans;
}

private static boolean containsAllBindingBindingTypes(AnnotatedItem<?, ?> element, Set<Annotation> bindingTypes, MetaDataCache metaDataCache)
private boolean containsAllBindingBindingTypes(AnnotatedItem<?, ?> element, Set<Annotation> bindingTypes)
{
MetaDataCache metaDataCache = manager.getMetaDataCache();
for (Annotation bindingType : element.getBindingTypes())
{
BindingTypeModel<?> bindingTypeModel = metaDataCache.getBindingTypeModel(bindingType.annotationType());
BindingTypeModel<?> bindingTypeModel = metaDataCache.getBindingTypeModel(bindingType.annotationType());
if (bindingTypeModel.getNonBindingTypes().size() > 0)
{
boolean matchFound = false;
Expand Down
Expand Up @@ -101,24 +101,27 @@ public static Class<? extends Annotation> getDeploymentType(List<Class<? extends
protected Set<AnnotatedItem<?, ?>> injectionPoints;

private boolean primitive;

protected ManagerImpl manager;

// Cached values
private Type declaredBeanType;

/**
* Constructor
*/
public AbstractBean()
public AbstractBean(ManagerImpl manager)
{
super(ManagerImpl.instance());
super(manager);
this.manager = manager;
}

/**
* Initializes the bean and its metadata
*/
protected void init()
{
mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class));
mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class), manager.getMetaDataCache());
initType();
initPrimitive();
log.debug("Building Web Bean bean metadata for " + getType());
Expand Down Expand Up @@ -221,7 +224,7 @@ protected void initDeploymentType()

if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
{
this.deploymentType = getDeploymentType(ManagerImpl.instance().getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
log.trace("Deployment type " + deploymentType + " specified by stereotype");
return;
}
Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.webbeans.Observes;
import javax.webbeans.Produces;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
Expand Down Expand Up @@ -60,9 +61,9 @@ public abstract class AbstractClassBean<T> extends AbstractBean<T, Class<T>>
* @param annotatedItem Annotations read from java classes
* @param xmlAnnotatedItem Annotations read from XML
*/
public AbstractClassBean(Class<T> type)
public AbstractClassBean(Class<T> type, ManagerImpl manager)
{
super();
super(manager);
this.annotatedItem = new AnnotatedClassImpl<T>(type);
}

Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.webbeans.Produces;
import javax.webbeans.Specializes;
import javax.webbeans.manager.EnterpriseBeanLookup;
import javax.webbeans.manager.Manager;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.ejb.EJB;
Expand Down Expand Up @@ -57,9 +58,9 @@ public class EnterpriseBean<T> extends AbstractClassBean<T>
*
* @param type The type of the bean
*/
public EnterpriseBean(Class<T> type)
public EnterpriseBean(Class<T> type, ManagerImpl manager)
{
super(type);
super(type, manager);
init();
}

Expand All @@ -70,7 +71,7 @@ public EnterpriseBean(Class<T> type)
protected void init()
{
super.init();
ejbMetaData = ManagerImpl.instance().getMetaDataCache().getEjbMetaData(getType());
ejbMetaData = manager.getMetaDataCache().getEjbMetaData(getType());
initRemoveMethod();
initInjectionPoints();
checkEnterpriseBeanTypeAllowed();
Expand Down Expand Up @@ -138,14 +139,14 @@ private void checkSpecialization()
}
if (!isDefinedInXml())
{
if (!ManagerImpl.instance().getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
if (!manager.getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
}
else
{
if (ManagerImpl.instance().getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
if (manager.getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
throw new DefinitionException("XML defined specializing EJB must have annotation defined EJB implementation");
}
Expand Down Expand Up @@ -224,11 +225,11 @@ else if (removeMethod.getAnnotatedParameters(Observes.class).size() > 0)
@Override
public T create()
{
T instance = (T) ManagerImpl.instance().getInstanceByType(EnterpriseBeanLookup.class).lookup(ejbMetaData.getEjbName());
T instance = (T) manager.getInstanceByType(EnterpriseBeanLookup.class).lookup(ejbMetaData.getEjbName());
bindDecorators();
bindInterceptors();
injectEjbAndCommonFields();
injectBoundFields(instance);
injectBoundFields(manager, instance);
callInitializers(instance);
return instance;
}
Expand All @@ -253,7 +254,7 @@ protected void callInitializers(T instance)
{
for (AnnotatedMethod<Object> initializer : getInitializerMethods())
{
initializer.invoke(instance);
initializer.invoke(manager, instance);
}
}

Expand All @@ -270,11 +271,11 @@ protected void injectEjbAndCommonFields()
*
* @param instance The bean instance
*/
protected void injectBoundFields(T instance)
protected void injectBoundFields(Manager manager, T instance)
{
for (AnnotatedField<?> field : getInjectableFields())
{
field.inject(instance);
field.inject(manager, instance);
}
}

Expand Down Expand Up @@ -306,7 +307,7 @@ protected AbstractBean<? extends T, Class<T>> getSpecializedType()
if (superclass != null)
{
// TODO look up this bean and do this via init
return new EnterpriseBean(superclass);
return new EnterpriseBean(superclass, manager);
}
else
{
Expand Down
45 changes: 4 additions & 41 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
Expand Up @@ -25,11 +25,10 @@
import javax.webbeans.Event;
import javax.webbeans.Standard;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.event.EventImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;

/**
* An event bean representation
Expand All @@ -41,10 +40,6 @@
public class EventBean<T> extends AbstractBean<Event<T>, Field>
{

private static LogProvider log = Logging.getLogProvider(EventBean.class);

// The debug location
private String location;
// The underlying annotated item
private AnnotatedField<Event<T>> annotatedItem;

Expand All @@ -54,9 +49,9 @@ public class EventBean<T> extends AbstractBean<Event<T>, Field>
* @param field The underlying field abstraction
*/
@SuppressWarnings("unchecked")
public EventBean(AnnotatedField<T> field)
public EventBean(AnnotatedField<T> field, ManagerImpl manager)
{
super();
super(manager);
this.annotatedItem = (AnnotatedField<Event<T>>) field;
init();
}
Expand Down Expand Up @@ -88,45 +83,30 @@ private void checkAnnotatedItem()
}
}

/**
* @see org.jboss.webbeans.bean.AbstractBean#initScopeType()
*/
@Override
protected void initScopeType()
{
this.scopeType = Dependent.class;
}

/**
* @see org.jboss.webbeans.bean.AbstractBean#initDeploymentType()
*/
@Override
protected void initDeploymentType()
{
this.deploymentType = Standard.class;
}

/**
* @see org.jboss.webbeans.bean.AbstractBean#getAnnotatedItem()
*/
@Override
protected AnnotatedItem<Event<T>, Field> getAnnotatedItem()
{
return annotatedItem;
}

/**
* @see org.jboss.webbeans.bean.AbstractBean#getDefaultName()
*/
@Override
protected String getDefaultName()
{
return null;
}

/**
* @see org.jboss.webbeans.bean.AbstractBean#initType()
*/
@Override
protected void initType()
{
Expand All @@ -144,29 +124,12 @@ protected void initType()
}
}

/**
* Gets the debug location
*
* @return A string describing the location
*/
private String getLocation()
{
if (location == null)
{
location = "type: Event Bean;";
}
return location;
}

/**
* @see javax.webbeans.manager.Bean#create()
*/
@SuppressWarnings("unchecked")
@Override
public Event<T> create()
{
Class<T> eventType = (Class<T>) annotatedItem.getType().getTypeParameters()[0].getClass();
return new EventImpl<T>(eventType, annotatedItem.getBindingTypesAsArray());
return new EventImpl<T>(manager, eventType, annotatedItem.getBindingTypesAsArray());
}

}

0 comments on commit 58a6bbe

Please sign in to comment.