1 | |
package org.apache.onami.validation; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import static com.google.inject.matcher.Matchers.annotatedWith; |
23 | |
import static com.google.inject.matcher.Matchers.any; |
24 | |
|
25 | |
import javax.inject.Singleton; |
26 | |
import javax.validation.ConstraintValidatorFactory; |
27 | |
import javax.validation.MessageInterpolator; |
28 | |
import javax.validation.TraversableResolver; |
29 | |
import javax.validation.Validator; |
30 | |
import javax.validation.ValidatorFactory; |
31 | |
import javax.validation.spi.ConfigurationState; |
32 | |
import javax.validation.spi.ValidationProvider; |
33 | |
|
34 | |
import org.aopalliance.intercept.MethodInterceptor; |
35 | |
import org.apache.bval.jsr303.ApacheValidationProvider; |
36 | |
import org.apache.bval.jsr303.DefaultMessageInterpolator; |
37 | |
import org.apache.bval.jsr303.resolver.DefaultTraversableResolver; |
38 | |
import org.kohsuke.MetaInfServices; |
39 | |
|
40 | |
import com.google.inject.AbstractModule; |
41 | |
import com.google.inject.Module; |
42 | |
import com.google.inject.TypeLiteral; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@MetaInfServices( Module.class ) |
48 | 1 | public final class ValidationModule |
49 | |
extends AbstractModule |
50 | |
{ |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
@Override |
56 | |
protected void configure() |
57 | |
{ |
58 | |
|
59 | 1 | bind( MessageInterpolator.class ).to( DefaultMessageInterpolator.class ).in( Singleton.class ); |
60 | 1 | bind( TraversableResolver.class ).to( DefaultTraversableResolver.class ).in( Singleton.class ); |
61 | 1 | bind( ConstraintValidatorFactory.class ).to( GuiceAwareConstraintValidatorFactory.class ); |
62 | 1 | bind( new TypeLiteral<ValidationProvider<?>>(){} ).to( ApacheValidationProvider.class ).in( Singleton.class ); |
63 | 1 | bind( ConfigurationState.class ).toProvider( ConfigurationStateProvider.class ).in( Singleton.class ); |
64 | 1 | bind( ValidatorFactory.class ).toProvider( ValidatorFactoryProvider.class ).in( Singleton.class ); |
65 | 1 | bind( Validator.class ).toProvider( ValidatorProvider.class ); |
66 | |
|
67 | |
|
68 | 1 | MethodInterceptor validateMethodInterceptor = new ValidateMethodInterceptor(); |
69 | 1 | requestInjection( validateMethodInterceptor ); |
70 | 1 | bindInterceptor( any(), annotatedWith( Validate.class ), validateMethodInterceptor ); |
71 | 1 | } |
72 | |
|
73 | |
} |