View Javadoc

1   package org.apache.onami.validation;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.inject.Inject;
23  import javax.inject.Provider;
24  import javax.inject.Singleton;
25  import javax.validation.ConstraintValidatorFactory;
26  import javax.validation.MessageInterpolator;
27  import javax.validation.TraversableResolver;
28  import javax.validation.spi.BootstrapState;
29  import javax.validation.spi.ConfigurationState;
30  import javax.validation.spi.ValidationProvider;
31  
32  import org.apache.bval.jsr303.ConfigurationImpl;
33  
34  /**
35   * The {@code javax.validation.spi.ConfigurationState} provider implementation.
36   */
37  @Singleton
38  final class ConfigurationStateProvider
39      implements Provider<ConfigurationState>
40  {
41  
42      @com.google.inject.Inject( optional = true )
43      private BootstrapState bootstrapState;
44  
45      private final ValidationProvider<?> validationProvider;
46  
47      private final TraversableResolver traversableResolver;
48  
49      private final MessageInterpolator messageInterpolator;
50  
51      private final ConstraintValidatorFactory constraintValidatorFactory;
52  
53      @Inject
54      public ConfigurationStateProvider( ValidationProvider<?> validationProvider,
55  			TraversableResolver traversableResolver,
56  			MessageInterpolator messageInterpolator,
57  			ConstraintValidatorFactory constraintValidatorFactory )
58      {
59  		this.validationProvider = validationProvider;
60  		this.traversableResolver = traversableResolver;
61  		this.messageInterpolator = messageInterpolator;
62  		this.constraintValidatorFactory = constraintValidatorFactory;
63  	}
64  
65      /**
66       * {@inheritDoc}
67       */
68      public ConfigurationState get()
69      {
70          ConfigurationImpl configuration = new ConfigurationImpl( bootstrapState, validationProvider );
71          configuration.traversableResolver( traversableResolver );
72          configuration.messageInterpolator( messageInterpolator );
73          configuration.constraintValidatorFactory( constraintValidatorFactory );
74          return configuration;
75      }
76  
77  }