Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-725 Updating bootstrapping chapter
- Loading branch information
1 parent
7d50347
commit 3826741
Showing
11 changed files
with
648 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
761 changes: 422 additions & 339 deletions
761
documentation/src/main/docbook/en-US/modules/bootstrapping.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ion/src/test/java/org/hibernate/validator/referenceguide/chapter08/BootstrappingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.hibernate.validator.referenceguide.chapter08; | ||
|
||
import java.io.InputStream; | ||
import javax.validation.Validation; | ||
import javax.validation.Validator; | ||
import javax.validation.ValidatorFactory; | ||
|
||
import org.hibernate.validator.HibernateValidator; | ||
import org.hibernate.validator.cfg.ConstraintMapping; | ||
|
||
public class BootstrappingTest { | ||
|
||
public void buildDefaultValidatorFactory() { | ||
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void byProvider() { | ||
ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) | ||
.configure() | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void byDefaultProvider() { | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.configure() | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void providerResolver() { | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.providerResolver( new OsgiServiceDiscoverer() ) | ||
.configure() | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void messageInterpolator() { | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.configure() | ||
.messageInterpolator( new MyMessageInterpolator() ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void traversableResolver() { | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.configure() | ||
.traversableResolver( new MyTraversableResolver() ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void constraintValidatorFactory() { | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.configure() | ||
.constraintValidatorFactory( new MyConstraintValidatorFactory() ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void parameterNameProvider() { | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.configure() | ||
.parameterNameProvider( new MyParameterNameProvider() ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void addMapping() { | ||
InputStream constraintMapping1 = null; | ||
InputStream constraintMapping2 = null; | ||
ValidatorFactory validatorFactory = Validation.byDefaultProvider() | ||
.configure() | ||
.addMapping( constraintMapping1 ) | ||
.addMapping( constraintMapping2 ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void providerSpecificOptions() { | ||
ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) | ||
.configure() | ||
.failFast( true ) | ||
.addMapping( (ConstraintMapping) null ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void providerSpecificOptionViaAddProperty() { | ||
ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) | ||
.configure() | ||
.addProperty( "hibernate.validator.fail_fast", "true" ) | ||
.buildValidatorFactory(); | ||
Validator validator = validatorFactory.getValidator(); | ||
} | ||
|
||
public void usingContext() { | ||
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); | ||
|
||
Validator validator = validatorFactory.usingContext() | ||
.messageInterpolator( new MyMessageInterpolator() ) | ||
.traversableResolver( | ||
new MyTraversableResolver() | ||
) | ||
.getValidator(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...t/java/org/hibernate/validator/referenceguide/chapter08/MyConstraintValidatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.hibernate.validator.referenceguide.chapter08; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorFactory; | ||
|
||
public class MyConstraintValidatorFactory implements ConstraintValidatorFactory { | ||
|
||
@Override | ||
public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) { | ||
//... | ||
return null; | ||
} | ||
|
||
@Override | ||
public void releaseInstance(ConstraintValidator<?, ?> instance) { | ||
//... | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/test/java/org/hibernate/validator/referenceguide/chapter08/MyMessageInterpolator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hibernate.validator.referenceguide.chapter08; | ||
|
||
import java.util.Locale; | ||
import javax.validation.MessageInterpolator; | ||
|
||
public class MyMessageInterpolator implements MessageInterpolator { | ||
|
||
@Override | ||
public String interpolate(String messageTemplate, Context context) { | ||
//... | ||
return null; | ||
} | ||
|
||
@Override | ||
public String interpolate(String messageTemplate, Context context, Locale locale) { | ||
//... | ||
return null; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...c/test/java/org/hibernate/validator/referenceguide/chapter08/MyParameterNameProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.hibernate.validator.referenceguide.chapter08; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import javax.validation.ParameterNameProvider; | ||
|
||
public class MyParameterNameProvider implements ParameterNameProvider { | ||
|
||
@Override | ||
public List<String> getParameterNames(Constructor<?> constructor) { | ||
//... | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<String> getParameterNames(Method method) { | ||
//... | ||
return null; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...src/test/java/org/hibernate/validator/referenceguide/chapter08/MyTraversableResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.hibernate.validator.referenceguide.chapter08; | ||
|
||
import java.lang.annotation.ElementType; | ||
import javax.validation.Path; | ||
import javax.validation.Path.Node; | ||
import javax.validation.TraversableResolver; | ||
|
||
public class MyTraversableResolver implements TraversableResolver { | ||
|
||
@Override | ||
public boolean isReachable( | ||
Object traversableObject, | ||
Node traversableProperty, | ||
Class<?> rootBeanType, | ||
Path pathToTraversableObject, | ||
ElementType elementType) { | ||
//... | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isCascadable( | ||
Object traversableObject, | ||
Node traversableProperty, | ||
Class<?> rootBeanType, | ||
Path pathToTraversableObject, | ||
ElementType elementType) { | ||
//... | ||
return false; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...src/test/java/org/hibernate/validator/referenceguide/chapter08/OsgiServiceDiscoverer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.hibernate.validator.referenceguide.chapter08; | ||
|
||
import java.util.List; | ||
import javax.validation.ValidationProviderResolver; | ||
import javax.validation.spi.ValidationProvider; | ||
|
||
public class OsgiServiceDiscoverer implements ValidationProviderResolver { | ||
|
||
@Override | ||
public List<ValidationProvider<?>> getValidationProviders() { | ||
//... | ||
return null; | ||
} | ||
} |