T
- この契約に特化したプロバイダ提供の型public interface Configuration<T extends Configuration<T>>
ValidatorFactory
の構築を行います。
使用方法:
//Validationの自動実行メソッドのひとつから提供される Configuration<?> configuration = ValidatorFactory = configuration .messageInterpolator( new CustomMessageInterpolator() ) .buildValidatorFactory();
デフォルトではMETA-INF/validation.xml
から設定情報が取得されます。
Configuration
のいくつかのメソッドを使用することでXMLファイルから受け取った設定を上書きすることが出来ます。
ValidationProviderResolver
は設定時に指定されます。(ValidationProvider
を参照してください。)
明示的な要求がない場合はデフォルトのValidationProviderResolver
が使用されます。
プロバイダーは次の方法で選択されます。
Validation.byProvider(Class)
を使用してプログラムで特定のプロバイダーが要求された場合、
要求されたプロバイダーのクラスで最初に見つかった実装クラスを使用します。META-INF/validation.xml
で特定のプロバイダーが要求された場合、
要求されたプロバイダーのクラスで最初に見つかった実装クラスを使用します。ValidationProviderResolver
で返された最初のプロバイダーを使用します。実装がスレッドセーフであるとは限りません。
修飾子とタイプ | メソッドと説明 |
---|---|
T |
addMapping(InputStream stream)
Add a stream describing constraint mapping in the Bean Validation XML
format.
|
T |
addProperty(String name,
String value)
Adds a provider specific property.
|
T |
addValueExtractor(ValueExtractor<?> extractor)
Adds a value extractor.
|
ValidatorFactory |
buildValidatorFactory()
Build a
ValidatorFactory implementation. |
T |
clockProvider(ClockProvider clockProvider)
使用される時刻プロバイダーを定義します。
|
T |
constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
使用される制約バリデーターファクトリーを定義します。
|
BootstrapConfiguration |
getBootstrapConfiguration()
Returns configuration information stored in the
META-INF/validation.xml file. |
ClockProvider |
getDefaultClockProvider()
Returns an implementation of the
ClockProvider
interface following the default ClockProvider
defined in the specification:
returns a clock representing the current system time and default time
zone. |
ConstraintValidatorFactory |
getDefaultConstraintValidatorFactory()
Returns an implementation of the
ConstraintValidatorFactory interface
following the default ConstraintValidatorFactory defined in the
specification:
uses the public no-arg constructor of the ConstraintValidator
|
MessageInterpolator |
getDefaultMessageInterpolator()
Returns an implementation of the
MessageInterpolator interface
following the default MessageInterpolator defined in the
specification:
use the ValidationMessages resource bundle to load keys
use Locale.getDefault()
|
ParameterNameProvider |
getDefaultParameterNameProvider()
Returns an implementation of the
ParameterNameProvider
interface following the default ParameterNameProvider
defined in the specification:
returns the actual parameter names as provided in the validated
executable’s definition, if the class file of the executable contains
parameter name information
otherwise returns names in the form arg<PARAMETER_INDEX> ,
where PARAMETER_INDEX starts at 0 for the first parameter,
e.g. |
TraversableResolver |
getDefaultTraversableResolver()
Returns an implementation of the
TraversableResolver interface
following the default TraversableResolver defined in the
specification:
if Java Persistence is available in the runtime environment,
a property is considered reachable if Java Persistence considers
the property as loaded
if Java Persistence is not available in the runtime environment,
all properties are considered reachable
all properties are considered cascadable. |
T |
ignoreXmlConfiguration()
このメソッドを呼び出すことで
META-INF/validation.xml ファイルからのデータを無視します。 |
T |
messageInterpolator(MessageInterpolator interpolator)
使用されるメッセージインターポレーターを定義します。
|
T |
parameterNameProvider(ParameterNameProvider parameterNameProvider)
使用されるパラメーター名プロバイダーを定義します。
|
T |
traversableResolver(TraversableResolver resolver)
使用される横断リゾルバを定義します。
|
T ignoreXmlConfiguration()
META-INF/validation.xml
ファイルからのデータを無視します。
このメソッドは通常、META-INF/validation.xml
自体を解析し、Configuration
のメソッドを介して情報を渡すコンテナで便利です。
this
T messageInterpolator(MessageInterpolator interpolator)
null
が渡された場合、(XML内で定義されたものもしくは仕様のデフォルトによる)デフォルトのメッセージインターセプターが使用されます。
interpolator
- メッセージインターポレーターの実装this
T traversableResolver(TraversableResolver resolver)
null
が渡された場合、(XML内で定義されたものもしくは仕様のデフォルトによる)デフォルトの横断リゾルバが使用されます。
resolver
- 横断リゾルバの実装this
T constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
null
が渡された場合、(XML内で定義されたものもしくは仕様のデフォルトによる)デフォルトの制約バリデーターファクトリーが使用されます。
constraintValidatorFactory
- 制約バリデーターファクトリーの実装this
T parameterNameProvider(ParameterNameProvider parameterNameProvider)
null
が渡された場合、(XML内で定義されたものもしくは仕様のデフォルトによる)デフォルトのパラメーター名プロバイダーが使用されます。
parameterNameProvider
- パラメーター名プロバイダーの実装this
T clockProvider(ClockProvider clockProvider)
null
が渡された場合、(XML内で定義されたものもしくは仕様のデフォルトによる)デフォルトの時刻プロバイダーが使用されます。
clockProvider
- 時刻プロバイダーの実装this
T addValueExtractor(ValueExtractor<?> extractor)
extractor
- 値エクストラクターの実装this
ValueExtractorDeclarationException
- if more than one extractor for
the same type and type parameter is addedT addMapping(InputStream stream)
The stream should be closed by the client API after the
ValidatorFactory
has been built. The Bean Validation provider
must not close the stream.
stream
- XML mapping stream; the given stream should support the
mark/reset contract (see InputStream.markSupported()
);
if it doesn't, it will be wrapped into a stream supporting the
mark/reset contract by the Bean Validation providerthis
IllegalArgumentException
- if stream
is nullT addProperty(String name, String value)
Note: Using this non type-safe method is generally not recommended.
It is more appropriate to use, if available, the type-safe equivalent provided
by a specific provider via its Configuration
subclass.
ValidatorFactory factory = Validation.byProvider(ACMEProvider.class) .configure() .providerSpecificProperty(ACMEState.FAST) .buildValidatorFactory();This method is typically used by containers parsing
META-INF/validation.xml
themselves and injecting the state to the Configuration
object.
If a property with a given name is defined both via this method and in the XML configuration, the value set programmatically has priority.
If null
is passed as a value, the value defined in XML is used. If no value
is defined in XML, the property is considered unset.
name
- property namevalue
- property valuethis
IllegalArgumentException
- if name
is nullMessageInterpolator getDefaultMessageInterpolator()
MessageInterpolator
interface
following the default MessageInterpolator
defined in the
specification:
ValidationMessages
resource bundle to load keysLocale.getDefault()
MessageInterpolator
implementation compliant with the
specificationTraversableResolver getDefaultTraversableResolver()
TraversableResolver
interface
following the default TraversableResolver
defined in the
specification:
TraversableResolver
implementation compliant with the
specificationConstraintValidatorFactory getDefaultConstraintValidatorFactory()
ConstraintValidatorFactory
interface
following the default ConstraintValidatorFactory
defined in the
specification:
ConstraintValidator
ConstraintValidatorFactory
implementation compliant with the
specificationParameterNameProvider getDefaultParameterNameProvider()
ParameterNameProvider
interface following the default ParameterNameProvider
defined in the specification:
arg<PARAMETER_INDEX>
,
where PARAMETER_INDEX
starts at 0 for the first parameter,
e.g. arg0
, arg1
etc.ParameterNameProvider
implementation compliant with
the specificationClockProvider getDefaultClockProvider()
ClockProvider
interface following the default ClockProvider
defined in the specification:
ClockProvider
implementation compliant with
the specificationBootstrapConfiguration getBootstrapConfiguration()
META-INF/validation.xml
file.
Note:
Implementations are encouraged to lazily build this object to delay parsing.
BootstrapConfiguration
; this method never
returns null
; if there is no META-INF/validation.xml
the
different getters of the returned instance will return null
respectively an empty set or mapValidatorFactory buildValidatorFactory()
ValidatorFactory
implementation.ValidatorFactory
ValidationException
- if the ValidatorFactory
cannot be builtCopyright © 2007-2018 Red Hat Inc. All Rights Reserved. Released under the Apache Software License 2.0. Translated by @megascus.