Skip to content

Commit

Permalink
WBRI-307
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3385 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jul 31, 2009
1 parent c502eb6 commit 3834c20
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 43 deletions.
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -682,7 +682,7 @@ public Set<Bean<?>> getBeans(WBAnnotated<?, ?> element, Annotation... bindings)
{
throw new IllegalArgumentException("Cannot resolve a type parameterized with a wildcard " + element);
}
if (type instanceof TypeVariable)
if (type instanceof TypeVariable<?>)
{
throw new IllegalArgumentException("Cannot resolve a type parameterized with a type parameter " + element);
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.webbeans;
package org.jboss.webbeans.bean.standard;

import java.io.Serializable;
import java.lang.annotation.Annotation;
Expand All @@ -23,6 +23,7 @@
import java.util.HashSet;
import java.util.Set;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;

/**
Expand All @@ -32,7 +33,7 @@
*
* @param <T>
*/
public abstract class FacadeImpl<T> implements Serializable
public abstract class AbstractFacade<T, X> implements Serializable
{

private static final long serialVersionUID = 8710258788495459128L;
Expand All @@ -52,7 +53,7 @@ public abstract class FacadeImpl<T> implements Serializable
* @param manager The Web Beans manager
* @param bindings The binding types
*/
protected FacadeImpl(Type type, BeanManagerImpl manager, Set<? extends Annotation> bindings)
protected AbstractFacade(Type type, BeanManagerImpl manager, Set<? extends Annotation> bindings)
{
this.manager = manager;
this.type = type;
Expand Down
Expand Up @@ -27,7 +27,6 @@
import javax.enterprise.inject.TypeLiteral;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.InstanceImpl;
import org.jboss.webbeans.literal.AnyLiteral;
import org.jboss.webbeans.resolution.ResolvableTransformer;

Expand Down
Expand Up @@ -14,18 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.webbeans;
package org.jboss.webbeans.bean.standard;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import javax.enterprise.inject.Instance;
import javax.enterprise.inject.TypeLiteral;
import javax.enterprise.inject.spi.Bean;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.resolution.ResolvableWBClass;

/**
Expand All @@ -35,10 +40,13 @@
*
* @param <T>
*/
public class InstanceImpl<T> extends FacadeImpl<T> implements Instance<T>, Serializable
public class InstanceImpl<T> extends AbstractFacade<T, Instance<T>> implements Instance<T>, Serializable
{

private static final long serialVersionUID = -376721889693284887L;
private static final Annotation[] EMPTY_BINDINGS = new Annotation[0];

private final Set<Bean<?>> beans;

public static <I> Instance<I> of(Type type, BeanManagerImpl manager, Set<Annotation> annotations)
{
Expand All @@ -48,9 +56,10 @@ public static <I> Instance<I> of(Type type, BeanManagerImpl manager, Set<Annotat
private InstanceImpl(Type type, BeanManagerImpl manager, Set<Annotation> bindings)
{
super(type, manager, bindings);
this.beans = getManager().getBeans(getType(), bindings.toArray(EMPTY_BINDINGS));
}

public T get(Annotation... bindings)
public T get(Annotation... bindings)
{
Annotation[] annotations = mergeInBindings(bindings);
Bean<T> bean = getManager().getBean(ResolvableWBClass.<T>of(getType(), annotations, getManager()), annotations);
Expand All @@ -71,49 +80,57 @@ public String toString()
return "Obtainable instance for type " + getType() + " and binding types " + getBindings();
}

private Collection<T> getReferences()
{
Collection<T> instances = new ArrayList<T>();
for (Bean<?> bean : beans)
{
Object object = getManager().getReference(bean, getType(), getManager().createCreationalContext(bean));

@SuppressWarnings("unchecked")
T instance = (T) object;

instances.add(instance);
}
return instances;
}

public Iterator<T> iterator()
{
throw new UnsupportedOperationException("Not yet implemented");
return getReferences().iterator();
}

/* (non-Javadoc)
* @see javax.enterprise.inject.Instance#isAmbiguous()
*/
public boolean isAmbiguous()
{
throw new UnsupportedOperationException();
return beans.size() > 1;
}

/* (non-Javadoc)
* @see javax.enterprise.inject.Instance#isUnsatisfied()
*/
public boolean isUnsatisfied()
{
throw new UnsupportedOperationException();
return beans.size() == 0;
}

/* (non-Javadoc)
* @see javax.enterprise.inject.Instance#select(java.lang.annotation.Annotation[])
*/
public Instance<T> select(Annotation... bindings)
{
throw new UnsupportedOperationException();
return selectInstance(this.getType(), bindings);
}

/* (non-Javadoc)
* @see javax.enterprise.inject.Instance#select(java.lang.Class, java.lang.annotation.Annotation[])
*/
public <U extends T> Instance<U> select(Class<U> subtype, Annotation... bindings)
{
throw new UnsupportedOperationException();
return selectInstance(subtype, bindings);
}

/* (non-Javadoc)
* @see javax.enterprise.inject.Instance#select(javax.enterprise.inject.TypeLiteral, java.lang.annotation.Annotation[])
*/
public <U extends T> Instance<U> select(TypeLiteral<U> subtype, Annotation... bindings)
{
throw new UnsupportedOperationException();
return selectInstance(subtype.getType(), bindings);
}

private <U extends T> Instance<U> selectInstance(Type subtype, Annotation[] bindings)
{
return new InstanceImpl<U>(
subtype,
this.getManager(),
new HashSet<Annotation>(Arrays.asList(mergeInBindings(bindings))));
}

}
27 changes: 13 additions & 14 deletions impl/src/main/java/org/jboss/webbeans/event/EventImpl.java
Expand Up @@ -26,7 +26,7 @@
import javax.enterprise.inject.TypeLiteral;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.FacadeImpl;
import org.jboss.webbeans.bean.standard.AbstractFacade;
import org.jboss.webbeans.util.Strings;

/**
Expand All @@ -37,7 +37,7 @@
* @param <T> The type of event being wrapped
* @see javax.enterprise.event.Event
*/
public class EventImpl<T> extends FacadeImpl<T> implements Event<T>
public class EventImpl<T> extends AbstractFacade<T, Event<T>> implements Event<T>
{

private static final long serialVersionUID = 656782657242515455L;
Expand All @@ -55,7 +55,7 @@ public static <E> Event<E> of(Type eventType, BeanManagerImpl manager, Set<Annot
* @param manager The Web Beans manager
* @param bindings The binding types
*/
public EventImpl(Type eventType, BeanManagerImpl manager, Set<Annotation> bindings)
private EventImpl(Type eventType, BeanManagerImpl manager, Set<Annotation> bindings)
{
super(eventType, manager, bindings);
}
Expand All @@ -74,29 +74,28 @@ public void fire(T event)
{
getManager().fireEvent(event, mergeInBindings());
}

public Event<T> select(Annotation... bindings)
{
return new EventImpl<T>(
this.getType(),
this.getManager(),
new HashSet<Annotation>(Arrays.asList(mergeInBindings(bindings))));
return selectEvent(this.getType(), bindings);
}

public <U extends T> Event<U> select(Class<U> subtype, Annotation... bindings)
{
return new EventImpl<U>(
subtype,
this.getManager(),
new HashSet<Annotation>(Arrays.asList(mergeInBindings(bindings))));
return selectEvent(subtype, bindings);
}

public <U extends T> Event<U> select(TypeLiteral<U> subtype, Annotation... bindings)
{
return selectEvent(subtype.getType(), bindings);
}

private <U extends T> Event<U> selectEvent(Type subtype, Annotation[] bindings)
{
return new EventImpl<U>(
subtype.getType(),
subtype,
this.getManager(),
new HashSet<Annotation>(Arrays.asList(mergeInBindings(bindings))));
}
}

}

0 comments on commit 3834c20

Please sign in to comment.