You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2023/01/25 23:02:28 UTC
[openwebbeans] branch main updated: OWB-1418 Priority on Stereotypes
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/main by this push:
new c25f20e70 OWB-1418 Priority on Stereotypes
c25f20e70 is described below
commit c25f20e701f7f7f9e388584fe272da38b80ee45c
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu Jan 26 00:01:47 2023 +0100
OWB-1418 Priority on Stereotypes
---
.../org/apache/webbeans/config/BeansDeployer.java | 54 ++++++++++++++++++++--
.../apache/webbeans/util/SpecializationUtil.java | 7 ---
.../org/apache/webbeans/util/WebBeansUtil.java | 25 ++++++----
3 files changed, 68 insertions(+), 18 deletions(-)
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
index 48a49e494..32cbaf146 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
@@ -547,6 +547,25 @@ public class BeansDeployer
return true;
}
}
+ }
+ if (at.getAnnotation(Priority.class) != null || hasStereoTypeWithPriority(stereotypes))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean hasStereoTypeWithPriority(Set<Class<? extends Annotation>> stereotypes)
+ {
+ if (stereotypes != null && !stereotypes.isEmpty())
+ {
+ for (Class<? extends Annotation> stereotype : stereotypes)
+ {
+ if (webBeansContext.getWebBeansUtil().isStereotypeWithPriority(stereotype, stereotypes))
+ {
+ return true;
+ }
+ }
}
return false;
@@ -665,7 +684,7 @@ public class BeansDeployer
{
if (annotatedType.getAnnotation(Alternative.class) != null)
{
- Priority priority = annotatedType.getAnnotation(Priority.class);
+ Priority priority = resolvePriority(annotatedType);
if (priority != null)
{
alternativesManager.addPriorityClazzAlternative(annotatedType.getJavaClass(), priority);
@@ -673,7 +692,7 @@ public class BeansDeployer
}
if (annotatedType.getAnnotation(jakarta.interceptor.Interceptor.class) != null)
{
- Priority priority = annotatedType.getAnnotation(Priority.class);
+ Priority priority = resolvePriority(annotatedType);
if (priority != null)
{
Class<?> javaClass = annotatedType.getJavaClass();
@@ -682,7 +701,7 @@ public class BeansDeployer
}
if (annotatedType.getAnnotation(jakarta.decorator.Decorator.class) != null)
{
- Priority priority = annotatedType.getAnnotation(Priority.class);
+ Priority priority = resolvePriority(annotatedType);
if (priority != null)
{
Class<?> javaClass = annotatedType.getJavaClass();
@@ -692,6 +711,35 @@ public class BeansDeployer
}
}
+ private Priority resolvePriority(AnnotatedType<?> annotatedType)
+ {
+ Priority priority = annotatedType.getAnnotation(Priority.class);
+ if (priority != null)
+ {
+ return priority;
+ }
+ for (Annotation annotation : annotatedType.getAnnotations())
+ {
+ if (webBeansContext.getAnnotationManager().isStereoTypeAnnotation(annotation.annotationType()))
+ {
+ final Priority stereoPriority = annotation.annotationType().getAnnotation(Priority.class);
+ if (stereoPriority != null)
+ {
+ if (priority == null)
+ {
+ priority = stereoPriority;
+ }
+ else
+ {
+ throw new WebBeansConfigurationException("Multiple Stereotypes with @Priority found on class " + annotatedType);
+ }
+ }
+ }
+ }
+
+ return priority;
+ }
+
/**
* Configure Default Beans.
*/
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java b/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java
index 7cec43f59..264c91795 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java
@@ -131,13 +131,6 @@ public class SpecializationUtil
AnnotatedType<?> superType = getAnnotatedTypeForClass(allAnnotatedTypes, superClass);
if (notSpecializationOnly)
{
- /*X TODO remove?
- if (superType != null && superType.getAnnotation(Specializes.class) != null)
- {
- continue;
- }
- */
-
if ((superType == null && !webBeansContext.findMissingAnnotatedType(superClass)) || (superType != null && !webBeansUtil.isConstructorOk(superType)))
{
throw new WebBeansDeploymentException(new InconsistentSpecializationException("@Specializes class " + specialClass.getName()
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java b/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
index a855a4521..73781bd41 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
@@ -904,8 +904,8 @@ public final class WebBeansUtil
{
for (Class<? extends Annotation> stereotype : stereotypes)
{
- if (alternativesManager.isAlternativeStereotype(stereotype) &&
- (at.getAnnotation(Priority.class) != null || isStereotypeWithPriority(stereotype, stereotypes)))
+ if (alternativesManager.isAlternativeStereotype(stereotype) ||
+ at.getAnnotation(Priority.class) != null || isStereotypeWithPriority(stereotype, stereotypes))
{
return true;
}
@@ -913,23 +913,32 @@ public final class WebBeansUtil
}
return false;
+ }
+ public boolean isStereotypeWithPriority(Class<? extends Annotation> stereotype, Set<Class<? extends Annotation>> stereotypes)
+ {
+ return getStereotypePriority(stereotype, stereotypes) != null;
}
- private boolean isStereotypeWithPriority(Class<? extends Annotation> stereotype, Set<Class<? extends Annotation>> stereotypes)
+ public Priority getStereotypePriority(Class<? extends Annotation> stereotype, Set<Class<? extends Annotation>> stereotypes)
{
- if (stereotype.getAnnotation(Priority.class) != null)
+ Priority priority = stereotype.getAnnotation(Priority.class);
+ if (priority != null)
{
- return true;
+ return priority;
}
for (Annotation annotation : stereotype.getAnnotations())
{
- if (stereotypes.contains(annotation.annotationType()) && annotation.annotationType().getAnnotation(Priority.class) != null)
+ if (stereotypes.contains(annotation.annotationType()))
{
- return true;
+ priority = annotation.annotationType().getAnnotation(Priority.class);
+ if (priority != null)
+ {
+ return priority;
+ }
}
}
- return false;
+ return null;
}
public static boolean isAlternative(Annotated annotated, Set<Class<? extends Annotation>> stereotypes)