| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 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 | |
|
| 27 | |
|
| 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 | |
} |