View Javadoc
1   package org.apache.fulcrum.intake.validator;
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 java.math.BigDecimal;
23  import java.util.Locale;
24  
25  
26  /**
27   * Validates BigDecimals with the following constraints in addition to those
28   * listed in NumberValidator and DefaultValidator.
29   *
30   * <table>
31   * <caption>Validation rules</caption>
32   * <tr><th>Name</th><th>Valid Values</th><th>Default Value</th></tr>
33   * <tr><td>minValue</td><td>greater than BigDecimal minValue</td>
34   * <td>&nbsp;</td></tr>
35   * <tr><td>maxValue</td><td>less than BigDecimal maxValue</td>
36   * <td>&nbsp;</td></tr>
37   * <tr><td>invalidNumberMessage</td><td>Some text</td>
38   * <td>Entry was not a valid number</td></tr>
39   * </table>
40   *
41   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
42   * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
43   * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
44   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
45   * @version $Id$
46   */
47  public class BigDecimalValidator
48          extends NumberValidator<BigDecimal>
49  {
50      /**
51       * Default Constructor
52       */
53      public BigDecimalValidator()
54      {
55          super();
56          invalidNumberMessage = "Entry was not a valid BigDecimal";
57      }
58  
59      /**
60       * @see org.apache.fulcrum.intake.validator.NumberValidator#parseNumber(java.lang.String, java.util.Locale)
61       */
62      @Override
63      protected BigDecimal parseNumber(String stringValue, Locale locale) throws NumberFormatException
64      {
65          Number number = parseIntoNumber(stringValue, locale);
66          return new BigDecimal(number.doubleValue());
67      }
68  }