Coverage Report - net.sf.beanform.validator.StringMax
 
Classes in this File Line Coverage Branch Coverage Complexity
StringMax
100% 
100% 
0
 
 1  
 // Copyright 2006 Daniel Gredler
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package net.sf.beanform.validator;
 16  
 
 17  
 import org.apache.tapestry.form.IFormComponent;
 18  
 import org.apache.tapestry.form.ValidationMessages;
 19  
 import org.apache.tapestry.form.validator.Max;
 20  
 import org.apache.tapestry.valid.ValidatorException;
 21  
 
 22  
 /**
 23  
  * Subclass of the {@link Max} validator that doesn't barf all over the
 24  
  * place if it's handed a string instead of a number. Apparently Tapestry
 25  
  * normally does some automatic type conversions depending on a value's
 26  
  * setter and getter, but our setters and getters are for generic objects.
 27  
  *
 28  
  * @author Daniel Gredler
 29  
  */
 30  
 public class StringMax extends Max {
 31  
 
 32  
     public final static String NAME = "smax";
 33  
 
 34  
     public StringMax() {
 35  9
         super();
 36  9
     }
 37  
 
 38  
     public StringMax( String initializer ) {
 39  4
         super( initializer );
 40  4
     }
 41  
 
 42  
     @Override
 43  
     public void validate( IFormComponent field, ValidationMessages messages, Object object )
 44  
     throws ValidatorException {
 45  4
         if( object instanceof String ) {
 46  2
             object = Double.parseDouble( (String) object );
 47  
         }
 48  4
         super.validate( field, messages, object );
 49  2
     }
 50  
 
 51  
     public void setSmax( double smax ) {
 52  4
         super.setMax( smax );
 53  4
     }
 54  
 
 55  
 }