Skip to content

Commit

Permalink
More specialization support
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1135 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 21, 2009
1 parent 5783f97 commit ab60b17
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 213 deletions.
Expand Up @@ -39,7 +39,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injection.InjectionPointImpl;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.jlr.AnnotationStore.AnnotationMap;
import org.jboss.webbeans.introspector.AnnotationStore.AnnotationMap;
import org.jboss.webbeans.literal.CurrentLiteral;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
Expand Down
147 changes: 123 additions & 24 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
Expand Up @@ -9,6 +9,7 @@
import java.util.Set;

import javax.webbeans.BindingType;
import javax.webbeans.DeploymentType;
import javax.webbeans.Fires;
import javax.webbeans.Initializer;
import javax.webbeans.Observes;
Expand All @@ -33,6 +34,8 @@
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.WrappedAnnotatedField;
import org.jboss.webbeans.introspector.WrappedAnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.jsf.JSFApiAbstraction;
import org.jboss.webbeans.log.LogProvider;
Expand Down Expand Up @@ -109,45 +112,72 @@ protected void createBean(AbstractClassBean<?> bean, final AnnotatedClass<?> ann

manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());

registerProducerMethods(bean, annotatedClass, EMPTY_BINDINGS);
registerProducerFields(bean, annotatedClass, EMPTY_BINDINGS);
registerObserverMethods(bean, annotatedClass);
registerFacades(bean.getAnnotatedInjectionPoints());
createProducerMethods(bean, annotatedClass);
createProducerFields(bean, annotatedClass);
createObserverMethods(bean, annotatedClass);
createFacades(bean.getAnnotatedInjectionPoints());

if (annotatedClass.isAnnotationPresent(Realizes.class))
{
Set<Annotation> extraAnnotations = new HashSet<Annotation>();
extraAnnotations.addAll(annotatedClass.getDeclaredMetaAnnotations(BindingType.class));
registerProducerMethods(bean, annotatedClass.getSuperclass(), extraAnnotations);
registerProducerFields(bean, annotatedClass.getSuperclass(), extraAnnotations);
createRealizedProducerMethods(bean, annotatedClass);
createRealizedProducerFields(bean, annotatedClass);
}

log.info("Web Bean: " + bean);
}

private void registerProducerMethods(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass, Set<Annotation> extraAnnotations)
private void createProducerMethods(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass)
{
for (AnnotatedMethod<?> method : annotatedClass.getDeclaredAnnotatedMethods(Produces.class))
{
ProducerMethodBean<?> bean = ProducerMethodBean.of(method.wrap(extraAnnotations), declaringBean, manager);
beans.add(bean);
manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());
registerFacades(bean.getAnnotatedInjectionPoints());
log.info("Web Bean: " + bean);
createProducerMethod(declaringBean, method);

}
}

private void registerProducerFields(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass, Set<Annotation> extraAnnotations)
private void createProducerMethod(AbstractClassBean<?> declaringBean, AnnotatedMethod<?> annotatedMethod)
{
ProducerMethodBean<?> bean = ProducerMethodBean.of(annotatedMethod, declaringBean, manager);
beans.add(bean);
manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());
createFacades(bean.getAnnotatedInjectionPoints());
log.info("Web Bean: " + bean);
}

private void createRealizedProducerMethods(AbstractClassBean<?> declaringBean, AnnotatedClass<?> realizingClass)
{
AnnotatedClass<?> realizedClass = realizingClass.getSuperclass();
for (AnnotatedMethod<?> realizedMethod : realizedClass.getDeclaredAnnotatedMethods(Produces.class))
{
createProducerMethod(declaringBean, realizeProducerMethod(realizedMethod, realizingClass));
}
}

private void createRealizedProducerFields(AbstractClassBean<?> declaringBean, AnnotatedClass<?> realizingClass)
{
AnnotatedClass<?> realizedClass = realizingClass.getSuperclass();
for (final AnnotatedField<?> realizedField : realizedClass.getDeclaredAnnotatedFields(Produces.class))
{
createProducerField(declaringBean, realizeProducerField(realizedField, realizingClass));
}
}

private void createProducerField(AbstractClassBean<?> declaringBean, AnnotatedField<?> field)
{
ProducerFieldBean<?> bean = ProducerFieldBean.of(field, declaringBean, manager);
beans.add(bean);
log.info("Web Bean: " + bean);
}

private void createProducerFields(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass)
{
for (AnnotatedField<?> field : annotatedClass.getDeclaredAnnotatedFields(Produces.class))
{
ProducerFieldBean<?> bean = ProducerFieldBean.of(field.wrap(extraAnnotations), declaringBean, manager);
beans.add(bean);
log.info("Web Bean: " + bean);
createProducerField(declaringBean, field);
}
}

private void registerObserverMethods(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass)
private void createObserverMethods(AbstractClassBean<?> declaringBean, AnnotatedClass<?> annotatedClass)
{
for (AnnotatedMethod<?> observerMethod : annotatedClass.getDeclaredMethodsWithAnnotatedParameters(Observes.class))
{
Expand All @@ -156,22 +186,22 @@ private void registerObserverMethods(AbstractClassBean<?> declaringBean, Annotat
}
}

private void registerFacades(Set<AnnotatedItem<?, ?>> injectionPoints)
private void createFacades(Set<AnnotatedItem<?, ?>> injectionPoints)
{
for (AnnotatedItem<?, ?> injectionPoint : injectionPoints)
{
if (injectionPoint.isAnnotationPresent(Fires.class))
{
registerEvent(injectionPoint);
createEvent(injectionPoint);
}
if (injectionPoint.isAnnotationPresent(Obtains.class))
{
registerInstance(injectionPoint);
createInstance(injectionPoint);
}
}
}

private void registerEvent(AnnotatedItem<?, ?> injectionPoint)
private void createEvent(AnnotatedItem<?, ?> injectionPoint)
{
// TODO Fix this!
@SuppressWarnings("unchecked")
Expand All @@ -180,7 +210,7 @@ private void registerEvent(AnnotatedItem<?, ?> injectionPoint)
log.info("Web Bean: " + bean);
}

private void registerInstance(AnnotatedItem<?, ?> injectionPoint)
private void createInstance(AnnotatedItem<?, ?> injectionPoint)
{
// TODO FIx this
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -223,4 +253,73 @@ private static boolean hasSimpleWebBeanConstructor(Class<?> type)
return false;
}
}

private static <T> AnnotatedMethod<T> realizeProducerMethod(final AnnotatedMethod<T> method, final AnnotatedClass<?> realizingClass)
{
return new WrappedAnnotatedMethod<T>(method, realizingClass.getMetaAnnotations(BindingType.class))
{

@Override
public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
if (metaAnnotationType.equals(DeploymentType.class))
{
return realizingClass.getMetaAnnotations(DeploymentType.class);
}
else
{
return super.getMetaAnnotations(metaAnnotationType);
}
}

@Override
public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
if (metaAnnotationType.equals(DeploymentType.class))
{
return realizingClass.getDeclaredMetaAnnotations(DeploymentType.class);
}
else
{
return super.getDeclaredMetaAnnotations(metaAnnotationType);
}
}

};
}

private static <T> AnnotatedField<T> realizeProducerField(final AnnotatedField<T> field, final AnnotatedClass<?> realizingClass)
{
return new WrappedAnnotatedField<T>(field, realizingClass.getMetaAnnotations(BindingType.class))
{

@Override
public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
if (metaAnnotationType.equals(DeploymentType.class))
{
return realizingClass.getMetaAnnotations(DeploymentType.class);
}
else
{
return super.getMetaAnnotations(metaAnnotationType);
}
}

@Override
public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
if (metaAnnotationType.equals(DeploymentType.class))
{
return realizingClass.getDeclaredMetaAnnotations(DeploymentType.class);
}
else
{
return super.getDeclaredMetaAnnotations(metaAnnotationType);
}
}

};
}

}
Expand Up @@ -43,6 +43,4 @@ public interface AnnotatedAnnotation<T extends Annotation> extends AnnotatedType
*/
public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends Annotation> annotationType);

public AnnotatedAnnotation<T> wrap(Set<Annotation> annotations);

}
Expand Up @@ -151,7 +151,5 @@ public interface AnnotatedClass<T> extends AnnotatedType<T>
public boolean isNonStaticMemberClass();

public boolean isParameterizedType();

public AnnotatedClass<T> wrap(Set<Annotation> annotations);

}
Expand Up @@ -20,7 +20,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Set;

import org.jboss.webbeans.ManagerImpl;

Expand Down Expand Up @@ -65,7 +64,5 @@ public interface AnnotatedConstructor<T> extends AnnotatedMember<T, Constructor<
* @return An abstraction of the declaring class
*/
public AnnotatedType<T> getDeclaringClass();

public AnnotatedConstructor<T> wrap(Set<Annotation> annotations);

}
Expand Up @@ -17,9 +17,7 @@

package org.jboss.webbeans.introspector;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Set;

import javax.webbeans.manager.Manager;

Expand Down Expand Up @@ -99,6 +97,4 @@ public interface AnnotatedField<T> extends AnnotatedMember<T, Field>

public boolean isTransient();

public AnnotatedField<T> wrap(Set<Annotation> annotations);

}
Expand Up @@ -184,6 +184,6 @@ public interface AnnotatedItem<T, S>
*/
public String getName();

public AnnotatedItem<T, S> wrap(Set<Annotation> annotations);
public AnnotationStore getAnnotationStore();

}
Expand Up @@ -16,9 +16,7 @@
*/
package org.jboss.webbeans.introspector;

import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.Set;
/**
* AnnotedMember provides enhanced access to an annotated member
*
Expand All @@ -30,6 +28,4 @@ public interface AnnotatedMember<T, S extends Member> extends AnnotatedItem<T, S

public S getMember();

public AnnotatedMember<T, S> wrap(Set<Annotation> annotations);

}
Expand Up @@ -130,7 +130,5 @@ public interface AnnotatedMethod<T> extends AnnotatedMember<T, Method>
public boolean isEquivalent(Method method);

public Method getAnnotatedMethod();

public AnnotatedMethod<T> wrap(Set<Annotation> annotations);

}
@@ -1,4 +1,4 @@
package org.jboss.webbeans.introspector.jlr;
package org.jboss.webbeans.introspector;

import static org.jboss.webbeans.introspector.AnnotatedItem.MAPPED_METAANNOTATIONS;

Expand Down Expand Up @@ -302,12 +302,12 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
return annotationMap.containsKey(annotationType);
}

public AnnotationMap getAnnotationMap()
AnnotationMap getAnnotationMap()
{
return annotationMap;
}

public AnnotationMap getDeclaredAnnotationMap()
AnnotationMap getDeclaredAnnotationMap()
{
return declaredAnnotationMap;
}
Expand Down

0 comments on commit ab60b17

Please sign in to comment.