@Override public boolean canWrite(EvaluationContext context, @Nullable Object target, String name) throws AccessException { if (!this.allowWrite || target == null) { return false; } Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass()); PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class); if (this.writerCache.containsKey(cacheKey)) { return true; } Method method = findSetterForProperty(name, type, target); if (method != null) { // Treat it like a property Property property = new Property(type, null, method); TypeDescriptor typeDescriptor = new TypeDescriptor(property); this.writerCache.put(cacheKey, method); this.typeDescriptorCache.put(cacheKey, typeDescriptor); return true; } else { Field field = findField(name, type, target); if (field != null) { this.writerCache.put(cacheKey, field); this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field)); return true; } } return false; }
@Nullable private Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { return null; } Field field = null; Class<?> declaringClass = declaringClass(); if (declaringClass != null) { field = ReflectionUtils.findField(declaringClass, name); if (field == null) { // Same lenient fallback checking as in CachedIntrospectionResults... field = ReflectionUtils.findField(declaringClass, StringUtils.uncapitalize(name)); if (field == null) { field = ReflectionUtils.findField(declaringClass, StringUtils.capitalize(name)); } } } return field; }
private MethodParameter resolveParameterType(MethodParameter parameter) { // needed to resolve generic property types that parameterized by sub-classes e.g. T getFoo(); GenericTypeResolver.resolveParameterType(parameter, getObjectType()); return parameter; }
private Annotation[] resolveAnnotations() { Annotation[] annotations = annotationCache.get(this); if (annotations == null) { Map<Class<? extends Annotation>, Annotation> annotationMap = new LinkedHashMap<>(); addAnnotationsToMap(annotationMap, getReadMethod()); addAnnotationsToMap(annotationMap, getWriteMethod()); addAnnotationsToMap(annotationMap, getField()); annotations = annotationMap.values().toArray(new Annotation[0]); annotationCache.put(this, annotations); } return annotations; }
@Nullable private Class<?> declaringClass() { if (getReadMethod() != null) { return getReadMethod().getDeclaringClass(); } else if (getWriteMethod() != null) { return getWriteMethod().getDeclaringClass(); } else { return null; } }
@Nullable private MethodParameter resolveWriteMethodParameter() { if (getWriteMethod() == null) { return null; } return resolveParameterType(new MethodParameter(getWriteMethod(), 0)); }
/** * Create a new type descriptor from a {@link Property}. * <p>Use this constructor when a source or target conversion point is a * property on a Java class. * @param property the property */ public TypeDescriptor(Property property) { Assert.notNull(property, "Property must not be null"); this.resolvableType = ResolvableType.forMethodParameter(property.getMethodParameter()); this.type = this.resolvableType.resolve(property.getType()); this.annotatedElement = new AnnotatedElementAdapter(property.getAnnotations()); }
private Annotation[] resolveAnnotations() { Map<Class<?>, Annotation> annMap = new LinkedHashMap<Class<?>, Annotation>(); Method readMethod = getReadMethod(); if (readMethod != null) { for (Annotation ann : readMethod.getAnnotations()) { annMap.put(ann.annotationType(), ann); } } Method writeMethod = getWriteMethod(); if (writeMethod != null) { for (Annotation ann : writeMethod.getAnnotations()) { annMap.put(ann.annotationType(), ann); } } Field field = getField(); if (field != null) { for (Annotation ann : field.getAnnotations()) { annMap.put(ann.annotationType(), ann); } } return annMap.values().toArray(new Annotation[annMap.size()]); }
@Nullable private MethodParameter resolveReadMethodParameter() { if (getReadMethod() == null) { return null; } return resolveParameterType(new MethodParameter(getReadMethod(), -1)); }
public boolean isRequired(UIComponent component) { ELContext elContext = DefaultComponentInfo.this.context.getELContext(); ValueExpression expression = component.getValueExpression("value"); Property property = ELUtils.getProperty(expression, elContext); if (property == null) { return false; } BeanDescriptor beanConstraints = this.validator.getConstraintsForClass(property.getObjectType()); PropertyDescriptor propertyConstraints = beanConstraints.getConstraintsForProperty(property.getName()); return isRequired(propertyConstraints.getConstraintDescriptors()); }
@Nullable private MethodParameter resolveWriteMethodParameter() { if (getWriteMethod() == null) { return null; } return resolveParameterType(new MethodParameter(getWriteMethod(), 0)); }
private Annotation[] resolveAnnotations() { Annotation[] annotations = annotationCache.get(this); if (annotations == null) { Map<Class<? extends Annotation>, Annotation> annotationMap = new LinkedHashMap<>(); addAnnotationsToMap(annotationMap, getReadMethod()); addAnnotationsToMap(annotationMap, getWriteMethod()); addAnnotationsToMap(annotationMap, getField()); annotations = annotationMap.values().toArray(new Annotation[0]); annotationCache.put(this, annotations); } return annotations; }
@Nullable private Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { return null; } Field field = null; Class<?> declaringClass = declaringClass(); if (declaringClass != null) { field = ReflectionUtils.findField(declaringClass, name); if (field == null) { // Same lenient fallback checking as in CachedIntrospectionResults... field = ReflectionUtils.findField(declaringClass, StringUtils.uncapitalize(name)); if (field == null) { field = ReflectionUtils.findField(declaringClass, StringUtils.capitalize(name)); } } } return field; }
@Nullable private MethodParameter resolveReadMethodParameter() { if (getReadMethod() == null) { return null; } return resolveParameterType(new MethodParameter(getReadMethod(), -1)); }
/** * Create a new type descriptor from a {@link Property}. * <p>Use this constructor when a source or target conversion point is a * property on a Java class. * @param property the property */ public TypeDescriptor(Property property) { Assert.notNull(property, "Property must not be null"); this.resolvableType = ResolvableType.forMethodParameter(property.getMethodParameter()); this.type = this.resolvableType.resolve(property.getType()); this.annotatedElement = new AnnotatedElementAdapter(property.getAnnotations()); }
private Annotation[] resolveAnnotations() { Annotation[] annotations = annotationCache.get(this); if (annotations == null) { Map<Class<? extends Annotation>, Annotation> annotationMap = new LinkedHashMap<>(); addAnnotationsToMap(annotationMap, getReadMethod()); addAnnotationsToMap(annotationMap, getWriteMethod()); addAnnotationsToMap(annotationMap, getField()); annotations = annotationMap.values().toArray(new Annotation[0]); annotationCache.put(this, annotations); } return annotations; }
@Nullable private MethodParameter resolveWriteMethodParameter() { if (getWriteMethod() == null) { return null; } return resolveParameterType(new MethodParameter(getWriteMethod(), 0)); }
@Nullable private Class<?> declaringClass() { if (getReadMethod() != null) { return getReadMethod().getDeclaringClass(); } else if (getWriteMethod() != null) { return getWriteMethod().getDeclaringClass(); } else { return null; } }
@Nullable private MethodParameter resolveReadMethodParameter() { if (getReadMethod() == null) { return null; } return resolveParameterType(new MethodParameter(getReadMethod(), -1)); }
Property property = new Property(type, method, null); TypeDescriptor typeDescriptor = new TypeDescriptor(property); this.readerCache.put(cacheKey, new InvokerPair(method, typeDescriptor));