Class DynTabDiscoveryExtension

java.lang.Object
dyntabs.annotation.DynTabDiscoveryExtension
All Implemented Interfaces:
jakarta.enterprise.inject.spi.Extension

public class DynTabDiscoveryExtension extends Object implements jakarta.enterprise.inject.spi.Extension
CDI Extension that automatically scans @DynTab annotations during bootstrap.

This eliminates the need for manual registration in a DynTabConfig subclass. The developer just places the @DynTab annotation on the bean and that's it!

How it works:

  1. During CDI bootstrap, processDynTabAnnotation(jakarta.enterprise.inject.spi.ProcessAnnotatedType<T>) is called for each class that has a @DynTab annotation (one or more, thanks to @Repeatable)
  2. Tab information is stored in the static list discoveredTabs
  3. After deployment, afterDeploymentValidation(jakarta.enterprise.inject.spi.AfterDeploymentValidation, jakarta.enterprise.inject.spi.BeanManager) only logs the result
  4. DynTabRegistry in its @PostConstruct calls getDiscoveredTabs() and registers all discovered tabs

IMPORTANT: The Extension does NOT access CDI beans (does not use CDI.current()). Reason: during the Extension lifecycle, the EE environment is not yet fully started, and accessing CDI beans causes a SEVERE error on GlassFish: "No valid EE environment for injection of..." Instead, the Extension only collects data, and DynTabRegistry retrieves it later.

@Repeatable support: A class can have one or more @DynTab annotations. When there are multiple, the Java compiler automatically wraps them in a @DynTabs container annotation. This Extension handles both cases using getAnnotationsByType().

Registration: The Extension is automatically loaded because it is registered in META-INF/services/jakarta.enterprise.inject.spi.Extension

Author:
DynTabs
See Also:
  • Constructor Details

    • DynTabDiscoveryExtension

      public DynTabDiscoveryExtension()
  • Method Details

    • getDiscoveredTabs

      public static List<DynTabDiscoveryExtension.DiscoveredTab> getDiscoveredTabs()
      Returns the list of all discovered @DynTab annotations. Called from DynTabRegistry.init() for tab registration.
      Returns:
      an unmodifiable list of discovered tabs
    • processDynTabAnnotation

      public <T> void processDynTabAnnotation(@Observes jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> pat)
      Called for each class that has a @DynTab or @DynTabs annotation during CDI scanning.

      Uses getAnnotationsByType(DynTab.class) instead of getAnnotation(DynTab.class) to cover both a single @DynTab and multiple @DynTab (wrapped in @DynTabs).

      getAnnotationsByType() works for both cases:

      • Single @DynTab annotation -> returns an array with one element
      • Multiple @DynTab (wrapped in @DynTabs) -> returns an array with all elements
      Type Parameters:
      T - the class type
      Parameters:
      pat - ProcessAnnotatedType event with class information
    • afterDeploymentValidation

      public void afterDeploymentValidation(@Observes jakarta.enterprise.inject.spi.AfterDeploymentValidation adv, jakarta.enterprise.inject.spi.BeanManager bm)
      Called after CDI deployment is complete.

      Does not access CDI beans - only logs the scanning result. Actual tab registration happens in DynTabRegistry.init().

      Parameters:
      adv - AfterDeploymentValidation event
      bm - BeanManager