Coverage Report - net.sf.echobinding.binding.AbstractPropertyAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractPropertyAdapter
100%
40/40
N/A
0
 
 1  
 /**
 2  
  * Copyright (C) 2006 Philipp Mpalampanis
 3  
  *
 4  
  * License: MPL 1.1/GPL 2.0/LGPL 2.1
 5  
  *
 6  
  * The contents of this file are subject to the Mozilla Public License Version
 7  
  * 1.1 (the "License"); you may not use this file except in compliance with
 8  
  * the License. You may obtain a copy of the License at
 9  
  * http://www.mozilla.org/MPL/
 10  
  *
 11  
  * Software distributed under the License is distributed on an "AS IS" basis,
 12  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 13  
  * for the specific language governing rights and limitations under the
 14  
  * License.
 15  
  *
 16  
  * Alternatively, the contents of this file may be used under the terms of
 17  
  * either the GNU General Public License Version 2 or later (the "GPL"), or
 18  
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 19  
  * in which case the provisions of the GPL or the LGPL are applicable instead
 20  
  * of those above. If you wish to allow use of your version of this file only
 21  
  * under the terms of either the GPL or the LGPL, and not to allow others to
 22  
  * use your version of this file under the terms of the MPL, indicate your
 23  
  * decision by deleting the provisions above and replace them with the notice
 24  
  * and other provisions required by the GPL or the LGPL. If you do not delete
 25  
  * the provisions above, a recipient may use your version of this file under
 26  
  * the terms of any one of the MPL, the GPL or the LGPL.
 27  
  */
 28  
 package net.sf.echobinding.binding;
 29  
 
 30  
 import java.util.HashSet;
 31  
 import java.util.Set;
 32  
 
 33  
 import net.sf.echobinding.decorator.Decorator;
 34  
 import net.sf.echobinding.decorator.DefaultDecorator;
 35  
 import net.sf.echobinding.format.Format;
 36  
 import net.sf.echobinding.validation.*;
 37  
 
 38  
 /**
 39  
  * @see net.sf.echobinding.binding.PropertyAdapter
 40  
  */
 41  82
 public abstract class AbstractPropertyAdapter implements PropertyAdapter {
 42  
 
 43  
         private Set<Validator> _validators;
 44  
         private Format _format;
 45  
         private Decorator _decorator;
 46  
         private String _label;
 47  
         private String _id;
 48  
         private ValidationHandler _validationHandler;
 49  
         private BindingContext _subContext;
 50  
 
 51  
         protected Object format(Object value) {
 52  161
                 if(getFormat()!=null)
 53  4
                         return getFormat().format(value);
 54  157
                 return value;
 55  
         }
 56  
 
 57  
         protected Object parse(Object value) {
 58  75
                 if(getFormat()!=null)
 59  1
                         return getFormat().parse((String)value);
 60  74
                 return value;
 61  
         }
 62  
 
 63  
         public ValidationReport validate(Object bean, Object value) {
 64  
                 
 65  55
                 ValidationReport validationReport = new ValidationReport(true, null);
 66  
                 
 67  55
                 if(getValidators()!=null) {
 68  14
                         for(Validator validator : getValidators() ) {
 69  6
                                 validationReport = validator.validate( bean, parse( value ) );
 70  6
                                 if(validationReport != null && !validationReport.isValid())
 71  4
                                         return validationReport;
 72  
                         }                
 73  
                 }
 74  
                 // no validator specified or input passed validation test
 75  51
                 return validationReport;         
 76  
         }
 77  
 
 78  
 
 79  
         public PropertyAdapter setValidators(Set<Validator> validators) {
 80  2
                 _validators = validators;
 81  2
                 return this;
 82  
         }
 83  
 
 84  
         public PropertyAdapter addValidator(Validator validator) {
 85  2
                 if(_validators==null)
 86  2
                         _validators = new HashSet<Validator>();
 87  2
                 _validators.add(validator);
 88  2
                 return this;
 89  
         }
 90  
 
 91  
         public PropertyAdapter setFormat(Format format) {
 92  4
                 _format = format;
 93  4
                 return this;
 94  
         }
 95  
 
 96  
         public PropertyAdapter setDecorator(Decorator decorator) {
 97  2
                 _decorator = decorator;
 98  2
                 return this;
 99  
         }
 100  
 
 101  
         public Decorator getDecorator() {
 102  6
                 if(_decorator == null)
 103  6
                         return new DefaultDecorator();
 104  
                 return _decorator;
 105  
         }
 106  
 
 107  
         public String getLabel() {
 108  2
                 return _label;
 109  
         }
 110  
 
 111  
 
 112  
         public PropertyAdapter setLabel(String label) {
 113  3
                 _label = label;
 114  3
                 return this;
 115  
         }
 116  
 
 117  
         public String getId() {
 118  2
                 return _id;
 119  
         }
 120  
 
 121  
         public PropertyAdapter setId(String id) {
 122  67
                 _id = id;
 123  67
                 return this;
 124  
         }
 125  
 
 126  
         public Format getFormat() {
 127  243
                 return _format;
 128  
         }
 129  
 
 130  
         /**
 131  
          * @return Returns the validator.
 132  
          */
 133  
         public Set<Validator> getValidators() {
 134  63
                 return _validators;
 135  
         }
 136  
 
 137  
         public PropertyAdapter setValidationHandler(ValidationHandler validationHandler) {
 138  2
                 _validationHandler = validationHandler;
 139  2
                 return this;
 140  
         }
 141  
 
 142  
         public ValidationHandler getValidationHandler() {
 143  6
                 return _validationHandler;
 144  
         }
 145  
 
 146  
         public PropertyAdapter setSubContext(BindingContext context) {
 147  2
                 _subContext = context;
 148  2
                 return this;
 149  
         }
 150  
 
 151  
         public BindingContext getSubContext() {
 152  2
                 return _subContext;
 153  
         }
 154  
 
 155  
 }