Skip to content

Commit

Permalink
ditch getInstance()
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@894 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
Gavin King authored and gavin.king@gmail.com committed Jan 12, 2009
1 parent ecc168a commit d794ca0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 84 deletions.
Expand Up @@ -422,7 +422,6 @@ public void postConstruct(T instance)
try
{
manager.getInjectionPointFactory().pushBean(this);
manager.getInjectionPointFactory().pushInstance(this);
DependentContext.INSTANCE.setActive(true);
bindDecorators();
bindInterceptors();
Expand All @@ -432,7 +431,6 @@ public void postConstruct(T instance)
}
finally
{
manager.getInjectionPointFactory().popInstance();
manager.getInjectionPointFactory().popBean();
DependentContext.INSTANCE.setActive(false);
}
Expand Down
30 changes: 11 additions & 19 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
Expand Up @@ -122,20 +122,12 @@ public T create()
try
{
instance = constructor.newInstance(manager);
try
{
injectionPointProvider.pushInstance(instance);
bindDecorators();
bindInterceptors();
injectEjbAndCommonFields(instance);
injectBoundFields(instance);
callInitializers(instance);
callPostConstruct(instance);
}
finally
{
injectionPointProvider.popInstance();
}
bindDecorators();
bindInterceptors();
injectEjbAndCommonFields(instance);
injectBoundFields(instance);
callInitializers(instance);
callPostConstruct(instance);
}
finally
{
Expand Down Expand Up @@ -236,14 +228,14 @@ protected void injectEjbAndCommonFields(T beanInstance)
{
for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getEJBAnnotation()))
{
InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
InjectionPoint injectionPoint = new InjectionPointImpl(field, this);
Object ejbInstance = manager.getEjbResolver().resolveEjb(injectionPoint, manager.getNaming());
field.inject(beanInstance, ejbInstance);
}

for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getEjbResolver().getEJBAnnotation()))
{
InjectionPoint injectionPoint = new InjectionPointImpl(method, this, beanInstance);
InjectionPoint injectionPoint = new InjectionPointImpl(method, this);
Object ejbInstance = manager.getEjbResolver().resolveEjb(injectionPoint, manager.getNaming());
method.invoke(beanInstance, ejbInstance);
}
Expand All @@ -254,21 +246,21 @@ protected void injectEjbAndCommonFields(T beanInstance)
{
throw new ExecutionException("Cannot inject an extended persistence context into " + field);
}
InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
InjectionPoint injectionPoint = new InjectionPointImpl(field, this);
Object puInstance = manager.getEjbResolver().resolvePersistenceContext(injectionPoint, manager.getNaming());
field.inject(beanInstance, puInstance);
}

for (AnnotatedMethod<?> method : annotatedItem.getAnnotatedMethods(manager.getEjbResolver().getPersistenceContextAnnotation()))
{
InjectionPoint injectionPoint = new InjectionPointImpl(method, this, beanInstance);
InjectionPoint injectionPoint = new InjectionPointImpl(method, this);
Object puInstance = manager.getEjbResolver().resolvePersistenceContext(injectionPoint, manager.getNaming());
method.invoke(beanInstance, puInstance);
}

for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getResourceAnnotation()))
{
InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
InjectionPoint injectionPoint = new InjectionPointImpl(field, this);
Object resourceInstance = manager.getEjbResolver().resolveResource(injectionPoint, manager.getNaming());
field.inject(beanInstance, resourceInstance);
}
Expand Down
Expand Up @@ -37,7 +37,6 @@
public class InjectionPointProvider
{
private final Stack<Bean<?>> beans = new Stack<Bean<?>>();
private final Stack<Object> beanInstances = new Stack<Object>();
private final Stack<AnnotatedMember<?, ? extends Member>> injectionPoints = new Stack<AnnotatedMember<?, ? extends Member>>();

/**
Expand All @@ -50,28 +49,6 @@ public class InjectionPointProvider
public void pushBean(Bean<?> currentBean)
{
beans.push(currentBean);
beanInstances.push(null);
}

/**
* Pushes the current bean instance that has been instantiated, but has not
* yet had any injection points initialized.
*
* @param currentInstance The bean instance last instantiated
*/
public void pushInstance(Object currentInstance)
{
// Replace the null instance (from pushing the bean) with this one
// on the top of the stack.
if (beanInstances.peek() == null)
{
popInstance();
beanInstances.push(currentInstance);
}
else
{
throw new java.lang.IllegalStateException("More bean instances pushed than there are beans");
}
}

/**
Expand All @@ -90,23 +67,9 @@ public void pushInjectionMember(AnnotatedMember<?, ? extends Member> injectedMem
*/
public void popBean()
{
if (!beanInstances.isEmpty() && beanInstances.size() == beans.size() && beanInstances.peek() == null)
{
// Pop the null instance since a real one was never pushed.
popInstance();
}
beans.pop();
}

/**
* Pops the current instance from the stack. This should be called whenever
* all processing is complete for instantiating a bean.
*/
public void popInstance()
{
beanInstances.pop();
}

/**
* Pops the current injection point being processed. This should be called
* once the injection point is bound.
Expand All @@ -124,7 +87,7 @@ public void popInjectionMember()
*/
public InjectionPoint getPreviousInjectionPoint()
{
return new InjectionPointImpl(getPreviousInjectionMember(), getPreviousBean(), getPreviousInstance());
return new InjectionPointImpl(getPreviousInjectionMember(), getPreviousBean());
}

/**
Expand All @@ -135,19 +98,13 @@ public InjectionPoint getPreviousInjectionPoint()
*/
public InjectionPoint getCurrentInjectionPoint()
{
return new InjectionPointImpl(getCurrentInjectionMember(), getCurrentBean(), getCurrentInstance());
return new InjectionPointImpl(getCurrentInjectionMember(), getCurrentBean());
}

protected Bean<?> getCurrentBean()
{
return beans.peek();
}

protected Object getCurrentInstance()
{
return beanInstances.peek();
}

protected AnnotatedMember<?, ? extends Member> getCurrentInjectionMember()
{
if (injectionPoints.size() > 0)
Expand All @@ -164,24 +121,6 @@ protected Bean<?> getPreviousBean()
return result;
}

protected Object getPreviousInstance()
{
Object result = null;
if (beanInstances.size() < beans.size())
{
// Return top of stack since this is the previous instance when a
// constructor is being invoked with injection points
result = beanInstances.peek();
}
else
{
Object currentInstance = beanInstances.pop();
result = beanInstances.peek();
beanInstances.push(currentInstance);
}
return result;
}

protected AnnotatedMember<?, ? extends Member> getPreviousInjectionMember()
{
AnnotatedMember<?, ? extends Member> result = null;
Expand Down

0 comments on commit d794ca0

Please sign in to comment.