Clover coverage report - Code Coverage for tapestry release 4.0-beta-12
Coverage timestamp: Sun Oct 30 2005 16:22:01 EST
file stats: LOC: 110   Methods: 6
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ValidatableFieldSupportImpl.java 100% 100% 100% 100%
coverage
 1    // Copyright 2005 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.tapestry.form;
 16   
 17    import java.util.Iterator;
 18   
 19    import org.apache.hivemind.service.ThreadLocale;
 20    import org.apache.tapestry.IMarkupWriter;
 21    import org.apache.tapestry.IRequestCycle;
 22    import org.apache.tapestry.coerce.ValueConverter;
 23    import org.apache.tapestry.form.validator.Validator;
 24    import org.apache.tapestry.valid.ValidatorException;
 25   
 26    /**
 27    * Default {@link VadidatableFieldSupport} implementation. This implementation generates calls to a
 28    * static javascript function during render if client-side validation is enabled.
 29    *
 30    * @author Paul Ferraro
 31    * @since 4.0
 32    */
 33    public class ValidatableFieldSupportImpl implements ValidatableFieldSupport
 34    {
 35    private ValueConverter _converter;
 36   
 37    private ThreadLocale _threadLocale;
 38   
 39  14 public void setValueConverter(ValueConverter converter)
 40    {
 41  14 _converter = converter;
 42    }
 43   
 44  11 public void setThreadLocale(ThreadLocale threadLocale)
 45    {
 46  11 _threadLocale = threadLocale;
 47    }
 48   
 49  26 protected Iterator getValidatorsIterator(ValidatableField component)
 50    {
 51  26 return (Iterator) _converter.coerceValue(component.getValidators(), Iterator.class);
 52    }
 53   
 54    /**
 55    * @see org.apache.tapestry.form.ValidatableFieldSupport#renderValidatorContributions(org.apache.tapestry.form.ValidatableField, org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 56    */
 57  28 public void renderContributions(ValidatableField component, IMarkupWriter writer,
 58    IRequestCycle cycle)
 59    {
 60  28 if (component.getForm().isClientValidationEnabled())
 61    {
 62  2 FormComponentContributorContext context = new FormComponentContributorContextImpl(
 63    _threadLocale.getLocale(), cycle, component);
 64   
 65  2 Iterator validators = getValidatorsIterator(component);
 66   
 67  2 while (validators.hasNext())
 68    {
 69  1 Validator validator = (Validator) validators.next();
 70   
 71  1 validator.renderContribution(writer, cycle, context, component);
 72    }
 73    }
 74    }
 75   
 76    /**
 77    * @see org.apache.tapestry.form.ValidatableFieldSupport#validate(org.apache.tapestry.form.ValidatableField, org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle, java.lang.Object)
 78    */
 79  21 public void validate(ValidatableField component, IMarkupWriter writer, IRequestCycle cycle, Object object) throws ValidatorException
 80    {
 81  21 boolean isNonNull = (object != null);
 82   
 83  21 Iterator validators = getValidatorsIterator(component);
 84   
 85  21 ValidationMessages messages = new ValidationMessagesImpl(component, _threadLocale.getLocale());
 86   
 87  21 while (validators.hasNext())
 88    {
 89  4 Validator validator = (Validator) validators.next();
 90   
 91  4 if (isNonNull || validator.getAcceptsNull())
 92  3 validator.validate(component, messages, object);
 93    }
 94    }
 95   
 96  3 public boolean isRequired(ValidatableField field)
 97    {
 98  3 Iterator i = getValidatorsIterator(field);
 99   
 100  3 while (i.hasNext())
 101    {
 102  2 Validator validator = (Validator) i.next();
 103   
 104  2 if (validator.isRequired())
 105  1 return true;
 106    }
 107   
 108  2 return false;
 109    }
 110    }