/*
 * CommonBean.java created on 2013-08-13 下午 16:20:12 by 谢清(xie-qing)
 */

package com.dgt.graphdemo.entity.fqz;

import com.google.gson.GsonBuilder;
import org.springframework.beans.BeanUtils;

/**
 * 公用JavaBean
 * @author: 谢清(xie-qing)
 * @since: 2013-08-13
 */
@SuppressWarnings({
		"serial", "unchecked"
})
public class CommonBean<T> implements Basebean {

	public final static GsonBuilder gb = new GsonBuilder();
	{
		gb.disableHtmlEscaping();
	}
	
	public Class<T> clazz;

	public CommonBean() {
		//		ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
		//		clazz = (Class<T>) pt.getActualTypeArguments()[0];
	}

	/**
	 * 克隆
	 * @creator: xie-qing
	 * @createDate: 2013-08-13
	 * @modifier:
	 * @modifiedDate:
	 * @return
	 */
	public T copy() {
		//		T target = BeanUtils.instantiate(clazz);
		T target = (T) BeanUtils.instantiate(this.getClass());
		BeanUtils.copyProperties(this, target);
		return target;
	}

	/**
	 * 把值克隆到的目标对象，并返回
	 * @creator: xie-qing
	 * @createDate: 2013-08-13
	 * @modifier:
	 * @modifiedDate:
	 * @param target 把值克隆到的目标对象
	 * @return
	 */
	public T copy(T target) {
		BeanUtils.copyProperties(this, target);
		return target;
	}

	/**
	 * 把值(除了忽略的属性数组)克隆到的目标对象，并返回
	 * @creator: xie-qing
	 * @createDate: 2013-08-13
	 * @modifier:
	 * @modifiedDate:
	 * @param target 把值克隆到的目标对象
	 * @param ignoreProperties 忽略的属性数组
	 * @return
	 */
	public T copy(T target, String[] ignoreProperties) {
		BeanUtils.copyProperties(this, target, ignoreProperties);
		return target;
	}
	
	@Override
	public String toString(){
		return gb.create().toJson(this);
	}

}
