Skip to content

Commit

Permalink
Modifications needed for injection point metadata and fixes to tests;…
Browse files Browse the repository at this point in the history
… integration code was thrown out due to conflicting design changes; all tests marked broken.

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@809 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Jan 7, 2009
1 parent 53e54a7 commit aece422
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 9 deletions.
17 changes: 16 additions & 1 deletion webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -56,6 +56,7 @@
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.injection.InjectionPointFactory;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
Expand Down Expand Up @@ -83,8 +84,10 @@ public class ManagerImpl implements Manager, Serializable

// The enabled deployment types from web-beans.xml
private transient List<Class<? extends Annotation>> enabledDeploymentTypes;
// The Web Beans manager
// The Web Beans event manager
private transient final EventManager eventManager;
// An injection point metadata beans factory
InjectionPointFactory injectionPointFactory;

// The bean resolver
private transient final Resolver resolver;
Expand Down Expand Up @@ -132,6 +135,7 @@ public ManagerImpl(Naming naming, EjbResolver ejbResolver, ResourceLoader resour
this.contextMap = new ContextMap();
this.eventManager = new EventManager();
this.ejbDescriptorCache = new EjbDescriptorCache();
this.injectionPointFactory = new InjectionPointFactory();

List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
defaultEnabledDeploymentTypes.add(0, Standard.class);
Expand Down Expand Up @@ -758,4 +762,15 @@ protected Object readResolve()
return CurrentManager.rootManager();
}

/**
* Accesses the factory used to create each instance of InjectionPoint
* that is injected into web beans.
*
* @return the factory
*/
public final InjectionPointFactory getInjectionPointFactory()
{
return injectionPointFactory;
}

}
Expand Up @@ -33,7 +33,6 @@
import javax.webbeans.Observes;
import javax.webbeans.Produces;
import javax.webbeans.Specializes;
import javax.webbeans.manager.Manager;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.context.DependentContext;
Expand Down Expand Up @@ -340,7 +339,7 @@ protected void injectEjbAndCommonFields()
* @param instance The bean instance
* @param manager The Web Beans manager
*/
protected void injectBoundFields(T instance, Manager manager)
protected void injectBoundFields(T instance, ManagerImpl manager)
{
for (AnnotatedField<?> field : getInjectableFields())
{
Expand Down
@@ -0,0 +1,124 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.webbeans.injection;

import java.lang.reflect.Member;
import java.util.Stack;

import javax.webbeans.InjectionPoint;
import javax.webbeans.manager.Bean;

import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedMember;

/**
* Factory used to create the container provided implementation for the
* InjectionPoint beans. This factory maintains a stack with the current bean
* and instance being created so that this information is readily available for
* construction of a new InjectionPoint bean.
*
* @author David Allen
*
*/
public class InjectionPointFactory
{
private final Stack<Bean<?>> beans = new Stack<Bean<?>>();
private final Stack<Object> beanInstances = new Stack<Object>();
private final Stack<AbstractAnnotatedMember<?, ? extends Member>> injectionPoints = new Stack<AbstractAnnotatedMember<?, ? extends Member>>();

/**
* Pushes the current bean that is being instantiated onto a stack for later
* use.
*
* @param currentBean The bean being instantiated
*/
public void pushBean(Bean<?> currentBean)
{
beans.push(currentBean);
}

/**
* 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)
{
beanInstances.push(currentInstance);
}

/**
* Pushes the current injection point being processed.
*
* @param injectedMember The metadata for the injection point
*/
public void pushInjectionPoint(AbstractAnnotatedMember<?, ? extends Member> injectedMember)
{
injectionPoints.push(injectedMember);
}

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

/**
* Pops the current injection point being processed. This should be called once
* the injection point is bound.
*/
public void popInjectionPoint()
{
injectionPoints.pop();
}

/**
* Creates an InjectionPoint based on the current state of processing as
* indicated by this factory's stack of injection points and related
* information.
*
* @return a new injection point metadata object
*/
public InjectionPoint newInstance()
{
// When the injected member is a constructor, we are short one instance,
// so the instance on the top of the stack is the bean instance
// we want. Otherwise, it is the second to last instance same as
// the bean stack.
InjectionPoint injectionPoint = null;
Bean<?> currentBean = beans.pop();
AbstractAnnotatedMember<?, ? extends Member> currentInjection = injectionPoints.pop();
if (beanInstances.size() < beans.size())
{
injectionPoint = new InjectionPointImpl(injectionPoints.peek(), beans.peek(), beanInstances.peek());
}
else
{
Object currentInstance = beanInstances.pop();
injectionPoint = new InjectionPointImpl(injectionPoints.peek(), beans.peek(), beanInstances.peek());
beanInstances.push(currentInstance);
}
beans.push(currentBean);
injectionPoints.push(currentInjection);
return injectionPoint;
}
}
Expand Up @@ -35,6 +35,7 @@
import org.jboss.webbeans.test.beans.BeanWithInjectionPointMetadata;
import org.jboss.webbeans.test.beans.ConstructorInjectionPointBean;
import org.jboss.webbeans.test.beans.FieldInjectionPointBean;
import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
import org.testng.annotations.Test;

Expand All @@ -61,6 +62,7 @@ public void testGetInstance()
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
assert beanWithInjectionPoint.getInjectedMetadata() != null;
//TODO Fix injection issue where raw bean is used instead of proxied bean
assert beanWithInjectionPoint.getInjectedMetadata().getInstance().equals(beanWithInjectedBean);
}
finally
Expand All @@ -84,8 +86,9 @@ public void testGetBean()
BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
assert beanWithInjectionPoint.getInjectedMetadata() != null;

Set<Bean<FieldInjectionPointBean>> theBean = manager.resolveByType(FieldInjectionPointBean.class);
assert beanWithInjectionPoint.getInjectedMetadata().getBean().equals(theBean);
Set<Bean<FieldInjectionPointBean>> resolvedBeans = manager.resolveByType(FieldInjectionPointBean.class);
assert resolvedBeans.size() == 1;
assert beanWithInjectionPoint.getInjectedMetadata().getBean().equals(resolvedBeans.iterator().next());
}
finally
{
Expand All @@ -107,7 +110,7 @@ public void testGetType()
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
assert beanWithInjectionPoint.getInjectedMetadata() != null;
assert beanWithInjectionPoint.getInjectedMetadata().getType().equals(FieldInjectionPointBean.class);
assert beanWithInjectionPoint.getInjectedMetadata().getType().equals(BeanWithInjectionPointMetadata.class);
}
finally
{
Expand Down Expand Up @@ -228,8 +231,8 @@ public void testGetAnnotations()
assert beanWithInjectionPoint.getInjectedMetadata() != null;
Set<Annotation> annotations = new HashSet<Annotation>(Arrays.asList(beanWithInjectionPoint.getInjectedMetadata().getAnnotations()));
assert annotations.size() > 0;
assert annotations.contains(Current.class);
assert annotations.contains(AnimalStereotype.class);
assert annotations.contains(new CurrentBinding());
assert annotations.contains(new AnimalStereotypeAnnotationLiteral());
}
finally
{
Expand Down Expand Up @@ -295,7 +298,7 @@ public void testApiTypeInjectionPoint()
FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
assert beanWithInjectionPoint.getInjectedMetadata() != null;
assert beanWithInjectionPoint.getInjectedMetadata().getBean().getTypes().contains(InjectionPoint.class);
assert InjectionPoint.class.isAssignableFrom(beanWithInjectionPoint.getInjectedMetadata().getClass());
}
finally
{
Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.jboss.webbeans.test.beans;

import javax.webbeans.Current;
import javax.webbeans.RequestScoped;

import org.jboss.webbeans.test.annotations.AnimalStereotype;

Expand All @@ -28,6 +29,7 @@
* @author David Allen
*
*/
@RequestScoped
public class FieldInjectionPointBean
{
@Current @AnimalStereotype
Expand Down

0 comments on commit aece422

Please sign in to comment.