Package org.apache.tika.serialization
Class ComponentNameResolver
java.lang.Object
org.apache.tika.serialization.ComponentNameResolver
Utility class that resolves friendly component names to classes using ComponentRegistry.
Supports friendly names like "pdf-parser" as well as fully qualified class names.
Registries must be registered via registerRegistry(String, ComponentRegistry)
before use.
Also stores ComponentConfig registrations for top-level component loading.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> Determines the ParseContext key for a component.static Class<?> findContextKeyInterface(Class<?> type) Finds the appropriate context key interface for a given type.static <T> ComponentConfig<T> getComponentConfig(Class<T> componentClass) Gets component configuration by component class.static Optional<ComponentInfo> getComponentInfo(String name) Gets the component info for a given friendly name.static Class<?> getContextKey(Class<?> clazz) Gets the contextKey for a class from the component registry.Returns the set of interfaces that use compact format serialization.static StringgetFriendlyName(Class<?> clazz) Gets the friendly name for a class, or null if not registered.Explicitly wire-blocked context-key interfaces; complement of the wire allowlist.Wire-instantiable context-key interfaces; seeWIRE_INSTANTIABLE_CONTEXT_KEYS.static booleanhasComponent(String name) Checks if a component with the given name is registered in any registry.static booleanhasImplementationsOf(Class<?> abstractType) Checks if any registered component implements or extends the given abstract type.static booleanisWireBlocked(Class<?> contextKey) True if a wire ParseContext must NOT instantiate this context-key type.static booleanisWireInstantiable(Class<?> contextKey) True if a wire ParseContext may bind this context-key type (default-deny).static <T> voidregisterComponentConfig(ComponentConfig<T> config) Registers a ComponentConfig for top-level component loading.static voidregisterRegistry(String indexName, ComponentRegistry registry) Registers a ComponentRegistry for name resolution.static Class<?> resolveClass(String name, ClassLoader classLoader) Resolves a friendly name (or registered FQCN) to a Class by searching the registered component registries only.static booleanusesCompactFormat(Class<?> type) Checks if a type should use compact format serialization.
-
Method Details
-
registerRegistry
Registers a ComponentRegistry for name resolution.- Parameters:
indexName- the index file name (e.g., "parsers", "detectors")registry- the registry to register
-
resolveClass
public static Class<?> resolveClass(String name, ClassLoader classLoader) throws ClassNotFoundException Resolves a friendly name (or registered FQCN) to a Class by searching the registered component registries only. There is deliberately no Class.forName fallback: unregistered names are rejected for security.- Parameters:
name- friendly name or registered fully qualified class nameclassLoader- unused for resolution; retained for API stability- Returns:
- the resolved class
- Throws:
ClassNotFoundException- if the name is not in any registry
-
getFriendlyName
Gets the friendly name for a class, or null if not registered.- Parameters:
clazz- the class to look up- Returns:
- the friendly name, or null if not found
-
hasComponent
Checks if a component with the given name is registered in any registry.- Parameters:
name- the component name to check- Returns:
- true if the component is registered
-
getComponentInfo
Gets the component info for a given friendly name.- Parameters:
name- the friendly name to look up- Returns:
- Optional containing the ComponentInfo, or empty if not found
-
hasImplementationsOf
Checks if any registered component implements or extends the given abstract type.This is used by TikaModule to determine if an abstract type (interface or abstract class) should use compact component serialization.
- Parameters:
abstractType- the abstract type to check- Returns:
- true if at least one registered component is assignable to this type
-
registerComponentConfig
Registers a ComponentConfig for top-level component loading.- Parameters:
config- the component configuration
-
getComponentConfig
Gets component configuration by component class.- Parameters:
componentClass- the component class (e.g., Parser.class)- Returns:
- the component config, or null if not registered
-
getContextKeyInterfaces
Returns the set of interfaces that use compact format serialization.- Returns:
- unmodifiable set of context key interfaces
-
getWireInstantiableContextKeys
Wire-instantiable context-key interfaces; seeWIRE_INSTANTIABLE_CONTEXT_KEYS. -
isWireInstantiable
True if a wire ParseContext may bind this context-key type (default-deny). -
isWireBlocked
True if a wire ParseContext must NOT instantiate this context-key type. Fail-closed: any context-key interface not on the wire allowlist is blocked, so a newly-added one is refused until consciously allow-listed. Non-component keys (plain config DTOs) are never blocked. -
getWireBlockedContextKeys
Explicitly wire-blocked context-key interfaces; complement of the wire allowlist. -
findContextKeyInterface
Finds the appropriate context key interface for a given type. This is used to determine which interface should be used as the ParseContext key when storing instances of this type.- Parameters:
type- the type to find the context key for- Returns:
- the interface to use as context key, or null if none found
-
usesCompactFormat
Checks if a type should use compact format serialization. Returns true if the type implements any of the registered context key interfaces.- Parameters:
type- the type to check- Returns:
- true if the type uses compact format
-
determineContextKey
Determines the ParseContext key for a component.Resolution order:
- Explicit contextKey from .idx file (via @TikaComponent annotation)
- Auto-detect from implemented interfaces (using CONTEXT_KEY_INTERFACES)
- Fall back to the component class itself
- Parameters:
info- the component info- Returns:
- the class to use as ParseContext key
-
getContextKey
Gets the contextKey for a class from the component registry. The contextKey is recorded in the .idx file by the annotation processor.- Parameters:
clazz- the class to check- Returns:
- the contextKey class if specified, or null if not registered or no contextKey
-