Coverage Report - org.apache.tapestry5.internal.translator.NumericTranslator
 
Classes in this File Line Coverage Branch Coverage Complexity
NumericTranslator
100%
11/11
100%
2/2
0
 
 1  
 // Copyright 2009 The Apache Software Foundation
 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 org.apache.tapestry5.internal.translator;
 16  
 
 17  
 import org.apache.tapestry5.Field;
 18  
 import org.apache.tapestry5.MarkupWriter;
 19  
 import org.apache.tapestry5.ValidationException;
 20  
 import org.apache.tapestry5.services.FormSupport;
 21  
 
 22  
 import java.text.ParseException;
 23  
 
 24  
 /**
 25  
  * Uses a {@link org.apache.tapestry5.internal.translator.NumericTranslatorSupport} to provide proper locale-aware
 26  
  * support for all the built-in numeric types.
 27  
  *
 28  
  * @since 5.1.0.1
 29  
  */
 30  162
 public class NumericTranslator<T extends Number> extends AbstractTranslator<T>
 31  
 {
 32  
     private final NumericTranslatorSupport support;
 33  
 
 34  
     public NumericTranslator(String name, Class<T> type, NumericTranslatorSupport support)
 35  
     {
 36  144
         super(name, type, support.getMessageKey(type));
 37  
 
 38  144
         this.support = support;
 39  144
     }
 40  
 
 41  
     public void render(Field field, String message, MarkupWriter writer, FormSupport formSupport)
 42  
     {
 43  102
         if (formSupport.isClientValidationEnabled())
 44  72
             support.addValidation(getType(), field, message);
 45  102
     }
 46  
 
 47  
     public T parseClient(Field field, String clientValue, String message) throws ValidationException
 48  
     {
 49  
         try
 50  
         {
 51  74
             return support.parseClient(getType(), clientValue);
 52  
         }
 53  14
         catch (ParseException ex)
 54  
         {
 55  14
             throw new ValidationException(message);
 56  
         }
 57  
     }
 58  
 
 59  
     public String toClient(T value)
 60  
     {
 61  88
         return support.toClient(getType(), value);
 62  
     }
 63  
 }