Permalink
Browse files

WELD-1084 Introduce class InterceptorBindingType

  • Loading branch information...
1 parent 9a4d161 commit 19c76bcdf249d91453fc56b71fd8266765381242 @luksa committed with alesj Mar 15, 2012
@@ -35,6 +35,7 @@
import org.jboss.weld.injection.ConstructorInjectionPoint;
import org.jboss.weld.injection.FieldInjectionPoint;
import org.jboss.weld.injection.MethodInjectionPoint;
+import org.jboss.weld.interceptor.InterceptorBindingType;
import org.jboss.weld.interceptor.builder.InterceptionModelBuilder;
import org.jboss.weld.interceptor.spi.metadata.ClassMetadata;
import org.jboss.weld.interceptor.spi.metadata.InterceptorMetadata;
@@ -51,7 +52,6 @@
import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
import org.jboss.weld.util.Beans;
-import org.jboss.weld.util.InterceptorBindingSet;
import org.jboss.weld.util.reflection.Reflections;
import org.jboss.weld.util.reflection.SecureReflections;
import org.slf4j.cal10n.LocLogger;
@@ -494,68 +494,66 @@ public void init() {
}
private void initCdiInterceptors() {
- Set<Annotation> classBindingAnnotations = getClassInterceptorBindings();
- initCdiLifecycleInterceptors(classBindingAnnotations);
- initCdiBusinessMethodInterceptors(classBindingAnnotations);
+ Set<InterceptorBindingType> classBindings = getClassInterceptorBindings();
+ initCdiLifecycleInterceptors(classBindings);
+ initCdiBusinessMethodInterceptors(classBindings);
}
- private Set<Annotation> getClassInterceptorBindings() {
- Set<Annotation> classBindingAnnotations = new InterceptorBindingSet(beanManager);
- classBindingAnnotations.addAll(beanManager.extractInterceptorBindings(getWeldAnnotated().getAnnotations()));
+ private Set<InterceptorBindingType> getClassInterceptorBindings() {
+ Set<InterceptorBindingType> classBindingAnnotations = new HashSet<InterceptorBindingType>();
+ classBindingAnnotations.addAll(beanManager.extractAndFlattenInterceptorBindings(getWeldAnnotated().getAnnotations()));
for (Class<? extends Annotation> annotation : getStereotypes()) {
- classBindingAnnotations.addAll(beanManager.extractInterceptorBindings(beanManager.getStereotypeDefinition(annotation)));
+ classBindingAnnotations.addAll(beanManager.extractAndFlattenInterceptorBindings(beanManager.getStereotypeDefinition(annotation)));
}
return classBindingAnnotations;
}
- private void initCdiLifecycleInterceptors(Set<Annotation> classBindingAnnotations) {
- if (classBindingAnnotations.size() == 0) {
+ private void initCdiLifecycleInterceptors(Set<InterceptorBindingType> classBindings) {
+ if (classBindings.size() == 0) {
return;
}
- if (Beans.findInterceptorBindingConflicts(beanManager, classBindingAnnotations)) {
+ if (Beans.findInterceptorBindingConflicts(classBindings)) {
throw new DeploymentException(CONFLICTING_INTERCEPTOR_BINDINGS, getType());
}
- Annotation[] classBindingAnnotationsArray = classBindingAnnotations.toArray(new Annotation[classBindingAnnotations.size()]);
- initLifeCycleInterceptor(InterceptionType.POST_CONSTRUCT, classBindingAnnotationsArray);
- initLifeCycleInterceptor(InterceptionType.PRE_DESTROY, classBindingAnnotationsArray);
- initLifeCycleInterceptor(InterceptionType.PRE_PASSIVATE, classBindingAnnotationsArray);
- initLifeCycleInterceptor(InterceptionType.POST_ACTIVATE, classBindingAnnotationsArray);
+ initLifeCycleInterceptor(InterceptionType.POST_CONSTRUCT, classBindings);
+ initLifeCycleInterceptor(InterceptionType.PRE_DESTROY, classBindings);
+ initLifeCycleInterceptor(InterceptionType.PRE_PASSIVATE, classBindings);
+ initLifeCycleInterceptor(InterceptionType.POST_ACTIVATE, classBindings);
}
- private void initLifeCycleInterceptor(InterceptionType interceptionType, Annotation[] classBindingAnnotationsArray) {
- List<Interceptor<?>> resolvedInterceptors = beanManager.resolveInterceptors(interceptionType, classBindingAnnotationsArray);
+ private void initLifeCycleInterceptor(InterceptionType interceptionType, Set<InterceptorBindingType> interceptorBindingTypes) {
+ List<Interceptor<?>> resolvedInterceptors = beanManager.resolveInterceptors(interceptionType, interceptorBindingTypes);
builder.intercept(interceptionType).with(toSerializableContextualArray(resolvedInterceptors));
}
- private void initCdiBusinessMethodInterceptors(Set<Annotation> classBindingAnnotations) {
+ private void initCdiBusinessMethodInterceptors(Set<InterceptorBindingType> classBindings) {
for (WeldMethod<?, ?> method : businessMethods) {
- initCdiBusinessMethodInterceptor(method, getMethodBindingAnnotations(classBindingAnnotations, method));
+ initCdiBusinessMethodInterceptor(method, getMethodInterceptorBindings(classBindings, method));
}
}
- private Set<Annotation> getMethodBindingAnnotations(Set<Annotation> classBindingAnnotations, WeldMethod<?, ?> method) {
- Set<Annotation> methodBindingAnnotations = new InterceptorBindingSet(beanManager);
+ private Set<InterceptorBindingType> getMethodInterceptorBindings(Set<InterceptorBindingType> classBindingAnnotations, WeldMethod<?, ?> method) {
+ Set<InterceptorBindingType> methodBindingAnnotations = new HashSet<InterceptorBindingType>();
methodBindingAnnotations.addAll(classBindingAnnotations);
- methodBindingAnnotations.addAll(beanManager.extractInterceptorBindings(method.getAnnotations()));
+ methodBindingAnnotations.addAll(beanManager.extractAndFlattenInterceptorBindings(method.getAnnotations()));
return methodBindingAnnotations;
}
- private void initCdiBusinessMethodInterceptor(WeldMethod<?, ?> method, Set<Annotation> methodBindingAnnotations) {
- if (methodBindingAnnotations.size() == 0) {
+ private void initCdiBusinessMethodInterceptor(WeldMethod<?, ?> method, Set<InterceptorBindingType> methodInterceptorBindings) {
+ if (methodInterceptorBindings.size() == 0) {
return;
}
- if (Beans.findInterceptorBindingConflicts(beanManager, methodBindingAnnotations)) {
+ if (Beans.findInterceptorBindingConflicts(methodInterceptorBindings)) {
throw new DeploymentException(CONFLICTING_INTERCEPTOR_BINDINGS, getType() + "." + method.getName() + "()");
}
- Annotation[] methodBindingAnnotationsArray = methodBindingAnnotations.toArray(new Annotation[methodBindingAnnotations.size()]);
- initInterceptor(InterceptionType.AROUND_INVOKE, method, methodBindingAnnotationsArray);
- initInterceptor(InterceptionType.AROUND_TIMEOUT, method, methodBindingAnnotationsArray);
+ initInterceptor(InterceptionType.AROUND_INVOKE, method, methodInterceptorBindings);
+ initInterceptor(InterceptionType.AROUND_TIMEOUT, method, methodInterceptorBindings);
}
- private void initInterceptor(InterceptionType interceptionType, WeldMethod<?, ?> method, Annotation[] methodBindingAnnotationsArray) {
- List<Interceptor<?>> methodBoundInterceptors = beanManager.resolveInterceptors(interceptionType, methodBindingAnnotationsArray);
+ private void initInterceptor(InterceptionType interceptionType, WeldMethod<?, ?> method, Set<InterceptorBindingType> interceptorBindingTypes) {
+ List<Interceptor<?>> methodBoundInterceptors = beanManager.resolveInterceptors(interceptionType, interceptorBindingTypes);
if (methodBoundInterceptors != null && methodBoundInterceptors.size() > 0) {
if (method.isFinal()) {
throw new DefinitionException(FINAL_INTERCEPTED_BEAN_METHOD_NOT_ALLOWED, method, methodBoundInterceptors.get(0).getBeanClass().getName());
@@ -21,8 +21,8 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.exceptions.DeploymentException;
import org.jboss.weld.exceptions.WeldException;
+import org.jboss.weld.interceptor.InterceptorBindingType;
import org.jboss.weld.interceptor.proxy.InterceptorInvocation;
-import org.jboss.weld.interceptor.proxy.SimpleInterceptorInvocation;
import org.jboss.weld.interceptor.proxy.SimpleInterceptionChain;
import org.jboss.weld.interceptor.reader.ClassMetadataInterceptorReference;
import org.jboss.weld.interceptor.spi.metadata.InterceptorMetadata;
@@ -51,7 +51,7 @@
private final InterceptorMetadata<?> interceptorMetadata;
- private final Set<Annotation> interceptorBindingTypes;
+ private final Set<InterceptorBindingType> interceptorBindingTypes;
private final boolean serializable;
@@ -63,21 +63,21 @@ protected InterceptorImpl(WeldClass<T> type, BeanManagerImpl beanManager, Servic
super(type, new StringBuilder().append(Interceptor.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(type.getName()).toString(), beanManager, services);
this.interceptorMetadata = beanManager.getInterceptorMetadataReader().getInterceptorMetadata(ClassMetadataInterceptorReference.of(WeldInterceptorClassMetadata.of(type)));
this.serializable = type.isSerializable();
- this.interceptorBindingTypes = new HashSet<Annotation>();
- interceptorBindingTypes.addAll(beanManager.flattenInterceptorBindings(getWeldAnnotated().getAnnotations()));
+ this.interceptorBindingTypes = new HashSet<InterceptorBindingType>();
+ interceptorBindingTypes.addAll(beanManager.extractAndFlattenInterceptorBindings(getWeldAnnotated().getAnnotations()));
for (Class<? extends Annotation> annotation : getStereotypes()) {
- interceptorBindingTypes.addAll(beanManager.flattenInterceptorBindings(beanManager.getStereotypeDefinition(annotation)));
+ interceptorBindingTypes.addAll(beanManager.extractAndFlattenInterceptorBindings(beanManager.getStereotypeDefinition(annotation)));
}
if (this.interceptorBindingTypes.size() == 0) {
throw new DeploymentException(MISSING_BINDING_ON_INTERCEPTOR, type.getName());
}
- if (Beans.findInterceptorBindingConflicts(beanManager, interceptorBindingTypes)) {
+ if (Beans.findInterceptorBindingConflicts(interceptorBindingTypes)) {
throw new DeploymentException(CONFLICTING_INTERCEPTOR_BINDINGS, getType());
}
}
public Set<Annotation> getInterceptorBindings() {
- return interceptorBindingTypes;
+ return InterceptorBindingType.unwrap(interceptorBindingTypes);
}
public InterceptorMetadata<?> getInterceptorMetadata() {
@@ -0,0 +1,56 @@
+package org.jboss.weld.interceptor;
+
+import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.metadata.cache.InterceptorBindingModel;
+import org.jboss.weld.metadata.cache.MetaAnnotationStore;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ */
+public class InterceptorBindingType {
+
+ private BeanManagerImpl beanManager;
+ private Annotation annotation;
+
+ public InterceptorBindingType(BeanManagerImpl beanManager, Annotation annotation) {
+ this.beanManager = beanManager;
+ this.annotation = annotation;
+ }
+
+ public Annotation getAnnotation() {
+ return annotation;
+ }
+
+ public static Set<Annotation> unwrap(Set<InterceptorBindingType> interceptorBindingTypes) {
+ HashSet<Annotation> annotations = new HashSet<Annotation>();
+ for (InterceptorBindingType interceptorBindingType : interceptorBindingTypes) {
+ annotations.add(interceptorBindingType.getAnnotation());
+ }
+ return annotations;
+ }
+
+ public Class<? extends Annotation> annotationType() {
+ return getAnnotation().annotationType();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ InterceptorBindingType that = (InterceptorBindingType) o;
+
+ MetaAnnotationStore metaAnnotationStore = beanManager.getMetaAnnotationStore();
+ InterceptorBindingModel<? extends Annotation> interceptorBindingModel = metaAnnotationStore.getInterceptorBindingModel(annotation.annotationType());
+ return interceptorBindingModel.isEqual(getAnnotation(), that.getAnnotation());
+ }
+
+ @Override
+ public int hashCode() {
+ return annotationType().hashCode();
+ }
+}
@@ -45,6 +45,7 @@
import org.jboss.weld.exceptions.UnproxyableResolutionException;
import org.jboss.weld.exceptions.UnsatisfiedResolutionException;
import org.jboss.weld.injection.CurrentInjectionPoint;
+import org.jboss.weld.interceptor.InterceptorBindingType;
import org.jboss.weld.interceptor.reader.cache.DefaultMetadataCachingReader;
import org.jboss.weld.interceptor.reader.cache.MetadataCachingReader;
import org.jboss.weld.interceptor.spi.metadata.ClassMetadata;
@@ -70,7 +71,6 @@
import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.BeansClosure;
-import org.jboss.weld.util.InterceptorBindingSet;
import org.jboss.weld.util.Observers;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.collections.Arrays2;
@@ -755,25 +755,30 @@ private void checkResolveDecoratorsArguments(Set<Type> types) {
if (interceptorBindings.length == 0) {
throw new IllegalArgumentException(INTERCEPTOR_BINDINGS_EMPTY);
}
- Set<Annotation> interceptorBindingsSet = new InterceptorBindingSet(this);
+ Set<InterceptorBindingType> interceptorBindingTypes = new HashSet<InterceptorBindingType>();
for (Annotation annotation : interceptorBindings) {
if (!isInterceptorBinding(annotation.annotationType())) {
throw new IllegalArgumentException(NOT_INTERCEPTOR_BINDING_TYPE, annotation);
}
- if (interceptorBindingsSet.contains(annotation)) {
+ InterceptorBindingType interceptorBindingType = new InterceptorBindingType(this, annotation);
+ if (interceptorBindingTypes.contains(interceptorBindingType)) {
throw new IllegalArgumentException(DUPLICATE_INTERCEPTOR_BINDING, annotation);
}
- interceptorBindingsSet.add(annotation);
+ interceptorBindingTypes.add(interceptorBindingType);
}
- Set<Annotation> flattenedInterceptorBindings = flattenInterceptorBindings(interceptorBindingsSet);
+ return resolveInterceptors(type, flattenInterceptorBindings(interceptorBindingTypes));
+ }
+
+ public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Set<InterceptorBindingType> flattenedInterceptorBindings) {
+ Set<Annotation> interceptorBindingAnnotations = InterceptorBindingType.unwrap(flattenedInterceptorBindings);
InterceptorResolvable interceptorResolvable = new InterceptorResolvableBuilder(Object.class)
.setInterceptionType(type)
- .addQualifiers(flattenedInterceptorBindings)
+ .addQualifiers(interceptorBindingAnnotations)
.create();
// We can always cache as this is only ever called by Weld where we avoid non-static inner classes for annotation literals
- return new ArrayList<Interceptor<?>>(interceptorResolver.resolve(interceptorResolvable, isCacheable(flattenedInterceptorBindings)));
+ return new ArrayList<Interceptor<?>>(interceptorResolver.resolve(interceptorResolvable, isCacheable(interceptorBindingAnnotations)));
}
/**
@@ -1083,34 +1088,36 @@ public MetadataCachingReader getInterceptorMetadataReader() {
return AbstractProcessInjectionTarget.fire(this, annotatedType, createInjectionTarget(annotatedType));
}
- public Set<Annotation> extractInterceptorBindings(Iterable<Annotation> annotations) {
- Set<Annotation> foundInterceptionBindingTypes = new HashSet<Annotation>();
+ public Set<InterceptorBindingType> extractAndFlattenInterceptorBindings(Iterable<Annotation> annotations) {
+ return flattenInterceptorBindings(extractInterceptorBindings(annotations));
+ }
+
+ public Set<InterceptorBindingType> extractInterceptorBindings(Iterable<Annotation> annotations) {
+ Set<InterceptorBindingType> foundInterceptionBindingTypes = new HashSet<InterceptorBindingType>();
for (Annotation annotation : annotations) {
if (isInterceptorBinding(annotation.annotationType())) {
- foundInterceptionBindingTypes.add(annotation);
+ foundInterceptionBindingTypes.add(new InterceptorBindingType(this, annotation));
}
}
return foundInterceptionBindingTypes;
}
/**
* Extracts the complete set of interception bindings from a given set of
- * annotations.
+ * interceptorBindingTypes.
*
- * @param annotations
+ * @param interceptorBindingTypes
* @return
*/
- public Set<Annotation> flattenInterceptorBindings(Set<Annotation> annotations) {
+ public Set<InterceptorBindingType> flattenInterceptorBindings(Set<InterceptorBindingType> interceptorBindingTypes) {
MetaAnnotationStore metaAnnotationStore = getMetaAnnotationStore();
- Set<Annotation> foundInterceptionBindingTypes = new InterceptorBindingSet(this);
- for (Annotation annotation : annotations) {
- if (isInterceptorBinding(annotation.annotationType())) {
- foundInterceptionBindingTypes.add(annotation);
+ Set<InterceptorBindingType> foundInterceptionBindingTypes = new HashSet<InterceptorBindingType>();
+ for (InterceptorBindingType interceptorBindingType : interceptorBindingTypes) {
+ foundInterceptionBindingTypes.add(interceptorBindingType);
- InterceptorBindingModel<? extends Annotation> interceptorBindingModel = metaAnnotationStore.getInterceptorBindingModel(annotation.annotationType());
- foundInterceptionBindingTypes.addAll(interceptorBindingModel.getInheritedInterceptionBindingTypes());
- }
+ InterceptorBindingModel<? extends Annotation> interceptorBindingModel = metaAnnotationStore.getInterceptorBindingModel(interceptorBindingType.annotationType());
+ foundInterceptionBindingTypes.addAll(extractInterceptorBindings(interceptorBindingModel.getInheritedInterceptionBindingTypes()));
}
return foundInterceptionBindingTypes;
}
Oops, something went wrong.

0 comments on commit 19c76bc

Please sign in to comment.