Coverage Report - org.apache.tapestry5.internal.beaneditor.PropertyModelImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyModelImpl
92%
23/25
75%
3/4
0
 
 1  
 // Copyright 2007, 2008 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.tapestry5.internal.beaneditor;
 16  
 
 17  
 import org.apache.tapestry5.PropertyConduit;
 18  
 import org.apache.tapestry5.beaneditor.BeanModel;
 19  
 import org.apache.tapestry5.beaneditor.PropertyModel;
 20  
 import org.apache.tapestry5.internal.TapestryInternalUtils;
 21  
 import org.apache.tapestry5.ioc.Messages;
 22  
 import org.apache.tapestry5.ioc.internal.util.Defense;
 23  
 import org.apache.tapestry5.ioc.services.ClassFabUtils;
 24  
 
 25  
 import java.lang.annotation.Annotation;
 26  
 
 27  
 public class PropertyModelImpl implements PropertyModel
 28  
 {
 29  
     private final BeanModel model;
 30  
 
 31  
     private final String name;
 32  
 
 33  
     private final PropertyConduit conduit;
 34  
 
 35  
     private final String id;
 36  
 
 37  
     private String label;
 38  
 
 39  
     private String dataType;
 40  
 
 41  
     private boolean sortable;
 42  
 
 43  
     public PropertyModelImpl(BeanModel model, String name, PropertyConduit conduit, Messages messages)
 44  1156
     {
 45  1156
         this.model = model;
 46  1156
         this.name = name;
 47  1156
         this.conduit = conduit;
 48  
 
 49  1156
         id = TapestryInternalUtils.extractIdFromPropertyExpression(name);
 50  
 
 51  1156
         label = TapestryInternalUtils.defaultLabel(id, messages, name);
 52  
 
 53  
         // Primitive types need to be converted to wrapper types before checking to see
 54  
         // if they are sortable.
 55  
 
 56  1156
         Class wrapperType = ClassFabUtils.getWrapperType(getPropertyType());
 57  
 
 58  1156
         sortable = Comparable.class.isAssignableFrom(wrapperType);
 59  1156
     }
 60  
 
 61  
     public String getId()
 62  
     {
 63  24032
         return id;
 64  
     }
 65  
 
 66  
     public Class getPropertyType()
 67  
     {
 68  1878
         return conduit == null ? Object.class : conduit.getPropertyType();
 69  
     }
 70  
 
 71  
     public PropertyConduit getConduit()
 72  
     {
 73  8384
         return conduit;
 74  
     }
 75  
 
 76  
     public PropertyModel label(String label)
 77  
     {
 78  4
         Defense.notBlank(label, "label");
 79  
 
 80  4
         this.label = label;
 81  
 
 82  4
         return this;
 83  
     }
 84  
 
 85  
     public String getLabel()
 86  
     {
 87  1102
         return label;
 88  
     }
 89  
 
 90  
     public String getPropertyName()
 91  
     {
 92  1450
         return name;
 93  
     }
 94  
 
 95  
     public BeanModel model()
 96  
     {
 97  2
         return model;
 98  
     }
 99  
 
 100  
     public PropertyModel dataType(String dataType)
 101  
     {
 102  1080
         this.dataType = dataType;
 103  
 
 104  1080
         return this;
 105  
     }
 106  
 
 107  
     public String getDataType()
 108  
     {
 109  7648
         return dataType;
 110  
     }
 111  
 
 112  
     public boolean isSortable()
 113  
     {
 114  1226
         return sortable;
 115  
     }
 116  
 
 117  
     public PropertyModel sortable(boolean sortable)
 118  
     {
 119  0
         this.sortable = sortable;
 120  
 
 121  0
         return this;
 122  
     }
 123  
 
 124  
     public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
 125  
     {
 126  210
         return conduit == null ? null : conduit.getAnnotation(annotationClass);
 127  
     }
 128  
 }