Skip to content

Commit

Permalink
Fixed some bugs and implemented the rest of the section 8.6 tests.
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@550 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Dec 18, 2008
1 parent ed83c48 commit c9fd472
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 162 deletions.
Expand Up @@ -63,6 +63,7 @@
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.transaction.Transaction;
Expand Down Expand Up @@ -184,15 +185,7 @@ protected void createBean(AbstractClassBean<?> bean, Set<AbstractBean<?, ?>> bea
ProducerMethodBean<?> producerMethodBean = createProducerMethodBean(producerMethod, bean, manager);
beans.add(producerMethodBean);
manager.getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
for (AnnotatedItem injectionPoint : producerMethodBean.getInjectionPoints())
{
if ( injectionPoint.isAnnotationPresent(Observable.class) )
{
EventBean<Object, Method> eventBean = createEventBean(injectionPoint, manager);
beans.add(eventBean);
log.info("Web Bean: " + eventBean);
}
}
registerEvents(producerMethodBean.getInjectionPoints(), beans);
log.info("Web Bean: " + producerMethodBean);
}
for (AnnotatedField<Object> producerField : bean.getProducerFields())
Expand All @@ -201,13 +194,18 @@ protected void createBean(AbstractClassBean<?> bean, Set<AbstractBean<?, ?>> bea
beans.add(producerFieldBean);
log.info("Web Bean: " + producerFieldBean);
}
for (AnnotatedMethod<Object> initializerMethod : bean.getInitializerMethods())
{
for (AnnotatedParameter<Object> parameter : initializerMethod.getAnnotatedParameters(Observable.class))
{
registerEvent(parameter, beans);
}
}
for (AnnotatedItem injectionPoint : bean.getInjectionPoints())
{
if ( injectionPoint.isAnnotationPresent(Observable.class) )
{
EventBean<Object, Field> eventBean = createEventBean(injectionPoint, manager);
beans.add(eventBean);
log.info("Web Bean: " + eventBean);
registerEvent(injectionPoint, beans);
}
if ( injectionPoint.isAnnotationPresent(Obtainable.class) )
{
Expand Down Expand Up @@ -312,6 +310,32 @@ private <T> void registerObserver(Observer<T> observer, Class<?> eventType, Anno
manager.addObserver(observer, (Class<T>) eventType, bindings);
}

/**
* Iterates through the injection points and creates and registers any Event
* observables specified with the @Observable annotation
*
* @param injectionPoints A set of injection points to inspect
* @param beans A set of beans to add the Event beans to
*/
@SuppressWarnings("unchecked")
private void registerEvents(Set<AnnotatedItem<?,?>> injectionPoints, Set<AbstractBean<?, ?>> beans)
{
for (AnnotatedItem injectionPoint : injectionPoints)
{
registerEvent(injectionPoint, beans);
}
}

@SuppressWarnings("unchecked")
private void registerEvent(AnnotatedItem injectionPoint, Set<AbstractBean<?, ?>> beans)
{
if ( injectionPoint.isAnnotationPresent(Observable.class) )
{
EventBean<Object, Method> eventBean = createEventBean(injectionPoint, manager);
beans.add(eventBean);
log.info("Web Bean: " + eventBean);
}
}
/**
* Indicates if the type is a simple Web Bean
*
Expand Down
Expand Up @@ -30,6 +30,7 @@
import javax.webbeans.BeforeTransactionCompletion;
import javax.webbeans.Disposes;
import javax.webbeans.IfExists;
import javax.webbeans.Observable;
import javax.webbeans.Observes;
import javax.webbeans.manager.Manager;

Expand All @@ -43,7 +44,7 @@
public interface AnnotatedMethod<T> extends AnnotatedItem<T, Method>
{

public static final Set<Class<? extends Annotation>> MAPPED_PARAMETER_ANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Disposes.class, Observes.class, IfExists.class, BeforeTransactionCompletion.class, AfterTransactionCompletion.class, AfterTransactionFailure.class, AfterTransactionSuccess.class));
public static final Set<Class<? extends Annotation>> MAPPED_PARAMETER_ANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Disposes.class, Observes.class, Observable.class, IfExists.class, BeforeTransactionCompletion.class, AfterTransactionCompletion.class, AfterTransactionFailure.class, AfterTransactionSuccess.class));

/**
* Gets the abstracted parameters of the method
Expand Down
Expand Up @@ -163,20 +163,6 @@ public List<AnnotatedParameter<Object>> getParameters()
return Collections.unmodifiableList(parameters);
}

/**
* Gets the parameter abstractions with a given annotation type
*
* if the annotated parameters map is null, it is initialized first.
*
* @param annotationType The annotation type to match
* @return The list of parameter abstractions with given annotation type. An
* empty list is returned if there are no matches.
*/
public List<AnnotatedParameter<Object>> getAnnotatedMethods(Class<? extends Annotation> annotationType)
{
return Collections.unmodifiableList(annotatedParameters.get(annotationType));
}

/**
* Gets parameter abstractions with a given annotation type.
*
Expand Down
Expand Up @@ -160,16 +160,16 @@ public String toString()
{
return toString;
}
toString = "Annotated parameter " + Names.type2String(getDelegate().getClass());
toString = toDetailedString();
return toString;
}

public String toDetailedString()
{
StringBuilder buffer = new StringBuilder();
buffer.append("AnnotatedParameterImpl:\n");
buffer.append(super.toString() + "\n");
buffer.append("Type: " + type.toString() + "\n");
buffer.append("Annotations: " + Names.annotations2String(this.getAnnotations().toArray(new Annotation[0])));
buffer.append("Final: " + _final + "\n");
buffer.append("Static: " + _static + "\n");
buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
Expand Down
Expand Up @@ -157,7 +157,7 @@ private static List<String> parseModifiers(int modifier)
* @param annotations The annotations
* @return The string representation
*/
private static String annotations2String(Annotation[] annotations)
public static String annotations2String(Annotation[] annotations)
{
StringBuilder buffer = new StringBuilder();
for (Annotation annotation : annotations)
Expand Down

0 comments on commit c9fd472

Please sign in to comment.