From 083c30877cab2071ad8a98e3ad311566c1be8ec2 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Mon, 13 Nov 2023 20:07:27 +0100 Subject: [PATCH] Draft an API for programmatic access to assignability rules for observer methods and typesafe resolution. --- .../enterprise/inject/spi/BeanContainer.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/api/src/main/java/jakarta/enterprise/inject/spi/BeanContainer.java b/api/src/main/java/jakarta/enterprise/inject/spi/BeanContainer.java index cf6b0bdc..9145c429 100644 --- a/api/src/main/java/jakarta/enterprise/inject/spi/BeanContainer.java +++ b/api/src/main/java/jakarta/enterprise/inject/spi/BeanContainer.java @@ -251,4 +251,42 @@ public interface BeanContainer { * @since 2.0 */ Instance createInstance(); + + /** + * Returns true if a bean with given bean types and qualifiers would be assignable + * to an injection point with given required type and required qualifiers, false otherwise. + * In other words, this method provides access to the typesafe resolution rules - the process of matching a bean to an injection point. + *

+ * Callers do not need to include implicit qualifiers such as {@code @Default} or {@code Any}. + * These will be automatically added where applicable. + *

+ * Throws {@link IllegalArgumentException} if any of the arguments is {@code null}. + * + * @param beanTypes bean types of a bean; must not be {@code null} + * @param beanQualifiers qualifiers of a bean; must not be {@code null} + * @param requiredType required type of an injection point; must not be {@code null} + * @param requiredQualifiers required qualifiers of an injection point; must not be {@code null} + * @return true if a bean with given bean types and qualifiers would be assignable + * to an injection point with given required type and required qualifiers, false otherwise + */ + boolean isMatchingBean(Set beanTypes, Set beanQualifiers, Type requiredType, Set requiredQualifiers); + + /** + * Returns true if an event object with given type and qualifiers would match + * an observer method with given observed event type and observed event qualifiers, false otherwise. + * In other words, this method provides access to the assignability rules for observers - the process of matching an event to an observer method. + *

+ * Callers do not need to supply implicit qualifiers such as {@code @Default} or {@code Any}. + * These will be automatically added where applicable. + *

+ * Throws {@link IllegalArgumentException} if any of the arguments is {@code null}. + * + * @param eventType type of an event object; must not be {@code null} + * @param eventQualifiers event qualifiers; must not be {@code null} + * @param observedEventType observed event type of an observer method; must not be {@code null} + * @param observedEventQualifiers observed event qualifiers on an observer method; must not be {@code null} + * @return true if an event object with given type and qualifiers would result in notifying + * an observer method with given observed event type and observed event qualifiers, false otherwise + */ + boolean isMatchingEvent(Type eventType, Set eventQualifiers, Type observedEventType, Set observedEventQualifiers); }