Coverage Report - org.apache.tapestry5.internal.services.BasePropertyConduit
 
Classes in this File Line Coverage Branch Coverage Complexity
BasePropertyConduit
94%
15/16
N/A
0
 
 1  
 // Copyright 2007, 2008, 2009 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.services;
 16  
 
 17  
 import org.apache.tapestry5.PropertyConduit;
 18  
 import org.apache.tapestry5.internal.util.IntegerRange;
 19  
 import org.apache.tapestry5.ioc.AnnotationProvider;
 20  
 import org.apache.tapestry5.ioc.internal.util.Defense;
 21  
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 22  
 
 23  
 import java.lang.annotation.Annotation;
 24  
 
 25  
 /**
 26  
  * Base class for {@link org.apache.tapestry5.PropertyConduit} instances created by the {@link
 27  
  * org.apache.tapestry5.services.PropertyConduitSource}.
 28  
  */
 29  
 public abstract class BasePropertyConduit implements PropertyConduit
 30  
 {
 31  
     private final Class propertyType;
 32  
 
 33  
     private final AnnotationProvider annotationProvider;
 34  
 
 35  
     private final String description;
 36  
 
 37  
     private final TypeCoercer typeCoercer;
 38  
 
 39  
     public BasePropertyConduit(Class propertyType, AnnotationProvider annotationProvider, String description,
 40  
                                TypeCoercer typeCoercer)
 41  1388
     {
 42  1388
         Defense.notNull(propertyType, "propertyType");
 43  1388
         Defense.notNull(annotationProvider, "annotationProvider");
 44  1388
         Defense.notBlank(description, "description");
 45  1388
         Defense.notNull(typeCoercer, "typeCoercer");
 46  
 
 47  1388
         this.propertyType = propertyType;
 48  1388
         this.annotationProvider = annotationProvider;
 49  1388
         this.description = description;
 50  1388
         this.typeCoercer = typeCoercer;
 51  1388
     }
 52  
 
 53  
     @Override
 54  
     public final String toString()
 55  
     {
 56  0
         return description;
 57  
     }
 58  
 
 59  
     public final <T extends Annotation> T getAnnotation(Class<T> annotationClass)
 60  
     {
 61  8008
         return annotationProvider.getAnnotation(annotationClass);
 62  
     }
 63  
 
 64  
     public final Class getPropertyType()
 65  
     {
 66  80086
         return propertyType;
 67  
     }
 68  
 
 69  
     public final IntegerRange range(int from, int to)
 70  
     {
 71  4
         return new IntegerRange(from, to);
 72  
     }
 73  
 
 74  
     protected final <T> T coerce(Object value, Class<T> type)
 75  
     {
 76  4118
         return typeCoercer.coerce(value, type);
 77  
     }
 78  
 
 79  
     public final boolean invert(Object value)
 80  
     {
 81  4068
         return coerce(value, Boolean.class).equals(Boolean.FALSE);
 82  
     }
 83  
 }