All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.ocean.rawsdk.util.DefaultPropertyUtils Maven / Gradle / Ivy

The newest version!
/**
 * 
 */
package com.alibaba.ocean.rawsdk.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;

/**
 * @author hongbang.hb
 *
 */
public class DefaultPropertyUtils {

	private static HashMap descriptorsCache = new HashMap();

	public static SimplePropertyDescriptor[] getPropertyDescriptors(
			Class beanClass) {

		if (beanClass == null) {
			return new SimplePropertyDescriptor[0];
		}
		SimplePropertyDescriptor[] descriptors = null;
		descriptors = (SimplePropertyDescriptor[]) descriptorsCache
				.get(beanClass);
		if (descriptors != null) {
			return (descriptors);
		}
		Field[] fields = beanClass.getDeclaredFields();
		if (fields == null) {
			descriptors = new SimplePropertyDescriptor[0];

		} else {
			descriptors = new SimplePropertyDescriptor[fields.length];
			for (int i = 0; i < fields.length; i++) {
				Field field = fields[i];
				SimplePropertyDescriptor simplePropertyDescriptor = new SimplePropertyDescriptor();
				simplePropertyDescriptor.setName(field.getName());
				simplePropertyDescriptor.setPropertyType(field.getType());
				try {
					Method readMethod = beanClass.getMethod("get"
							+ GenericsUtil.capitalize(field.getName()));
					simplePropertyDescriptor.setReadMethod(readMethod);
				} catch (Exception ex) {
					// do nothing if readMethod is not support.
				}
				descriptors[i] = simplePropertyDescriptor;
			}
		}
		descriptorsCache.put(beanClass, descriptors);
		return (descriptors);

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy