Skip to content

Commit

Permalink
Merge behaviour into annotated*
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@297 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Nov 13, 2008
1 parent 201172e commit 821e8e2
Show file tree
Hide file tree
Showing 59 changed files with 775 additions and 1,130 deletions.
62 changes: 35 additions & 27 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
@@ -1,7 +1,6 @@
package org.jboss.webbeans;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -12,9 +11,11 @@
import java.util.concurrent.CopyOnWriteArrayList;

import javax.webbeans.AmbiguousDependencyException;
import javax.webbeans.BindingType;
import javax.webbeans.ContextNotActiveException;
import javax.webbeans.Dependent;
import javax.webbeans.DeploymentException;
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Observer;
import javax.webbeans.Production;
import javax.webbeans.Standard;
Expand All @@ -29,7 +30,6 @@
import javax.webbeans.manager.Manager;

import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bean.proxy.ClientProxy;
import org.jboss.webbeans.bean.proxy.ProxyPool;
import org.jboss.webbeans.contexts.ApplicationContext;
import org.jboss.webbeans.contexts.DependentContext;
Expand All @@ -38,9 +38,9 @@
import org.jboss.webbeans.ejb.DefaultEnterpriseBeanLookup;
import org.jboss.webbeans.event.EventBus;
import org.jboss.webbeans.exceptions.NameResolutionLocation;
import org.jboss.webbeans.exceptions.TypesafeResolutionLocation;
import org.jboss.webbeans.introspector.impl.Injectable;
import org.jboss.webbeans.introspector.impl.ResolverInjectable;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
import org.jboss.webbeans.util.Reflections;

import com.google.common.collect.ForwardingMap;
Expand Down Expand Up @@ -74,6 +74,8 @@ protected Map<Class<? extends Annotation>, List<Context>> delegate()
return delegate;
}
}



private List<Class<? extends Annotation>> enabledDeploymentTypes;
private ModelManager modelManager;
Expand Down Expand Up @@ -152,9 +154,9 @@ public <T> void removeObserver(Observer<T> observer)

}

public <T> Set<Method> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
public <T> Set<AnnotatedMethod<Object>> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
{
return new HashSet<Method>();
return new HashSet<AnnotatedMethod<Object>>();
}

public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
Expand All @@ -174,27 +176,33 @@ public ModelManager getModelManager()

public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindingTypes)
{
return resolveByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
return resolveByType(new SimpleAnnotatedClass<T>(type, type, bindingTypes), bindingTypes);
}

public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType, Annotation... bindingTypes)
public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> type, Annotation... bindingTypes)
{
return resolveByType(new ResolverInjectable<T>(apiType, bindingTypes, getModelManager()));
return resolveByType(new SimpleAnnotatedClass<T>(type.getRawType(), type.getType(), bindingTypes), bindingTypes);
}

private <T> Set<Bean<T>> resolveByType(Injectable<T, ?> injectable)
public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, Annotation... bindingTypes)
{
Set<Bean<T>> beans = getResolutionManager().get(injectable);

if (beans == null)
checkBindingAnnotations(element, bindingTypes);
return getResolutionManager().get(element);
}

private void checkBindingAnnotations(AnnotatedItem<?, ?> element, Annotation... bindingTypes)
{
for (Annotation annotation : element.getAnnotations())
{
return new HashSet<Bean<T>>();
if (!modelManager.getBindingTypeModel(annotation.annotationType()).isValid())
{
throw new IllegalArgumentException("Not a binding type " + annotation);
}
}
else
if (bindingTypes.length > element.getAnnotations(BindingType.class).size())
{
return beans;
throw new DuplicateBindingTypeException(element.toString());
}

}

public ResolutionManager getResolutionManager()
Expand Down Expand Up @@ -337,31 +345,31 @@ else if (beans.size() > 1)

public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
{
return getInstanceByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
return getInstanceByType(new SimpleAnnotatedClass<T>(type, type, bindingTypes), bindingTypes);
}

public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
{
return getInstanceByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
return getInstanceByType(new SimpleAnnotatedClass<T>(type.getRawType(), type.getType(), bindingTypes), bindingTypes);
}

private <T> T getInstanceByType(Injectable<T, ?> injectable)
public <T> T getInstanceByType(AnnotatedItem<T, ?> element, Annotation... bindingTypes)
{
Set<Bean<T>> beans = resolveByType(injectable);
Set<Bean<T>> beans = resolveByType(element, bindingTypes);
if (beans.size() == 0)
{
throw new UnsatisfiedDependencyException(new TypesafeResolutionLocation(injectable) + "Unable to resolve any Web Beans");
throw new UnsatisfiedDependencyException(element + "Unable to resolve any Web Beans");
}
else if (beans.size() > 1)
{
throw new AmbiguousDependencyException(new TypesafeResolutionLocation(injectable) + "Resolved multiple Web Beans");
throw new AmbiguousDependencyException(element + "Resolved multiple Web Beans");
}
else
{
Bean<T> bean = beans.iterator().next();
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal() && !ClientProxy.isProxyable(injectable.getType()))
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal() && !element.isProxyable())
{
throw new UnproxyableDependencyException(new TypesafeResolutionLocation(injectable) + "Unable to proxy");
throw new UnproxyableDependencyException(element + "Unable to proxy");
}
else
{
Expand Down
38 changes: 37 additions & 1 deletion webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java
Expand Up @@ -4,6 +4,8 @@
import java.util.HashMap;
import java.util.Map;

import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.model.AnnotationModel;
import org.jboss.webbeans.model.BindingTypeModel;
import org.jboss.webbeans.model.ScopeModel;
Expand Down Expand Up @@ -82,12 +84,43 @@ protected <S extends Annotation> BindingTypeModel<?> createAnnotationModel(Class

}

private class EjbMetaDataMap extends ForwardingMap<AnnotatedClass<?>, EjbMetaData<?>>
{

private Map<AnnotatedClass<?>, EjbMetaData<?>> delegate;

public EjbMetaDataMap()
{
delegate = new HashMap<AnnotatedClass<?>, EjbMetaData<?>>();
}

@Override
protected Map<AnnotatedClass<?>, EjbMetaData<?>> delegate()
{
return delegate;
}

public <T> EjbMetaData<T> putIfAbsent(AnnotatedClass<T> key)
{
if (!containsKey(key))
{
EjbMetaData<T> ejbMetaData = new EjbMetaData<T>(key);
super.put(key, ejbMetaData);
return ejbMetaData;
}
return (EjbMetaData<T>) super.get(key);
}

}

private Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();

private ScopeModelMap scopes = new ScopeModelMap();

private BindingTypeModelMap bindingTypes = new BindingTypeModelMap();

private EjbMetaDataMap ejbMetaDataMap = new EjbMetaDataMap();


public void addStereotype(StereotypeModel<?> stereotype)
{
Expand All @@ -109,6 +142,9 @@ public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(Class<T> b
return bindingTypes.putIfAbsent(bindingType);
}


public <E> EjbMetaData<E> getEjbMetaData(AnnotatedClass<E> clazz)
{
return ejbMetaDataMap.putIfAbsent(clazz);
}

}

0 comments on commit 821e8e2

Please sign in to comment.