Class Registry

java.lang.Object
org.approvej.configuration.Registry

@NullMarked public final class Registry extends Object
Registry for components that can be configured via aliases.

Components are discovered via the Java ServiceLoader mechanism. Providers register themselves by implementing the Provider interface and adding a corresponding entry in META-INF/services/org.approvej.configuration.Provider.

The registry supports both alias-based lookups (e.g., "json", "yaml") and fallback to fully-qualified class names for backward compatibility.

  • Method Details

    • resolve

      public static <T> T resolve(String aliasOrClassName, Class<T> type)
      Resolves a component by its alias or fully-qualified class name.

      First attempts to find a registered provider with the given alias. If no provider is found, falls back to creating an instance via reflection using the alias as a class name.

      Type Parameters:
      T - the component type
      Parameters:
      aliasOrClassName - the alias (e.g., "json") or fully-qualified class name
      type - the expected component type
      Returns:
      the resolved component instance
      Throws:
      ConfigurationError - if the component cannot be resolved
    • findByAlias

      public static <T> Optional<T> findByAlias(String alias, Class<T> type)
      Finds a provider by its alias for the given type.
      Type Parameters:
      T - the component type
      Parameters:
      alias - the alias to look up
      type - the expected component type
      Returns:
      an Optional containing the component if found