Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 283   Methods: 23
NCLOC: 109   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LabeledPropertySelectionModel.java 100% 67.9% 60.9% 70.5%
coverage coverage
 1    // Copyright 2004, 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    /**
 18    * Decorates an underlying {@link IPropertySelectionModel}adding an initial property. The label,
 19    * option, and value of the initial property are configurable.
 20    *
 21    * @author Paul Ferraro
 22    * @since 4.0
 23    */
 24    public class LabeledPropertySelectionModel implements IPropertySelectionModel
 25    {
 26    private IPropertySelectionModel _model;
 27   
 28    private String _label = "";
 29   
 30    private Object _option = null;
 31   
 32    private String _value = "";
 33   
 34    /**
 35    * Constructs a new LabeledPropertySelectionModel using an empty model and default label,
 36    * option, and value. Default constructor is made available so that this model may be specified
 37    * as a component helper bean.
 38    */
 39  2 public LabeledPropertySelectionModel()
 40    {
 41  2 this(EMPTY_MODEL);
 42    }
 43   
 44    /**
 45    * Constructs a new LabeledPropertySelectionModel using the specified model and default label,
 46    * option, and value.
 47    *
 48    * @param model
 49    * the underlying model to decorate
 50    */
 51  4 public LabeledPropertySelectionModel(IPropertySelectionModel model)
 52    {
 53  4 _model = model;
 54    }
 55   
 56    /**
 57    * Constructs a new LabeledPropertySelectionModel using the specified model and label, and
 58    * default option and value.
 59    *
 60    * @param model
 61    * the underlying model to decorate
 62    * @param label
 63    * the label of the initial property
 64    */
 65  1 public LabeledPropertySelectionModel(IPropertySelectionModel model, String label)
 66    {
 67  1 this(model);
 68   
 69  1 _label = label;
 70    }
 71   
 72    /**
 73    * Constructs a new LabeledPropertySelectionModel using the specified model, label, and option;
 74    * and default value.
 75    *
 76    * @param model
 77    * the underlying model to decorate
 78    * @param label
 79    * the label of the initial property
 80    * @param option
 81    * the option value of the initial property
 82    */
 83  1 public LabeledPropertySelectionModel(IPropertySelectionModel model, String label, Object option)
 84    {
 85  1 this(model, label);
 86   
 87  1 _option = option;
 88    }
 89   
 90    /**
 91    * Constructs a new LabeledPropertySelectionModel using the specified model, label, option, and
 92    * value.
 93    *
 94    * @param model
 95    * the underlying model to decorate
 96    * @param label
 97    * the label of the initial property
 98    * @param option
 99    * the option value of the initial property
 100    * @param value
 101    * the value of the initial property
 102    */
 103  1 public LabeledPropertySelectionModel(IPropertySelectionModel model, String label,
 104    Object option, String value)
 105    {
 106  1 this(model, label, option);
 107   
 108  1 _value = value;
 109    }
 110   
 111    /**
 112    * Returns the underlying IPropertySelectionModel
 113    *
 114    * @return the underlying IPropertySelectionModel
 115    */
 116  0 public IPropertySelectionModel getModel()
 117    {
 118  0 return _model;
 119    }
 120   
 121    /**
 122    * Sets the underlying IPropertySelectionModel
 123    *
 124    * @param model
 125    * the IPropertySelectionModel to set
 126    */
 127  0 public void setModel(IPropertySelectionModel model)
 128    {
 129  0 _model = model;
 130    }
 131   
 132    /**
 133    * @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
 134    */
 135  6 public int getOptionCount()
 136    {
 137  6 return _model.getOptionCount() + 1;
 138    }
 139   
 140    /**
 141    * @see org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
 142    */
 143  7 public Object getOption(int index)
 144    {
 145  7 return (index == 0) ? _option : _model.getOption(index - 1);
 146    }
 147   
 148    /**
 149    * @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
 150    */
 151  7 public String getLabel(int index)
 152    {
 153  7 return (index == 0) ? _label : _model.getLabel(index - 1);
 154    }
 155   
 156    /**
 157    * @see org.apache.tapestry.form.IPropertySelectionModel#getValue(int)
 158    */
 159  7 public String getValue(int index)
 160    {
 161  7 return (index == 0) ? _value : _model.getValue(index - 1);
 162    }
 163   
 164    /**
 165    * @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
 166    */
 167  8 public Object translateValue(String value)
 168    {
 169  8 if (value == null)
 170  1 return null;
 171   
 172  7 return value.equals(_value) ? _option : _model.translateValue(value);
 173    }
 174   
 175    /**
 176    * Returns the label of the initial IPropertySelectionModel option
 177    *
 178    * @return a IPropertySelectionModel option label
 179    */
 180  1 public String getLabel()
 181    {
 182  1 return _label;
 183    }
 184   
 185    /**
 186    * Sets the label of the initial IPropertySelectionModel option
 187    *
 188    * @param label
 189    * a IPropertySelectionModel option label
 190    */
 191  0 public void setLabel(String label)
 192    {
 193  0 _label = label;
 194    }
 195   
 196    /**
 197    * Returns the value of the initial IPropertySelectionModel option
 198    *
 199    * @return a IPropertySelectionModel option value
 200    */
 201  1 public String getValue()
 202    {
 203  1 return _value;
 204    }
 205   
 206    /**
 207    * Sets the value of the initial IPropertySelectionModel option
 208    *
 209    * @param value
 210    * a IPropertySelectionModel option value
 211    */
 212  0 public void setValue(String value)
 213    {
 214  0 _value = value;
 215    }
 216   
 217    /**
 218    * Returns the initial option
 219    *
 220    * @return a PropertySelectionModel option
 221    */
 222  1 public Object getOption()
 223    {
 224  1 return _option;
 225    }
 226   
 227    /**
 228    * Sets the initial IPropertySelectionModel option
 229    *
 230    * @param option
 231    * a IPropertySelectionModel option
 232    */
 233  0 public void setOption(Object option)
 234    {
 235  0 _option = option;
 236    }
 237   
 238    /**
 239    * Empty model implementation. Avoids NullPointerExceptions when default constructor is used.
 240    */
 241    private static final IPropertySelectionModel EMPTY_MODEL = new IPropertySelectionModel()
 242    {
 243    /**
 244    * @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
 245    */
 246  2 public int getOptionCount()
 247    {
 248  2 return 0;
 249    }
 250   
 251    /**
 252    * @see org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
 253    */
 254  0 public Object getOption(int index)
 255    {
 256  0 return null;
 257    }
 258   
 259    /**
 260    * @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
 261    */
 262  0 public String getLabel(int index)
 263    {
 264  0 return null;
 265    }
 266   
 267    /**
 268    * @see org.apache.tapestry.form.IPropertySelectionModel#getValue(int)
 269    */
 270  0 public String getValue(int index)
 271    {
 272  0 return null;
 273    }
 274   
 275    /**
 276    * @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
 277    */
 278  0 public Object translateValue(String value)
 279    {
 280  0 return null;
 281    }
 282    };
 283    }