org.springframework.core.convert.Property Java Examples

The following examples show how to use org.springframework.core.convert.Property. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflectUtil.java    From mica with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取 bean 的属性信息
 *
 * @param propertyType 类型
 * @param propertyName 属性名
 * @return {Property}
 */
@Nullable
public static TypeDescriptor getTypeDescriptor(Class<?> propertyType, String propertyName) {
	Property property = ReflectUtil.getProperty(propertyType, propertyName);
	if (property == null) {
		return null;
	}
	return new TypeDescriptor(property);
}
 
Example #2
Source File: ReflectivePropertyAccessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
	if (target == null) {
		return false;
	}
	Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
	CacheKey cacheKey = new CacheKey(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;
}
 
Example #3
Source File: ReflectivePropertyAccessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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;
}
 
Example #4
Source File: ReflectivePropertyAccessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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;
}
 
Example #5
Source File: ReflectivePropertyAccessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
	if (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;
}
 
Example #6
Source File: ReflectUtil.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取 bean 的属性信息
 * @param propertyType 类型
 * @param propertyName 属性名
 * @return {Property}
 */
@Nullable
public static Property getProperty(Class<?> propertyType, String propertyName) {
	PropertyDescriptor propertyDescriptor = BeanUtil.getPropertyDescriptor(propertyType, propertyName);
	if (propertyDescriptor == null) {
		return null;
	}
	return ReflectUtil.getProperty(propertyType, propertyDescriptor, propertyName);
}
 
Example #7
Source File: ReflectUtil.java    From mica with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取 bean 的属性信息
 *
 * @param propertyType 类型
 * @param propertyName 属性名
 * @return {Property}
 */
@Nullable
public static Property getProperty(Class<?> propertyType, String propertyName) {
	PropertyDescriptor propertyDescriptor = BeanUtil.getPropertyDescriptor(propertyType, propertyName);
	if (propertyDescriptor == null) {
		return null;
	}
	return ReflectUtil.getProperty(propertyType, propertyDescriptor, propertyName);
}
 
Example #8
Source File: ReflectUtil.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取 bean 的属性信息
 * @param propertyType 类型
 * @param propertyName 属性名
 * @return {Property}
 */
@Nullable
public static TypeDescriptor getTypeDescriptor(Class<?> propertyType, String propertyName) {
	Property property = ReflectUtil.getProperty(propertyType, propertyName);
	if (property == null) {
		return null;
	}
	return new TypeDescriptor(property);
}
 
Example #9
Source File: SpringUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static TypeDescriptor typeDescriptorForPerperty(Class<?> clazz, String propertyName){
	PropertyDescriptor pd = ReflectUtils.getPropertyDescriptor(clazz, propertyName);
	TypeDescriptor td = new TypeDescriptor(new Property(clazz, pd.getReadMethod(), pd.getWriteMethod()));
	return td;
}
 
Example #10
Source File: BeanWrapperImpl.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private Property property(PropertyDescriptor pd) {
	GenericTypeAwarePropertyDescriptor gpd = (GenericTypeAwarePropertyDescriptor) pd;
	return new Property(gpd.getBeanClass(), gpd.getReadMethod(), gpd.getWriteMethod(), gpd.getName());
}
 
Example #11
Source File: BeanWrapperImpl.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
private Property property(PropertyDescriptor pd) {
	GenericTypeAwarePropertyDescriptor typeAware = (GenericTypeAwarePropertyDescriptor) pd;
	return new Property(typeAware.getBeanClass(), typeAware.getReadMethod(), typeAware.getWriteMethod(), typeAware.getName());
}
 
Example #12
Source File: BeanWrapperImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private Property property(PropertyDescriptor pd) {
	GenericTypeAwarePropertyDescriptor gpd = (GenericTypeAwarePropertyDescriptor) pd;
	return new Property(gpd.getBeanClass(), gpd.getReadMethod(), gpd.getWriteMethod(), gpd.getName());
}
 
Example #13
Source File: BeanWrapperImpl.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Property property(PropertyDescriptor pd) {
	GenericTypeAwarePropertyDescriptor gpd = (GenericTypeAwarePropertyDescriptor) pd;
	return new Property(gpd.getBeanClass(), gpd.getReadMethod(), gpd.getWriteMethod(), gpd.getName());
}
 
Example #14
Source File: BeanWrapperImpl.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private Property property(PropertyDescriptor pd) {
	GenericTypeAwarePropertyDescriptor gpd = (GenericTypeAwarePropertyDescriptor) pd;
	return new Property(gpd.getBeanClass(), gpd.getReadMethod(), gpd.getWriteMethod(), gpd.getName());
}
 
Example #15
Source File: AbstractBinder.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * @return Property for property binder
 */
protected Property getProperty() {
	PropertyDescriptor pd = getPropertyDescriptor();
	return new Property(getModel().getClass(), pd.getReadMethod(), pd.getWriteMethod());
}
 
Example #16
Source File: ReflectUtil.java    From blade-tool with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * 获取 类属性信息
 * @param propertyType 类型
 * @param propertyDescriptor PropertyDescriptor
 * @param propertyName 属性名
 * @return {Property}
 */
public static TypeDescriptor getTypeDescriptor(Class<?> propertyType, PropertyDescriptor propertyDescriptor, String propertyName) {
	Method readMethod = propertyDescriptor.getReadMethod();
	Method writeMethod = propertyDescriptor.getWriteMethod();
	Property property = new Property(propertyType, readMethod, writeMethod, propertyName);
	return new TypeDescriptor(property);
}
 
Example #17
Source File: ReflectUtil.java    From mica with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * 获取 类属性信息
 *
 * @param propertyType       类型
 * @param propertyDescriptor PropertyDescriptor
 * @param propertyName       属性名
 * @return {Property}
 */
public static TypeDescriptor getTypeDescriptor(Class<?> propertyType, PropertyDescriptor propertyDescriptor, String propertyName) {
	Method readMethod = propertyDescriptor.getReadMethod();
	Method writeMethod = propertyDescriptor.getWriteMethod();
	Property property = new Property(propertyType, readMethod, writeMethod, propertyName);
	return new TypeDescriptor(property);
}
 
Example #18
Source File: ReflectUtil.java    From blade-tool with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 获取 bean 的属性信息
 * @param propertyType 类型
 * @param propertyDescriptor PropertyDescriptor
 * @param propertyName 属性名
 * @return {Property}
 */
public static Property getProperty(Class<?> propertyType, PropertyDescriptor propertyDescriptor, String propertyName) {
	Method readMethod = propertyDescriptor.getReadMethod();
	Method writeMethod = propertyDescriptor.getWriteMethod();
	return new Property(propertyType, readMethod, writeMethod, propertyName);
}
 
Example #19
Source File: ReflectUtil.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 获取 bean 的属性信息
 *
 * @param propertyType       类型
 * @param propertyDescriptor PropertyDescriptor
 * @param propertyName       属性名
 * @return {Property}
 */
public static Property getProperty(Class<?> propertyType, PropertyDescriptor propertyDescriptor, String propertyName) {
	Method readMethod = propertyDescriptor.getReadMethod();
	Method writeMethod = propertyDescriptor.getWriteMethod();
	return new Property(propertyType, readMethod, writeMethod, propertyName);
}