Skip to content

Commit

Permalink
Start to fix injection tests
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@200 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Oct 28, 2008
1 parent 46bbe0f commit 1ec3f19
Show file tree
Hide file tree
Showing 26 changed files with 399 additions and 210 deletions.
46 changes: 25 additions & 21 deletions webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java
Expand Up @@ -7,25 +7,32 @@

import org.jboss.webbeans.model.bean.BeanModel;

public class BeanImpl<T> extends Bean<T>
public abstract class BeanImpl<T> extends Bean<T>
{

public static final String LOGGER_NAME = "bean";

private BeanModel<T, ?> beanModel;

private ManagerImpl manager;
protected ManagerImpl manager;

public BeanImpl(BeanModel<T, ?> model, ManagerImpl manager)
public BeanImpl(ManagerImpl manager)
{
super(manager);
this.beanModel = model;
this.manager = manager;
}

@Override
public T create()

protected T getInstance()
{
return getModel().getConstructor().invoke(manager);
}

protected void bindInterceptors()
{
// TODO
}

protected void bindDecorators()
{
return beanModel.getConstructor().invoke(manager);
// TODO
}

@Override
Expand All @@ -38,37 +45,37 @@ public void destroy(T instance)
@Override
public Set<Annotation> getBindingTypes()
{
return beanModel.getBindingTypes();
return getModel().getBindingTypes();
}

@Override
public Class<? extends Annotation> getDeploymentType()
{
return beanModel.getDeploymentType();
return getModel().getDeploymentType();
}

@Override
public String getName()
{
return beanModel.getName();
return getModel().getName();
}

@Override
public Class<? extends Annotation> getScopeType()
{
return beanModel.getScopeType();
return getModel().getScopeType();
}

@Override
public Set<Class<?>> getTypes()
{
return beanModel.getApiTypes();
return getModel().getApiTypes();
}

@Override
public boolean isNullable()
{
return !beanModel.isPrimitive();
return !getModel().isPrimitive();
}

@Override
Expand All @@ -81,12 +88,9 @@ public boolean isSerializable()
@Override
public String toString()
{
return beanModel.toString();
return getModel().toString();
}

public BeanModel<T, ?> getModel()
{
return beanModel;
}
public abstract BeanModel<T, ?> getModel();

}
47 changes: 40 additions & 7 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -24,6 +24,10 @@
import javax.webbeans.manager.Interceptor;
import javax.webbeans.manager.Manager;

import org.jboss.webbeans.contexts.ApplicationContext;
import org.jboss.webbeans.contexts.DependentContext;
import org.jboss.webbeans.contexts.RequestContext;
import org.jboss.webbeans.contexts.SessionContext;
import org.jboss.webbeans.ejb.EjbManager;
import org.jboss.webbeans.event.EventBus;
import org.jboss.webbeans.exceptions.NameResolutionLocation;
Expand Down Expand Up @@ -57,14 +61,14 @@ public List<Context> get(Class<? extends Annotation> key)
private EventBus eventBus;
private ResolutionManager resolutionManager;
private ContextMap contextMap;
private DependentContext dependentContext;

private Set<Bean<?>> beans;

public ManagerImpl()
{
contextMap = new ContextMap();
// TODO Are there any contexts that should be initialized here?
initEnabledDeploymentTypes(null);
initContexts(null);
this.modelManager = new ModelManager();
this.ejbLookupManager = new EjbManager();
this.beans = new HashSet<Bean<?>>();
Expand All @@ -89,6 +93,27 @@ protected void initEnabledDeploymentTypes(List<Class<? extends Annotation>> enab
}
}
}

protected void initContexts(Context ... contexts)
{
this.contextMap = new ContextMap();
if (contexts == null)
{

this.dependentContext = new DependentContext();
addContext(dependentContext);
addContext(new RequestContext());
addContext(new SessionContext());
addContext(new ApplicationContext());
}
else
{
for (Context context : contexts)
{
addContext(context);
}
}
}

public Manager addBean(Bean<?> bean)
{
Expand Down Expand Up @@ -242,14 +267,22 @@ public Context getContext(Class<? extends Annotation> scopeType)

public <T> T getInstance(Bean<T> bean)
{
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
try
{
// TODO return a client proxy
return null;
dependentContext.setActive(true);
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
{
// TODO return a client proxy
return getContext(bean.getScopeType()).get(bean, true);
}
else
{
return getContext(bean.getScopeType()).get(bean, true);
}
}
else
finally
{
return getContext(bean.getScopeType()).get(bean, true);
dependentContext.setActive(false);
}
}

Expand Down
47 changes: 47 additions & 0 deletions webbeans-ri/src/main/java/org/jboss/webbeans/SimpleBeanImpl.java
@@ -0,0 +1,47 @@
package org.jboss.webbeans;

import org.jboss.webbeans.injectable.InjectableField;
import org.jboss.webbeans.model.bean.SimpleBeanModel;

public class SimpleBeanImpl<T> extends BeanImpl<T>
{

private SimpleBeanModel<T> model;

public SimpleBeanImpl(SimpleBeanModel<T> model, ManagerImpl manager)
{
super(manager);
this.model = model;
}

@Override
public T create()
{
T instance = getInstance();
bindDecorators();
bindInterceptors();
injectEjbAndCommonFields();
injectBoundFields(instance);
return instance;
}

protected void injectEjbAndCommonFields()
{
// TODO
}

protected void injectBoundFields(T instance)
{
for (InjectableField<?> injectableField : getModel().getInjectableFields())
{
injectableField.inject(instance, manager);
}
}

@Override
public SimpleBeanModel<T> getModel()
{
return model;
}

}
Expand Up @@ -2,7 +2,10 @@

import java.lang.reflect.Field;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.SimpleAnnotatedField;
import org.jboss.webbeans.util.Reflections;

/**
* Abstraction of Java Reflection
Expand All @@ -17,5 +20,15 @@ public InjectableField(Field field)
{
super(new SimpleAnnotatedField<T>(field));
}

public InjectableField(AnnotatedField<T> annotatedField)
{
super(annotatedField);
}

public void inject(Object instance, ManagerImpl manager)
{
Reflections.setAndWrap(getAnnotatedItem().getDelegate(), instance, getValue(manager));
}

}
Expand Up @@ -24,7 +24,7 @@ public interface AnnotatedType<T> extends AnnotatedItem<T, Class<T>>
* Get all fields on the type
* @return
*/
public Set<AnnotatedField<?>> getFields();
public Set<AnnotatedField<Object>> getFields();

/**
* Get all annotations which are annotated with the given annotation
Expand All @@ -33,7 +33,7 @@ public interface AnnotatedType<T> extends AnnotatedItem<T, Class<T>>
* If no annotations are present which are annotated with the given
* annotation an empty set is returned
*/
public Set<AnnotatedField<?>> getAnnotatedField(Class<? extends Annotation> annotationType);
public Set<AnnotatedField<Object>> getAnnotatedField(Class<? extends Annotation> annotationType);

/**
* Get all fields which are annotated with the given meta annotation
Expand All @@ -42,7 +42,7 @@ public interface AnnotatedType<T> extends AnnotatedItem<T, Class<T>>
* If no annotations are present which are annotated with the given meta
* annotation an empty set is returned
*/
public Set<AnnotatedField<?>> getMetaAnnotatedFields(
public Set<AnnotatedField<Object>> getMetaAnnotatedFields(
Class<? extends Annotation> metaAnnotationType);

}
Expand Up @@ -21,9 +21,9 @@ public class SimpleAnnotatedType<T> extends AbstractAnnotatedItem<T, Class<T>> i

private Class<T> clazz;
private Type[] actualTypeArguements;
private Set<AnnotatedField<?>> fields;
private Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> annotatedFields;
private Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> metaAnnotatedFields;
private Set<AnnotatedField<Object>> fields;
private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> annotatedFields;
private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> metaAnnotatedFields;

public SimpleAnnotatedType(Class<T> annotatedClass, Map<Class<? extends Annotation>, Annotation> annotationMap)
{
Expand Down Expand Up @@ -55,7 +55,7 @@ public Class<T> getDelegate()
return clazz;
}

public Set<AnnotatedField<?>> getFields()
public Set<AnnotatedField<Object>> getFields()
{
if (fields == null)
{
Expand All @@ -66,19 +66,19 @@ public Set<AnnotatedField<?>> getFields()

private void initFields()
{
this.fields = new HashSet<AnnotatedField<?>>();
this.fields = new HashSet<AnnotatedField<Object>>();
for(Field field : clazz.getFields())
{
fields.add(new SimpleAnnotatedField<Object>(field));
}
}

public Set<AnnotatedField<?>> getMetaAnnotatedFields(
public Set<AnnotatedField<Object>> getMetaAnnotatedFields(
Class<? extends Annotation> metaAnnotationType)
{
if (metaAnnotatedFields == null)
{
metaAnnotatedFields = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<?>>>();
metaAnnotatedFields = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>();
}
if (annotatedFields == null)
{
Expand All @@ -88,14 +88,14 @@ public Set<AnnotatedField<?>> getMetaAnnotatedFields(
return metaAnnotatedFields.get(metaAnnotationType);
}

protected static <T extends Annotation> Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> populateMetaAnnotatedFieldMap(
protected static <T extends Annotation> Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> populateMetaAnnotatedFieldMap(
Class<T> metaAnnotationType,
Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> annotatedFields,
Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> metaAnnotatedFields)
Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> annotatedFields,
Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> metaAnnotatedFields)
{
if (!metaAnnotatedFields.containsKey(metaAnnotationType))
{
Set<AnnotatedField<?>> s = new HashSet<AnnotatedField<?>>();
Set<AnnotatedField<Object>> s = new HashSet<AnnotatedField<Object>>();
for (Class<? extends Annotation> annotationType: annotatedFields.keySet())
{
if (annotationType.isAnnotationPresent(metaAnnotationType))
Expand All @@ -108,7 +108,7 @@ protected static <T extends Annotation> Map<Class<? extends Annotation>, Set<Ann
return metaAnnotatedFields;
}

public Set<AnnotatedField<?>> getAnnotatedField(
public Set<AnnotatedField<Object>> getAnnotatedField(
Class<? extends Annotation> annotationType)
{
if (annotatedFields == null)
Expand All @@ -124,14 +124,14 @@ private void initAnnotatedFields()
{
initFields();
}
annotatedFields = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<?>>>();
for (AnnotatedField<?> field : fields)
annotatedFields = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>();
for (AnnotatedField<Object> field : fields)
{
for (Annotation annotation : field.getAnnotations())
{
if (!annotatedFields.containsKey(annotation))
{
annotatedFields.put(annotation.annotationType(), new HashSet<AnnotatedField<?>>());
annotatedFields.put(annotation.annotationType(), new HashSet<AnnotatedField<Object>>());
}
annotatedFields.get(annotation.annotationType()).add(field);
}
Expand Down

0 comments on commit 1ec3f19

Please sign in to comment.