Skip to content

Commit

Permalink
Fix most tests, remove @Obtains, fix transformer
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2950 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jul 1, 2009
1 parent 0f4bc83 commit 0bcc231
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 137 deletions.
44 changes: 0 additions & 44 deletions api/src/main/java/javax/inject/Obtains.java

This file was deleted.

115 changes: 100 additions & 15 deletions impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -24,6 +24,7 @@
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -94,6 +95,7 @@
import org.jboss.webbeans.util.Observers;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.collections.Iterators;
import org.jboss.webbeans.util.collections.multi.ConcurrentListHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentListMultiMap;

Expand Down Expand Up @@ -176,30 +178,46 @@ public String toString()
* ***********************************
*/

// Contexts are shared across the application
private transient final ConcurrentListMultiMap<Class<? extends Annotation>, Context> contexts;

// Client proxies can be used application wide
private transient final ClientProxyProvider clientProxyProvider;

// We want to generate unique id's across the whole deployment
private transient final AtomicInteger ids;

// TODO review this structure
private transient final Map<String, RIBean<?>> riBeans;

// TODO review this structure
private transient final Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans;

/*
* Archive scoped services
* ***********************
*/
// TODO This isn't right, specialization should follow accessibility rules, but I think we can enforce these in resolve()
private transient final Map<Contextual<?>, Contextual<?>> specializedBeans;

/*
* Archive scoped data structures
* ******************************
*/

/* These data structures are all non-transitive in terms of bean deployment
* archive accessibility, and the configuration for this bean deployment
* archive
*/
private transient List<Class<? extends Annotation>> enabledDeploymentTypes;
private transient List<Class<?>> enabledDecoratorClasses;
private transient List<Class<?>> enabledInterceptorClasses;
private transient final Set<CurrentActivity> currentActivities;
private transient final Map<Contextual<?>, Contextual<?>> specializedBeans;
private transient final Set<CurrentActivity> currentActivities;

/*
* Activity scoped services
* *************************
*/

/* These services are scoped to this activity only, but use data
* structures that are transitive accessible from other bean deployment
* archives
*/
private transient final TypeSafeResolver<Bean<?>> beanResolver;
private transient final TypeSafeResolver<DecoratorBean<?>> decoratorResolver;
Expand All @@ -212,11 +230,30 @@ public String toString()
* Activity scoped data structures
* ********************************
*/

/* These data structures are scoped to this bean deployment archive activity
* only and represent the beans, decorators, interceptors, namespaces and
* observers deployed in this bean deployment archive activity
*/
private transient final List<Bean<?>> beans;
private transient final List<DecoratorBean<?>> decorators;
private transient final List<String> namespaces;
private transient final List<EventObserver<?>> observers;

/*
* These data structures represent the beans, decorators, interceptors,
* namespaces and observers *accessible* from this bean deployment archive
* activity
*/
private transient final Set<Iterable<Iterable<Bean<?>>>> accessibleBeans;
private transient final Set<Iterable<Iterable<DecoratorBean<?>>>> accessibleDecorators;
private transient final Set<Iterable<Iterable<String>>> accessibleNamespaces;
private transient final Set<Iterable<Iterable<EventObserver<?>>>> accessibleObservers;

/*
* This data structures represents child activities for this activity, it is
* not transitively accessible
*/
private transient final Set<BeanManagerImpl> childActivities;

private final Integer id;
Expand Down Expand Up @@ -299,7 +336,7 @@ private BeanManagerImpl(
ServiceRegistry serviceRegistry,
List<Bean<?>> beans,
List<DecoratorBean<?>> decorators,
List<EventObserver<?>> registeredObservers,
List<EventObserver<?>> observers,
List<String> namespaces,
Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans,
Map<String, RIBean<?>> riBeans,
Expand All @@ -321,17 +358,30 @@ private BeanManagerImpl(
this.contexts = contexts;
this.currentActivities = currentActivities;
this.specializedBeans = specializedBeans;
this.observers = registeredObservers;
this.observers = observers;
setEnabledDeploymentTypes(enabledDeploymentTypes);
setEnabledDecoratorClasses(enabledDecoratorClasses);
this.namespaces = namespaces;
this.ids = ids;
this.id = ids.incrementAndGet();

this.beanResolver = new TypeSafeBeanResolver<Bean<?>>(this, beans);
this.decoratorResolver = new TypeSafeDecoratorResolver(this, decorators);
this.observerResolver = new TypeSafeObserverResolver(this, registeredObservers);
this.nameBasedResolver = new NameBasedResolver(this, beans);

// Set up the structures to store accessible beans etc.

this.accessibleBeans = new HashSet<Iterable<Iterable<Bean<?>>>>();
this.accessibleDecorators = new HashSet<Iterable<Iterable<DecoratorBean<?>>>>();
this.accessibleNamespaces = new HashSet<Iterable<Iterable<String>>>();
this.accessibleObservers = new HashSet<Iterable<Iterable<EventObserver<?>>>>();

// Add this bean deployment archvies beans etc. to the accessible
add(accessibleBeans, beans);
add(accessibleDecorators, decorators);
add(accessibleNamespaces, namespaces);
add(accessibleObservers, observers);

this.beanResolver = new TypeSafeBeanResolver<Bean<?>>(this, Iterators.concat(getAccessibleBeans()));
this.decoratorResolver = new TypeSafeDecoratorResolver(this, Iterators.concat(getAccessibleDecorators()));
this.observerResolver = new TypeSafeObserverResolver(this, Iterators.concat(getAccessibleObservers()));
this.nameBasedResolver = new NameBasedResolver(this, Iterators.concat(getAccessibleBeans()));
this.webbeansELResolver = new WebBeansELResolverImpl(this);
this.childActivities = new CopyOnWriteArraySet<BeanManagerImpl>();

Expand All @@ -344,6 +394,41 @@ protected Stack<InjectionPoint> initialValue()
}
};
}

private static <X> void add(Collection<Iterable<Iterable<X>>> collection, Iterable<X> instance)
{
Collection<Iterable<X>> c = new ArrayList<Iterable<X>>();
c.add(instance);
collection.add(c);
}

public void addAccessibleBeanManager(BeanManagerImpl accessibleBeanManager)
{
accessibleBeans.add(accessibleBeanManager.getAccessibleBeans());
accessibleDecorators.add(accessibleBeanManager.getAccessibleDecorators());
accessibleNamespaces.add(accessibleBeanManager.getAccessibleNamespaces());
accessibleObservers.add(accessibleBeanManager.getAccessibleObservers());
}

protected Iterable<Iterable<Bean<?>>> getAccessibleBeans()
{
return Iterators.concat(accessibleBeans);
}

protected Iterable<Iterable<String>> getAccessibleNamespaces()
{
return Iterators.concat(accessibleNamespaces);
}

protected Iterable<Iterable<DecoratorBean<?>>> getAccessibleDecorators()
{
return Iterators.concat(accessibleDecorators);
}

protected Iterable<Iterable<EventObserver<?>>> getAccessibleObservers()
{
return Iterators.concat(accessibleObservers);
}

/**
* Set up the enabled deployment types, if none are specified by the user,
Expand Down Expand Up @@ -1065,7 +1150,7 @@ protected AtomicInteger getIds()
return ids;
}

protected Set<CurrentActivity> getCurrentActivities()
private Set<CurrentActivity> getCurrentActivities()
{
return currentActivities;
}
Expand All @@ -1085,7 +1170,7 @@ public Namespace getRootNamespace()
// TODO I don't like this lazy init
if (rootNamespace == null)
{
rootNamespace = new Namespace(getNamespaces());
rootNamespace = new Namespace(Iterators.concat(getAccessibleNamespaces()));
}
return rootNamespace;
}
Expand Down
3 changes: 1 addition & 2 deletions impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -149,8 +149,7 @@ public void initialize(BeanDeployerEnvironment environment)
}
initDefaultBindings();
initPrimitive();
if (log.isDebugEnabled())
log.debug("Building Web Bean bean metadata for " + getType());
log.trace("Building Web Bean bean metadata for #0", getType());
initName();
initDeploymentType();
checkDeploymentType();
Expand Down
Expand Up @@ -23,8 +23,8 @@
import java.util.Set;

import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.TypeLiteral;
import javax.inject.Obtains;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.event.EventImpl;
Expand All @@ -38,8 +38,8 @@ public class EventBean extends AbstractFacadeBean<Event<?>>
private static final Set<Type> DEFAULT_TYPES = new HashSet<Type>(Arrays.asList(TYPE, Object.class));
private static final Annotation ANY = new AnyLiteral();
private static final Set<Annotation> DEFAULT_BINDINGS = new HashSet<Annotation>(Arrays.asList(ANY));
public static final ResolvableTransformer TRANSFORMER = new FacadeBeanResolvableTransformer(Event.class, ANY);
private static final Set<Class<? extends Annotation>> FILTERED_ANNOTATION_TYPES = new HashSet<Class<? extends Annotation>>(Arrays.asList(Obtains.class));
public static final ResolvableTransformer TRANSFORMER = new FacadeBeanResolvableTransformer(TYPE);
private static final Set<Class<? extends Annotation>> FILTERED_ANNOTATION_TYPES = new HashSet<Class<? extends Annotation>>(Arrays.asList(Any.class));


public static AbstractFacadeBean<Event<?>> of(BeanManagerImpl manager)
Expand Down
Expand Up @@ -18,11 +18,13 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.enterprise.inject.Any;

import org.jboss.webbeans.literal.AnyLiteral;
import org.jboss.webbeans.resolution.ForwardingResolvable;
import org.jboss.webbeans.resolution.Resolvable;
import org.jboss.webbeans.resolution.ResolvableTransformer;
Expand All @@ -36,16 +38,20 @@
public class FacadeBeanResolvableTransformer implements ResolvableTransformer
{

private static final Set<Annotation> bindings;

static
{
bindings = new HashSet<Annotation>();
bindings.add(new AnyLiteral());
}

private final Class<?> clazz;
private final Annotation annotation;
private final Set<Annotation> bindings;
private final HashSet<Type> types;

public FacadeBeanResolvableTransformer(Class<?> clazz, Annotation annotation)
public FacadeBeanResolvableTransformer(Class<?> clazz)
{
this.clazz = clazz;
this.annotation = annotation;
this.bindings = new HashSet<Annotation>(Arrays.asList(annotation));
this.types = new HashSet<Type>();
types.add(clazz);
}
Expand All @@ -54,44 +60,40 @@ public Resolvable transform(final Resolvable resolvable)
{
if (resolvable.isAssignableTo(clazz))
{
if (resolvable.isAnnotationPresent(annotation.annotationType()))
return new ForwardingResolvable()
{

return new ForwardingResolvable()
@Override
protected Resolvable delegate()
{
return resolvable;
}

@Override
protected Resolvable delegate()
{
return resolvable;
}

@Override
public Set<Annotation> getBindings()
{
return Collections.unmodifiableSet(bindings);
}
@Override
public Set<Annotation> getBindings()
{
return Collections.unmodifiableSet(bindings);
}

@Override
public Set<Type> getTypeClosure()
{
return Collections.unmodifiableSet(types);
}
@Override
public Set<Type> getTypeClosure()
{
return Collections.unmodifiableSet(types);
}

@Override
public boolean isAssignableTo(Class<?> clazz)
{
return clazz.isAssignableFrom(clazz);
}
@Override
public boolean isAssignableTo(Class<?> c)
{
return c.isAssignableFrom(clazz);
}

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
return annotation.annotationType().equals(annotationType);
}
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
return Any.class.equals(annotationType);
}

};
}
};
}
return resolvable;
}
Expand Down

0 comments on commit 0bcc231

Please sign in to comment.