Package org.apache.uima.fit.factory
Class ConfigurationParameterFactory
java.lang.Object
org.apache.uima.fit.factory.ConfigurationParameterFactory
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A simple class for storing an array of configuration parameters along with an array of the values that will fill in those configuration parameters -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addConfigurationParameter
(ResourceCreationSpecifier specifier, String name, Object value) Adds a single configuration parameter name value pair to a specifierstatic void
addConfigurationParameters
(ResourceCreationSpecifier specifier, Class<?>... dynamicallyLoadedClasses) Provides a mechanism to add configuration parameter information to a specifier for the given classes.static void
addConfigurationParameters
(ResourceCreationSpecifier specifier, Object... configurationData) This method adds configuration parameter information to the specifier given the provided configuration datastatic void
addConfigurationParameters
(ResourceCreationSpecifier specifier, List<Class<?>> dynamicallyLoadedClasses) Provides a mechanism to add configuration parameter information to a specifier for the given classes.static boolean
canParameterBeSet
(ResourceSpecifier aSpec, String name) Check if the given parameter can be set on the provided specifier.createConfigurationData
(Class<?> componentClass) This method creates configuration data for a given class definition using reflection and the configuration parameter annotationcreateConfigurationData
(Object... configurationData) This method converts configuration data provided as an array of objects and returns aConfigurationParameterFactory.ConfigurationData
object.static ConfigurationParameter
createPrimitiveParameter
(Field field) A factory method for creating a ConfigurationParameter from a given field definitionstatic ConfigurationParameter
createPrimitiveParameter
(String name, Class<?> parameterClass, String parameterDescription, boolean isMandatory) A factory method for creating a ConfigurationParameter object.static ConfigurationParameter
createPrimitiveParameter
(String name, String parameterType, String parameterDescription, boolean isMultiValued, boolean isMandatory) A factory method for creating a ConfigurationParameter object.static String
This method generates the default name of a configuration parameter that is defined by anConfigurationParameter
annotation when no name is givenstatic Object
getDefaultValue
(Field field) Determines the default value of an annotated configuration parameter.Fetches the parameter settings from the given resource specifier.static boolean
This method determines if the field is annotated withConfigurationParameter
.static void
setParameter
(ResourceSpecifier aSpec, String name, Object value) Sets the specified parameter in the given resource specifier.static void
setParameters
(ResourceCreationSpecifier desc, Class<?> componentClass, ConfigurationParameter[] configurationParameters, Object[] configurationValues) Analyze a component for parameters and default values, merge that with parameter values specified, potentially adding extra parameters.
-
Method Details
-
isConfigurationParameterField
This method determines if the field is annotated withConfigurationParameter
.- Parameters:
field
- the field to analyze- Returns:
- whether the field is marked as a configuration parameter
-
getDefaultValue
Determines the default value of an annotated configuration parameter. The returned value is not necessarily the value that the annotated member variable will be instantiated with in ConfigurationParameterInitializer which does extra work to convert the UIMA configuration parameter value to comply with the type of the member variable.- Parameters:
field
- the field to analyze- Returns:
- the default value
-
getConfigurationParameterName
This method generates the default name of a configuration parameter that is defined by anConfigurationParameter
annotation when no name is given- Parameters:
field
- the field to analyze- Returns:
- the parameter name
-
createPrimitiveParameter
A factory method for creating a ConfigurationParameter from a given field definition- Parameters:
field
- the field to analyze- Returns:
- the configuration parameter.
-
createPrimitiveParameter
public static ConfigurationParameter createPrimitiveParameter(String name, Class<?> parameterClass, String parameterDescription, boolean isMandatory) A factory method for creating a ConfigurationParameter object.- Parameters:
name
- the parameter nameparameterClass
- the parameter classparameterDescription
- the parameter descriptionisMandatory
- whether the parameter is mandatory- Returns:
- the configuration parameter
-
createPrimitiveParameter
public static ConfigurationParameter createPrimitiveParameter(String name, String parameterType, String parameterDescription, boolean isMultiValued, boolean isMandatory) A factory method for creating a ConfigurationParameter object.- Parameters:
name
- the parameter nameparameterType
- the parameter typeparameterDescription
- the parameter descriptionisMultiValued
- whether the parameter is multi-valuedisMandatory
- whether the parameter is mandatory- Returns:
- the configuration parameter
-
setParameters
public static void setParameters(ResourceCreationSpecifier desc, Class<?> componentClass, ConfigurationParameter[] configurationParameters, Object[] configurationValues) Analyze a component for parameters and default values, merge that with parameter values specified, potentially adding extra parameters. Set the merged result into the provided descriptor.- Parameters:
desc
- the descriptor into which to merge the parameterscomponentClass
- the component class which will be analyzed for parameters. Must match the implementationName set in the descriptor.configurationParameters
- additional parameter namesconfigurationValues
- additional parameters values
-
createConfigurationData
public static ConfigurationParameterFactory.ConfigurationData createConfigurationData(Object... configurationData) This method converts configuration data provided as an array of objects and returns aConfigurationParameterFactory.ConfigurationData
object. This should only be used to prepare values supplied in a factory method call for merging with existing parameter declarations, e.g. extracted from a class usingcreateConfigurationData(Class)
.- Parameters:
configurationData
- configuration parameters as (name, value) pairs, so there should always be an even number of parameters.- Returns:
- the configuration data
-
createConfigurationData
public static ConfigurationParameterFactory.ConfigurationData createConfigurationData(Class<?> componentClass) This method creates configuration data for a given class definition using reflection and the configuration parameter annotation- Parameters:
componentClass
- the class to analyze- Returns:
- the configuration settings extracted from the class
-
addConfigurationParameters
public static void addConfigurationParameters(ResourceCreationSpecifier specifier, Object... configurationData) This method adds configuration parameter information to the specifier given the provided configuration data- Parameters:
specifier
- the specified to add the parameters toconfigurationData
- should consist of name value pairs.
-
addConfigurationParameters
public static void addConfigurationParameters(ResourceCreationSpecifier specifier, List<Class<?>> dynamicallyLoadedClasses) Provides a mechanism to add configuration parameter information to a specifier for the given classes. This method may be useful in situations where a class definition has annotated configuration parameters that you want to include in the given specifier.- Parameters:
specifier
- the specified to add the parameters todynamicallyLoadedClasses
- the classes to analyze and extract parameter information from
-
addConfigurationParameters
public static void addConfigurationParameters(ResourceCreationSpecifier specifier, Class<?>... dynamicallyLoadedClasses) Provides a mechanism to add configuration parameter information to a specifier for the given classes. This method may be useful in situations where a class definition has annotated configuration parameters that you want to include in the given specifier- Parameters:
specifier
- the specified to add the parameters todynamicallyLoadedClasses
- the classes to analyze and extract parameter information from
-
addConfigurationParameter
public static void addConfigurationParameter(ResourceCreationSpecifier specifier, String name, Object value) Adds a single configuration parameter name value pair to a specifier- Parameters:
specifier
- the specifier to add the parameter setting toname
- the name of the parametervalue
- the parameter value
-
getParameterSettings
Fetches the parameter settings from the given resource specifier.- Parameters:
spec
- a resource specifier.- Returns:
- the parameter settings.
-
setParameter
Sets the specified parameter in the given resource specifier. If the specified is aCustomResourceSpecifier
an exception is thrown if the parameter value not a String.- Parameters:
aSpec
- a resource specifier.name
- the parameter name.value
- the parameter value.- Throws:
IllegalArgumentException
- if the value is not of a supported type for the given specifier.
-
canParameterBeSet
Check if the given parameter can be set on the provided specifier. Some specifier types require parameters to be declared before they can be set.- Parameters:
aSpec
- the specifier to testname
- the parameter to be tested- Returns:
- if the parameter can be set
-