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 aString
parameter 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
ParameterType
qualifiers 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 R
convert(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.null
results 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
InvalidParameterFormatException
will be thrown. TheparameterName
andparameterValue
should 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
InvalidParameterValueException
will be thrown. TheparameterName
andparameterValue
should 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
Exception
will be wrapped by the code calling the converter in aParameterParseException
withparameterName
andparameterValue
set unless the thrown exception already is of that type. If aParameterParseException
is thrown, theparameterName
andparameterValue
should 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
-
-