View Javadoc

1   /*
2    * Copyright 2004-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springmodules.validation.bean.conf.loader.xml;
18  
19  import org.springmodules.validation.bean.conf.loader.xml.handler.*;
20  import org.springmodules.validation.bean.conf.loader.xml.handler.jodatime.InstantInFutureRuleElementHandler;
21  import org.springmodules.validation.bean.conf.loader.xml.handler.jodatime.InstantInPastRuleElementHandler;
22  import org.springmodules.validation.util.LibraryUtils;
23  
24  /**
25   * A {@link SimpleValidationRuleElementHandlerRegistry} that already registers the following default element handlers:
26   * <p/>
27   * <ol>
28   * <li>{@link NotNullRuleElementHandler}</li>
29   * <li>{@link LengthRuleElementHandler}</li>
30   * <li>{@link NotBlankRuleElementHandler}</li>
31   * <li>{@link EmailRuleElementHandler}</li>
32   * <li>{@link RegExpRuleElementHandler}</li>
33   * <li>{@link SizeRuleElementHandler}</li>
34   * <li>{@link NotEmptyRuleElementHandler}</li>
35   * <li>{@link NotBlankRuleElementHandler}</li>
36   * <li>{@link RangeRuleElementHandler}</li>
37   * <li>{@link ExpressionPropertyValidationElementHandler}</li>
38   * <li>{@link DateInPastRuleElementHandler}</li>
39   * <li>{@link DateInFutureRuleElementHandler}</li> *
40   * <li>{@link InstantInFutureRuleElementHandler} (only if joda-time library is available in the classpath)</li> *
41   * <li>{@link InstantInPastRuleElementHandler} (only if joda-time library is available in the classpath)</li> *
42   * </ol>
43   *
44   * @author Uri Boness
45   */
46  public class DefaultValidationRuleElementHandlerRegistry extends SimpleValidationRuleElementHandlerRegistry {
47  
48      /**
49       * Constructs a new DefaultValidationRuleElementHandlerRegistry with the default handlers.
50       */
51      public DefaultValidationRuleElementHandlerRegistry() {
52  
53          String namepsaceUri = DefaultXmlBeanValidationConfigurationLoader.DEFAULT_NAMESPACE_URL;
54  
55          // registering class handlers
56          registerClassHandler(new ExpressionClassValidationElementHandler(namepsaceUri));
57  
58          // registering property handlers
59          registerPropertyHandler(new NotNullRuleElementHandler(namepsaceUri));
60          registerPropertyHandler(new LengthRuleElementHandler(namepsaceUri));
61          registerPropertyHandler(new EmailRuleElementHandler(namepsaceUri));
62          registerPropertyHandler(new RegExpRuleElementHandler(namepsaceUri));
63          registerPropertyHandler(new SizeRuleElementHandler(namepsaceUri));
64          registerPropertyHandler(new NotEmptyRuleElementHandler(namepsaceUri));
65          registerPropertyHandler(new NotBlankRuleElementHandler(namepsaceUri));
66          registerPropertyHandler(new RangeRuleElementHandler(namepsaceUri));
67          registerPropertyHandler(new ExpressionPropertyValidationElementHandler(namepsaceUri));
68          registerPropertyHandler(new DateInPastRuleElementHandler(namepsaceUri));
69          registerPropertyHandler(new DateInFutureRuleElementHandler(namepsaceUri));
70          registerPropertyHandler(new ConditionReferenceRuleElementHandler(namepsaceUri));
71          if (LibraryUtils.JODA_TIME_IN_CLASSPATH) {
72              registerPropertyHandler(new InstantInPastRuleElementHandler(namepsaceUri));
73              registerPropertyHandler(new InstantInFutureRuleElementHandler(namepsaceUri));
74          }
75      }
76  
77  }