Class CdiUtils

java.lang.Object
org.a2aproject.sdk.server.util.CdiUtils

public final class CdiUtils extends Object
CDI utility methods shared across server modules.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> @Nullable T
    getIfResolvable(@Nullable jakarta.enterprise.inject.Instance<T> instance)
    Resolves a bean from an optional CDI Instance.
    static <T> @Nullable T
    resolveDefaultBean(jakarta.enterprise.inject.Instance<T> allBeans, Class<? extends Annotation> excludeQualifier, @Nullable Class<? extends Annotation> requiredQualifier, String beanTypeName)
    Finds the single default bean of a given type, excluding beans that carry a specific qualifier and optionally requiring another.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getIfResolvable

      public static <T> @Nullable T getIfResolvable(@Nullable jakarta.enterprise.inject.Instance<T> instance)
      Resolves a bean from an optional CDI Instance.
      Type Parameters:
      T - the bean type
      Parameters:
      instance - the CDI instance, may be null
      Returns:
      the resolved bean, or null if the instance is absent or not uniquely resolvable
    • resolveDefaultBean

      public static <T> @Nullable T resolveDefaultBean(jakarta.enterprise.inject.Instance<T> allBeans, Class<? extends Annotation> excludeQualifier, @Nullable Class<? extends Annotation> requiredQualifier, String beanTypeName)
      Finds the single default bean of a given type, excluding beans that carry a specific qualifier and optionally requiring another. Warns on duplicate defaults and validates that the bean scope is @ApplicationScoped or @Singleton.
      Type Parameters:
      T - the bean type
      Parameters:
      allBeans - the CDI instance containing all beans of type T
      excludeQualifier - qualifier whose presence causes a bean to be skipped
      requiredQualifier - qualifier that the default bean must carry, or null to accept any non-excluded bean
      beanTypeName - human-readable label used in warning messages (e.g. "@ExtendedAgentCard")
      Returns:
      the resolved default bean, or null if none was found