Coverage Report - org.apache.tapestry.coerce.StringConvertedPropertySelectionModel
 
Classes in this File Line Coverage Branch Coverage Complexity
StringConvertedPropertySelectionModel
0%
0/13
0%
0/2
1.222
StringConvertedPropertySelectionModel$Entry
0%
0/9
0%
0/2
1.222
 
 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.coerce;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.hivemind.util.Defense;
 21  
 import org.apache.tapestry.form.IPropertySelectionModel;
 22  
 
 23  
 /**
 24  
  * {@link org.apache.tapestry.form.IPropertySelectionModel} created from a comma-seperated string by
 25  
  * {@link org.apache.tapestry.coerce.StringToPropertySelectionModelConverter}.
 26  
  * 
 27  
  * @author Howard M. Lewis Ship
 28  
  * @since 4.0
 29  
  */
 30  
 public final class StringConvertedPropertySelectionModel implements IPropertySelectionModel
 31  
 {
 32  
     /**
 33  
      * Entry.
 34  
      * @author Howard Lewis Ship
 35  
      */
 36  
     private static class Entry
 37  
     {
 38  
         String _label;
 39  
 
 40  
         String _value;
 41  
 
 42  
         Entry(String term)
 43  0
         {
 44  0
             Defense.notNull(term, "term");
 45  
 
 46  0
             int equalx = term.indexOf('=');
 47  
 
 48  0
             if (equalx < 0)
 49  
             {
 50  0
                 _label = term.trim();
 51  0
                 _value = _label;
 52  
             }
 53  
             else
 54  
             {
 55  0
                 _label = term.substring(0, equalx).trim();
 56  0
                 _value = term.substring(equalx + 1).trim();
 57  
             }
 58  0
         }
 59  
     }
 60  
 
 61  
     private final List _entries;
 62  
 
 63  
     public StringConvertedPropertySelectionModel(String[] terms)
 64  0
     {
 65  0
         Defense.notNull(terms, "terms");
 66  
 
 67  0
         _entries = new ArrayList(terms.length);
 68  
 
 69  0
         for (int i = 0; i < terms.length; i++)
 70  
         {
 71  0
             _entries.add(new Entry(terms[i]));
 72  
         }
 73  0
     }
 74  
 
 75  
     public int getOptionCount()
 76  
     {
 77  0
         return _entries.size();
 78  
     }
 79  
 
 80  
     private Entry getEntry(int index)
 81  
     {
 82  0
         return (Entry) _entries.get(index);
 83  
     }
 84  
 
 85  
     public Object getOption(int index)
 86  
     {
 87  0
         return getValue(index);
 88  
     }
 89  
 
 90  
     public String getLabel(int index)
 91  
     {
 92  0
         return getEntry(index)._label;
 93  
     }
 94  
 
 95  
     public String getValue(int index)
 96  
     {
 97  0
         return getEntry(index)._value;
 98  
     }
 99  
 
 100  
     public boolean isDisabled(int index)
 101  
     {
 102  0
         return false;
 103  
     }
 104  
     
 105  
     public Object translateValue(String value)
 106  
     {
 107  
         // Values are the same on the client and the server, so no translation needed.
 108  0
         return value;
 109  
     }
 110  
 
 111  
 }