Interface ParameterConverter<M,R>
-
- Type Parameters:
M- the class of the messages this parameter converter processesR- the class of the result this parameter converter produces
public interface ParameterConverter<M,R>A converter that converts aStringparameter determined from the given message type to the given result type.CDI Beans implementing this interface also need to be annotated with one or multiple
ParameterTypequalifiers that define the parameter type aliases for which the annotated parameter converter works. Without such qualifier the converter will simply never be used. It is an error to have multiple parameter converters with the same parameter type that can be applied to the same framework message type and this will produce an error latest when a parameter with that type is being converted. The only exception are the built-in parameter types. A user-supplied converter with the same parameter type as a built-in converter will be preferred, but it would still be an error to have multiple such overrides for the same type.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Rconvert(String parameter, String type, CommandContext<? extends M> commandContext)Converts the given parameter to the result type.
-
-
-
Method Detail
-
convert
R convert(String parameter, String type, CommandContext<? extends M> commandContext) throws Exception
Converts the given parameter to the result type.nullresults are not permitted and will lead to exceptions at runtime.If the format of the parameter is invalid, for example some text for a number-parsing converter, an
InvalidParameterFormatExceptionwill be thrown. TheparameterNameandparameterValueshould not be set manually, they will automatically be set by the code calling the converter and will override any previously set values. The exception message should be written in a way so that it can be directly presented to the end user.If the value of the parameter is invalid though the format was correct, for example the id of an unknown user, an
InvalidParameterValueExceptionwill be thrown. TheparameterNameandparameterValueshould not be set manually, they will automatically be set by the code calling the converter and will override any previously set values. The exception message should be written in a way so that it can be directly presented to the end user.Any other
Exceptionwill be wrapped by the code calling the converter in aParameterParseExceptionwithparameterNameandparameterValueset unless the thrown exception already is of that type. If aParameterParseExceptionis thrown, theparameterNameandparameterValueshould not be set manually, they will automatically be set by the code calling the converter and will override any previously set values.- Parameters:
parameter- the parameter to converttype- the type of the parameter to convertcommandContext- the command context, usually fully populated but not necessarily- Returns:
- the converted parameter
- Throws:
InvalidParameterFormatException- if the format of the parameter is invalid and could not be parsedInvalidParameterValueException- if the value of the parameter is invalid, e. g. the id of an unknown userException- if there goes anything wrong during parsing
-
-