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 ComponentConfig<?>getComponentConfig(String jsonField) Gets component configuration by JSON field name.Gets all registered component JSON field names.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.static booleanhasComponent(String name) Checks if a component with the given name is registered in any registry.static booleanhasComponentConfig(Class<?> componentClass) Checks if a component config is registered for the given class.static booleanhasComponentConfig(String jsonField) Checks if a component config is registered for the given JSON field.static booleanhasImplementationsOf(Class<?> abstractType) Checks if any registered component implements or extends the given abstract type.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 FQCN to a Class.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 FQCN to a Class. Searches all registered component registries, falling back to Class.forName.- Parameters:
name- friendly name or fully qualified class nameclassLoader- the class loader to use for FQCN fallback- Returns:
- the resolved class
- Throws:
ClassNotFoundException- if not found in any registry and not a valid FQCN
-
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 JSON field name.- Parameters:
jsonField- the JSON field name (e.g., "parsers")- Returns:
- the component config, or null if not registered
-
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
-
hasComponentConfig
Checks if a component config is registered for the given JSON field. -
hasComponentConfig
Checks if a component config is registered for the given class. -
getComponentFields
Gets all registered component JSON field names. -
getContextKeyInterfaces
Returns the set of interfaces that use compact format serialization.- Returns:
- unmodifiable set of context key interfaces
-
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
-