/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.utils;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

import org.springframework.beans.BeanUtils;

/**
 * @author 田平 create 2014-6-4下午4:17:14
 */
public class PropertyUtil {

	public static void filterStringNull(Object obj) {
		if (obj != null) {
			PropertyDescriptor[] properties = BeanUtils.getPropertyDescriptors(obj.getClass());
			try {
				for (PropertyDescriptor descriptor : properties) {
					Method read = descriptor.getReadMethod();
					if (read.getParameterTypes().length == 0) {
						Object value = read.invoke(obj, new Object[] {});
						if (value == null) {
							if (descriptor.getPropertyType() == String.class) {
								Method write = descriptor.getWriteMethod();
								write.invoke(obj, new Object[] { "" });
							}
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException("PropertyUtil filterNull Failure!" + e.getMessage());
			}
		}
	}

	public static void main(String[] args) {

	}
}
