Coverage report

  %line %branch
org.apache.turbine.services.intake.model.ShortField
0% 
0% 

 1  
 package org.apache.turbine.services.intake.model;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 
 21  
 import org.apache.turbine.services.intake.IntakeException;
 22  
 import org.apache.turbine.services.intake.validator.ShortValidator;
 23  
 import org.apache.turbine.services.intake.xmlmodel.XmlField;
 24  
 
 25  
 /**
 26  
  * Processor for short fields.
 27  
  *
 28  
  * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
 29  
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
 30  
  * @version $Id: ShortField.java 264148 2005-08-29 14:21:04Z henning $
 31  
  */
 32  
 public class ShortField
 33  
         extends Field
 34  
 {
 35  
     /**
 36  
      * Constructor.
 37  
      *
 38  
      * @param field xml field definition object
 39  
      * @param group xml group definition object
 40  
      * @throws IntakeException thrown by superclass
 41  
      */
 42  
     public ShortField(XmlField field, Group group)
 43  
             throws IntakeException
 44  
     {
 45  0
         super(field, group);
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Sets the default value for an Short Field
 50  
      *
 51  
      * @param prop Parameter for the default values
 52  
      */
 53  
     public void setDefaultValue(String prop)
 54  
     {
 55  0
         defaultValue = null;
 56  
 
 57  0
         if (prop == null)
 58  
         {
 59  0
             return;
 60  
         }
 61  
 
 62  0
         defaultValue = new Short(prop);
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Set the empty Value. This value is used if Intake
 67  
      * maps a field to a parameter returned by the user and
 68  
      * the corresponding field is either empty (empty string)
 69  
      * or non-existant.
 70  
      *
 71  
      * @param prop The value to use if the field is empty.
 72  
      */
 73  
     public void setEmptyValue(String prop)
 74  
     {
 75  0
         emptyValue = null;
 76  
 
 77  0
         if (prop == null)
 78  
         {
 79  0
             return;
 80  
         }
 81  
 
 82  0
         emptyValue = new Short(prop);
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Provides access to emptyValue such that the value returned will be
 87  
      * acceptable as an argument parameter to Method.invoke.  Subclasses
 88  
      * that deal with primitive types should ensure that they return an
 89  
      * appropriate value wrapped in the object wrapper class for the
 90  
      * primitive type.
 91  
      *
 92  
      * @return the value to use when the field is empty or an Object that
 93  
      * wraps the empty value for primitive types.
 94  
      */
 95  
     protected Object getSafeEmptyValue()
 96  
     {
 97  0
         if (isMultiValued)
 98  
         {
 99  0
             return new short[0];
 100  
         }
 101  
         else
 102  
         {
 103  0
             return (null == getEmptyValue())
 104  
                     ? new Short((short) 0) : getEmptyValue();
 105  
         }
 106  
     }
 107  
 
 108  
     /**
 109  
      * A suitable validator.
 110  
      *
 111  
      * @return A suitable validator
 112  
      */
 113  
     protected String getDefaultValidator()
 114  
     {
 115  0
         return ShortValidator.class.getName();
 116  
     }
 117  
 
 118  
     /**
 119  
      * Sets the value of the field from data in the parser.
 120  
      */
 121  
     protected void doSetValue()
 122  
     {
 123  0
         if (isMultiValued)
 124  
         {
 125  0
             String[] inputs = parser.getStrings(getKey());
 126  0
             short[] values = new class="keyword">short[inputs.length];
 127  0
             for (int i = 0; i < inputs.length; i++)
 128  
             {
 129  0
                 values[i] = StringUtils.isNotEmpty(inputs[i])
 130  
                         ? new Short(inputs[i]).shortValue()
 131  
                         : ((Short) getEmptyValue()).shortValue();
 132  
             }
 133  0
             setTestValue(values);
 134  
         }
 135  
         else
 136  
         {
 137  0
             String val = parser.getString(getKey());
 138  0
             setTestValue(StringUtils.isNotEmpty(val)
 139  
                     ? new Short(val) : (Short) getEmptyValue());
 140  
         }
 141  0
     }
 142  
 
 143  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.