注釈型 RequireMatch
@Documented @Target(FIELD) @Retention(RUNTIME) public @interface RequireMatch
expression()
or
presetExpression()
.
Several regular expression presets have already been defined as
RegexPreset
for this annotation. If you want to use a regular
expression preset, specify the RegexPreset
element for
presetExpression()
. The regular expression can also be specified as
an arbitrary string instead of RegexPreset
. To specify an arbitrary
regular expression, specify a regular expression literal for
expression()
. If a regular expression preset and a regular
expression literal are specified in the same annotation at the same time,
like @RequireMatch(expression =
"\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", presetExpression =
RegexPreset.EMAIL_ADDRESS)
, presetExpression()
and
RegexPreset
will be used preferentially in the validation process.
This annotation validation process provides several methods for applying
regular expressions as RegexMethod
. Each of them provides
RegexMethod.FIND
, RegexMethod.LOOKING_AT
and
RegexMethod.MATCHES
methods, and the specification is similar to that
of Matcher class which is widely known in Java. By specifying
RegexMethod
element in the annotation, like
@RequireMatch(method = RegexMethod.MATCHES)
, the regular
expression will be applied in the specified method during the validation
process.
You can specify any modifier flag by specifying RegexModifier
to the
annotation like @RequireMatch(modifiers =
{RegexModifier.UNIX_LINES, RegexModifier.DOTALL})
.
If this annotation is specified for an object of type other than String, UnsupportedOperationException will always be thrown at runtime.
Specify the expected value for Content Framework:
@ParameterMapping( content = "Parameter" )
public class ConcreteEntity implements ValidatableEntity, Serializable {
@RequireMatch
private String literal;
@RequireMatch( method = RegexMethod.MATCHES, errorType = ErrorType.UNRECOVERABLE, message = "failed!" )
private String unrecoverableLiteral;
}
Specify the expected value for the annotation:
public class ConcreteEntity implements ValidatableEntity, Serializable {
@RequireMatch( presetExpression = RegexPreset.EMAIL_ADDRESS )
private String literalWithRegexPreset;
@RequireMatch( expression = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*" )
private String literalWithSpesifiedExpression;
@RequireMatch( presetExpression = RegexPreset.EMAIL_ADDRESS, method = RegexMethod.MATCHES )
private String literalWithMatchesMethod;
@RequireMatch( presetExpression = RegexPreset.EMAIL_ADDRESS, method = RegexMethod.LOOKING_AT, errorType = ErrorType.RECOVERABLE, message = "failed!" )
private String recoverableLiteral;
}
- 導入されたバージョン:
- 1.0.2
-
任意要素の概要
任意要素 修飾子とタイプ 任意要素 説明 ErrorType
errorType
Returns the error type based onErrorType
, andErrorType.RUNTIME
is set as the default.String
expression
Returns the regular expression ofString
data type, and empty (""
) is set as the default.String
message
Returns the error type based onErrorType
, and empty (""
) is set as the default.RegexMethod
method
Returns the method used to apply regular expression based onRegexMethod
, andRegexMethod.MATCHES
is set as the default.RegexModifier[]
modifiers
Returns the array of regex modifiers based onRegexModifier
, and an enmpty array is set as the default.RegexPreset
presetExpression
Returns the preset of regular expression based onRegexPreset
, andRegexPreset.NONE
is set as the default.
-
要素の詳細
-
errorType
ErrorType errorTypeReturns the error type based onErrorType
, andErrorType.RUNTIME
is set as the default.- 戻り値:
- The error type based on the
ErrorType
- デフォルト:
- RUNTIME
-
message
String messageReturns the error type based onErrorType
, and empty (""
) is set as the default.- 戻り値:
- The message
- デフォルト:
- ""
-
expression
String expressionReturns the regular expression ofString
data type, and empty (""
) is set as the default.- 戻り値:
- The regular expression
- デフォルト:
- ""
-
presetExpression
RegexPreset presetExpressionReturns the preset of regular expression based onRegexPreset
, andRegexPreset.NONE
is set as the default.- 戻り値:
- The preset of regular expression based on
RegexPreset
- デフォルト:
- NONE
-
modifiers
RegexModifier[] modifiersReturns the array of regex modifiers based onRegexModifier
, and an enmpty array is set as the default.- 戻り値:
- The array of regex modifiers based on
RegexModifier
- デフォルト:
- {}
-
method
RegexMethod methodReturns the method used to apply regular expression based onRegexMethod
, andRegexMethod.MATCHES
is set as the default.- 戻り値:
- The method used to apply regular expression based on
RegexMethod
- デフォルト:
- MATCHES
-