亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? propertyutil.java

?? javaEE 原代碼 javaEE 原代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package com;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * 通過類反射進行對象與對象之間、對象與request中傳遞的參數之間的值拷貝。 使用規則: 1)對象與對象之間的值拷貝,對象的屬性名稱必須相同,大小寫敏感。
 * 2)對象與request中參數之間的值拷貝,對象的屬性名稱必須與參數名稱相同。 3)支持String 跟
 * long,double,Date數據類型的自動轉換。
 * <p>
 * 2005-10-29 <br>
 * 增加 Long,Double,Short,short 類型的數據與 String類型的轉換,增加 Long與long , Double與double ,
 * Short與short的類型轉換。 修改bug 無法拷貝對象super class的field的值
 * 
 * 
 * 
 * 
 * @author migro
 * @version v 1.0 $ 2005-10-22 20:47:44 $
 */
public class PropertyUtil {
	private static final String TYPE_STRING = "java.lang.String";

	private static final String TYPE_LONG = "long";

	private static final String TYPE_LONG_OBJ = "java.lang.Long";

	private static final String TYPE_DOUBLE = "double";

	private static final String TYPE_DOUBLE_OBJ = "java.lang.Double";

	private static final String TYPE_DATE = "java.util.Date";

	private static final String TYPE_SET = "java.util.Set";

	private static final String TYPE_HASHSET = "java.util.HashSet";

	private static final String TYPE_SHORT = "short";

	private static final String TYPE_SHORT_OBJ = "java.lang.Short";
	private Date start = new Date();

	public PropertyUtil() {
	}

	/**
	 * 對象之間拷貝相同名稱屬性的值
	 * 
	 * @param target
	 *            目標對象
	 * @param source
	 *            源對象
	 * @throws SysException
	 */
	public void copy(Object target, Object source) throws SysException {
		Class cTar = target.getClass();
		Class cSou = source.getClass();

		Class[] paramType = new Class[1];
		Object[] paramValue = new Object[1];

		Field[] fTar = getExtendsFields(cTar);// cTar.getDeclaredFields();
		Field[] fSou = getExtendsFields(cSou);// cSou.getDeclaredFields();

		String fNameTar = null; // target field name
		String fTypeTar = null; // target field type
		String fNameSou = null; // source field name
		String fTypeSou = null; // source field type

		Method setMethod = null;
		Object tmpVal = null;

		try {
			for (int i = 0; i < fSou.length; i++) {
				fNameSou = fSou[i].getName();
				fTypeSou = fSou[i].getType().getName();

				for (int j = 0; j < fTar.length; j++) {
					fNameTar = fTar[j].getName();
					fTypeTar = fTar[j].getType().getName();

					/** find the same field , copy value */
					if (fNameSou.equals(fNameTar)) {
						/** set the target obj setXXX() method parameter type */
						paramType[0] = fTar[j].getType();

						/** get the property value from source obj */
						tmpVal = getPropertyValue(fNameSou, null, null, source);

						if (fTypeSou.equals(fTypeTar)) { // the same type
							paramValue[0] = tmpVal;
						} else { // need type convert
							paramValue[0] = objTypeConvert(fTypeTar, fTypeSou,
									tmpVal);
						}

						/** get the setXXX() method from target obj */
						setMethod = cTar.getMethod(getSetMethodName(fNameTar),
								paramType);

						/** invoker the setXXX() method,complete property copy */
						setMethod.invoke(target, paramValue);

						break;
					}
				}
			}
		} catch (NoSuchMethodException e) {
			throw new SysException("SYS-0014", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":objectToObject()", null, e, "值對象缺少基本方法:" + fNameTar);
		} catch (InvocationTargetException e) {
			throw new SysException("SYS-0015", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":objectToObject()", null, e);
		} catch (IllegalAccessException e) {
			throw new SysException("SYS-0016", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":objectToObject()", null, e);
		} catch (NullPointerException upe) {

			throw upe;
		}
	}

	/**
	 * 從Httprequest對象中獲得對象中變量的值
	 * 
	 * @param target
	 *            目標對象
	 * @param httpRequest
	 *            JSP、Servlet中的請求對象
	 * @throws SysException
	 */
	public List copyXml(Object target, HttpServletRequest httpRequest)
			throws SysException {
		CDataSet cDataSet = new CDataSet();
		cDataSet.getDataSet(httpRequest);
		List ret = new ArrayList();
		Class cTar = target.getClass();
		Class[] paramType = new Class[1];
		Object[] paramValue = new Object[1];

		Field[] fTar = getExtendsFields(cTar);// cTar.getDeclaredFields();

		String fNameTar = null; // target field name
		String fTypeTar = null; // target field type

		Method setMethod = null;
		Object tmpVal = null;

		try {
			Document doc = cDataSet.getDoc();

			NodeList nodes = doc.getElementsByTagName(getClassName(cTar));
			if (nodes != null) {
				for (int i = 0; i < nodes.getLength(); i++) {
					for (int j = 0; j < fTar.length; j++) {
						fNameTar = fTar[j].getName();
						fTypeTar = fTar[j].getType().getName();

						/** find the value from http request */
						/** set the target obj setXXX() method parameter type */
						paramType[0] = fTar[j].getType();

						/** get the property value from http request */
						NodeList fileds = doc.getElementsByTagName(fNameTar);
						tmpVal = null;
						if (fileds != null && fileds.item(i) != null
								&& fileds.item(i).getFirstChild() != null) {
							tmpVal = fileds.item(i).getFirstChild()
									.getNodeValue();
						}

						if (tmpVal != null) {
							if (fTypeTar.equals("java.lang.String")) {
								paramValue[0] = tmpVal;
							} else { // need type convert
								paramValue[0] = objTypeConvert(fTypeTar,
										"java.lang.String", tmpVal);
							}

							/** get the setXXX() method from target obj */
							setMethod = cTar.getMethod(
									getSetMethodName(fNameTar), paramType);

							/**
							 * invoker the setXXX() method,complete property
							 * copy
							 */
							setMethod.invoke(target, paramValue);
						}
					}
					ret.add(target);
					this.toString(target);
				}
			}

		} catch (NoSuchMethodException e) {
			throw new SysException("SYS-0014", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e, "值對象缺少基本方法:" + fNameTar);
		} catch (InvocationTargetException e) {
			throw new SysException("SYS-0015", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e, "property<" + fNameTar
					+ "> value<" + tmpVal + ">");
		} catch (IllegalAccessException e) {
			throw new SysException("SYS-0016", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e);
		} catch (NullPointerException upe) {

			throw upe;
		}
		long tmp = new Date().getTime() - start.getTime();
		System.out.println("dom耗時:" + tmp + " ms");
		return ret;
	}

	/**
	 * 從Httprequest對象中獲得對象中變量的值
	 * 
	 * @param target
	 *            目標對象
	 * @param httpRequest
	 *            JSP、Servlet中的請求對象
	 * @throws SysException
	 */
	public void copy(Object target, HttpServletRequest httpRequest)
			throws SysException {
		Class cTar = target.getClass();

		Class[] paramType = new Class[1];
		Object[] paramValue = new Object[1];

		Field[] fTar = getExtendsFields(cTar);// cTar.getDeclaredFields();

		String fNameTar = null; // target field name
		String fTypeTar = null; // target field type

		Method setMethod = null;
		Object tmpVal = null;

		try {
			for (int j = 0; j < fTar.length; j++) {
				fNameTar = fTar[j].getName();
				fTypeTar = fTar[j].getType().getName();

				/** find the value from http request */
				/** set the target obj setXXX() method parameter type */
				paramType[0] = fTar[j].getType();

				/** get the property value from http request */
				tmpVal = httpRequest.getParameter(fNameTar);

				if (tmpVal != null) {
					if (fTypeTar.equals("java.lang.String")) { // the same type
						paramValue[0] = tmpVal;
					} else { // need type convert
						paramValue[0] = objTypeConvert(fTypeTar,
								"java.lang.String", tmpVal);
					}

					/** get the setXXX() method from target obj */
					setMethod = cTar.getMethod(getSetMethodName(fNameTar),
							paramType);

					/** invoker the setXXX() method,complete property copy */
					setMethod.invoke(target, paramValue);
				}
			}
		} catch (NoSuchMethodException e) {
			throw new SysException("SYS-0014", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e, "值對象缺少基本方法:" + fNameTar);
		} catch (InvocationTargetException e) {
			throw new SysException("SYS-0015", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e, "property<" + fNameTar
					+ "> value<" + tmpVal + ">");
		} catch (IllegalAccessException e) {
			throw new SysException("SYS-0016", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e);
		} catch (NullPointerException upe) {

			throw upe;
		}
	}

	/**
	 * 從數據集ResultSet對象中獲得對象中變量的值
	 * 
	 * @param target目標對象
	 * @param res數據集對象
	 * @throws SysException
	 */
	public void copy(Object target, ResultSet res) throws SysException {
		Class cTar = target.getClass();

		Class[] paramType = new Class[1];
		Object[] paramValue = new Object[1];

		Field[] fTar = getExtendsFields(cTar);// cTar.getDeclaredFields();

		String fNameTar = null; // target field name
		String fTypeTar = null; // target field type

		Method setMethod = null;
		String tmpVal = null;

		try {
			for (int j = 0; j < fTar.length; j++) {
				fNameTar = fTar[j].getName();
				fTypeTar = fTar[j].getType().getName();

				/** find the value from http request */
				/** set the target obj setXXX() method parameter type */
				paramType[0] = fTar[j].getType();

				/** get the property value from ResultSet */
				try {
					tmpVal = res.getString(fNameTar);
				} catch (SQLException sss) {
					// ignore SQLExceptions
					tmpVal = null;

				}
				if (tmpVal != null) {
					tmpVal = tmpVal.trim();
				}

				if ((tmpVal != null) && (tmpVal.length() > 0)) {
					if (fTypeTar.equals("java.lang.String")) { // the same type
						paramValue[0] = tmpVal;
					} else { // need type convert
						paramValue[0] = objTypeConvert(fTypeTar,
								"java.lang.String", tmpVal);
					}

					/** get the setXXX() method from target obj */
					setMethod = cTar.getMethod(getSetMethodName(fNameTar),
							paramType);

					/** invoker the setXXX() method,complete property copy */
					setMethod.invoke(target, paramValue);
				}
			}
		} catch (NoSuchMethodException e) {
			throw new SysException("SYS-0014", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e, "值對象缺少基本方法:" + fNameTar);
		} catch (InvocationTargetException e) {
			throw new SysException("SYS-0015", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e, "property<" + fNameTar
					+ "> value<" + tmpVal + ">");
		} catch (IllegalAccessException e) {
			throw new SysException("SYS-0016", "SYS", "網絡繁忙,請稍后再試!", this
					.getClass().getName()
					+ ":requestToObject()", null, e);
		} catch (NullPointerException upe) {

			throw upe;
		}
	}

	private Object getPropertyValue(String fieldName, Class[] types,
			Object[] params, Object obj) throws NoSuchMethodException,
			InvocationTargetException, IllegalAccessException {
		Object ret = null;

		Class c = obj.getClass();
		Method getMethod = c.getMethod(getGetMethodName(fieldName), types);
		ret = getMethod.invoke(obj, params);

		// System.out.println(getMethod.getName());
		return ret;
	}

	private String getGetMethodName(String fieldName) {
		if (fieldName == null) {
			return null;
		}

		StringBuffer ret = new StringBuffer();
		ret.append("get");
		ret.append(fieldName.substring(0, 1).toUpperCase());
		ret.append(fieldName.substring(1));

		return ret.toString();
	}

	private String getSetMethodName(String fieldName) {
		if (fieldName == null) {
			return null;
		}

		StringBuffer ret = new StringBuffer();
		ret.append("set");
		ret.append(fieldName.substring(0, 1).toUpperCase());
		ret.append(fieldName.substring(1));

		return ret.toString();
	}

	private Object objTypeConvert(String targetType, String sourceType,
			Object obj) throws SysException {
		Object ret = null;
		boolean exception = false;

		try {
			if (targetType.equals(TYPE_STRING)) { // convert to String

				if (obj != null) {
					if (sourceType.equals(TYPE_DATE)
							|| sourceType.equals(TYPE_DOUBLE)
							|| sourceType.equals(TYPE_LONG)
							|| sourceType.equals(TYPE_SHORT)
							|| sourceType.equals(TYPE_LONG_OBJ)
							|| sourceType.equals(TYPE_DOUBLE_OBJ)
							|| sourceType.equals(TYPE_SHORT_OBJ)) {
						ret = formatString(obj);
					} else {
						exception = true;
					}
				} else {
					ret = null;
				}
			} else if (targetType.equals(TYPE_DOUBLE)) { // convert to double

				if (sourceType.equals(TYPE_STRING)) {
					String tmp = (String) obj;

					if ((tmp == null) || (tmp.length() < 1)) {
						tmp = "0.0";
					}

					ret = new Double(tmp);
				} else if (sourceType.equals(TYPE_DOUBLE_OBJ)) {
					ret = obj;
				} else {
					exception = true;
				}
			} else if (targetType.equals(TYPE_LONG)) { // convert to long

				if (sourceType.equals(TYPE_STRING)) {
					String tmp = (String) obj;

					if ((tmp == null) || (tmp.length() < 1)) {
						tmp = "0";
					}

					ret = new Long(tmp);
				} else if (sourceType.equals(TYPE_LONG_OBJ)) {
					ret = obj;
				} else {
					exception = true;
				}
			} else if (targetType.equals(TYPE_DATE)) { // convert to Date

				if (sourceType.equals(TYPE_STRING)) {
					String tmp = (String) obj;

					if ((tmp == null) || (tmp.length() < 1)) {
						ret = null;
					} else {
						ret = DateUtil.parseDate(tmp);
					}
				} else {
					exception = true;
				}
			} else if (targetType.equals(TYPE_SHORT)) { // convert to short

				if (sourceType.equals(TYPE_STRING)) {
					String tmp = (String) obj;

					if ((tmp == null) || (tmp.length() < 1)) {
						tmp = "0";
					}

					ret = new Short(tmp);
				} else if (sourceType.equals(TYPE_SHORT_OBJ)) {
					ret = obj;
				} else {
					exception = true;
				}
			} else if (targetType.equals(TYPE_LONG_OBJ)) { // convert to Long
				if (sourceType.equals(TYPE_STRING)) {
					String tmp = (String) obj;
					if (tmp == null || tmp.length() < 1) {
						tmp = "0";
					}

					ret = new Long(tmp);
				} else if (sourceType.equals(TYPE_LONG)) {
					String tmp = formatString(obj);
					ret = new Long(tmp);
				} else {
					exception = true;
				}
			} else if (targetType.equals(TYPE_DOUBLE_OBJ)) { // convert to
				// Long
				if (sourceType.equals(TYPE_STRING)) {
					String tmp = (String) obj;
					if (tmp == null || tmp.length() < 1) {
						tmp = "0.0";
					}

					ret = new Double(tmp);
				} else if (sourceType.equals(TYPE_DOUBLE)) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
视频在线观看一区| 美女尤物国产一区| 欧美一级日韩不卡播放免费| 国产69精品久久99不卡| 伊人婷婷欧美激情| 久久久天堂av| 欧美一区日韩一区| 色婷婷综合久久久久中文| 久久99国产精品麻豆| 亚洲国产精品一区二区久久| 国产色综合一区| 日韩欧美国产高清| 欧美老女人在线| 91在线码无精品| 国产91精品露脸国语对白| 久久成人免费电影| 三级久久三级久久久| 亚洲精品久久久蜜桃| 欧美激情一区二区三区在线| 日韩精品一区二区三区中文精品| 色噜噜狠狠成人中文综合| 成人午夜av电影| 激情欧美一区二区三区在线观看| 日韩主播视频在线| 亚洲在线视频免费观看| 亚洲人123区| 国产精品拍天天在线| 国产三级精品在线| 久久先锋影音av| 欧美zozozo| 日韩美女一区二区三区| 欧美成人一区二区三区在线观看| 欧美日韩在线不卡| 欧美调教femdomvk| 欧美在线999| 欧美少妇性性性| 欧美午夜免费电影| 欧美三级视频在线观看 | 色偷偷久久一区二区三区| 成人app在线观看| 成人av动漫网站| av中文字幕在线不卡| 不卡av在线免费观看| 不卡的av网站| 色综合久久综合网97色综合| 成人av网址在线观看| 亚洲国产成人tv| 欧美一区二区三区免费视频| 91麻豆高清视频| 97精品视频在线观看自产线路二| 国产不卡在线一区| av在线不卡电影| av网站一区二区三区| 91日韩精品一区| 欧美日韩二区三区| 在线综合+亚洲+欧美中文字幕| 日韩三级视频在线看| 26uuu国产在线精品一区二区| 国产日韩影视精品| 亚洲欧美色综合| 天堂一区二区在线| 韩国中文字幕2020精品| 成人午夜免费av| 91丨九色丨黑人外教| 欧美人体做爰大胆视频| 欧美一区二区网站| 国产欧美一区二区精品性色| 综合亚洲深深色噜噜狠狠网站| 一区二区久久久久| 青青草国产成人av片免费| 国产精品一二二区| 色综合中文综合网| 国产精品成人一区二区三区夜夜夜| 国产精品国产精品国产专区不蜜| 亚洲精品菠萝久久久久久久| 午夜精品免费在线| 极品少妇xxxx偷拍精品少妇| 国产91色综合久久免费分享| 日本道免费精品一区二区三区| 国产精品人成在线观看免费| 奇米影视在线99精品| 极品少妇xxxx精品少妇| 成人精品鲁一区一区二区| 欧美伊人久久久久久久久影院| 日韩视频在线你懂得| 中文久久乱码一区二区| 亚洲电影视频在线| 高清不卡一区二区| 欧美日韩一卡二卡三卡| 国产欧美综合在线| 亚洲成人av在线电影| 成人精品一区二区三区中文字幕| 777精品伊人久久久久大香线蕉| 久久精品欧美一区二区三区麻豆| 亚洲一区在线视频观看| 国产精品一区二区91| 欧美色倩网站大全免费| 国产色爱av资源综合区| 偷拍与自拍一区| 成人白浆超碰人人人人| 欧美一区二区三区播放老司机| 国产精品不卡一区| 国产呦萝稀缺另类资源| 制服丝袜亚洲色图| 一级日本不卡的影视| 国产成人免费视频一区| 欧美一区二区女人| 亚洲va国产va欧美va观看| 99精品一区二区三区| 久久精品亚洲精品国产欧美kt∨| 亚洲成av人片在www色猫咪| 不卡的av电影| 国产精品毛片久久久久久| 久久疯狂做爰流白浆xx| 91麻豆精品91久久久久同性| 亚洲永久免费av| 91网站最新地址| 在线观看视频91| 精品99一区二区| 麻豆91免费观看| 日韩欧美在线网站| 日韩黄色一级片| 欧美精品久久久久久久多人混战 | 亚洲成人综合在线| 99精品欧美一区二区三区小说 | 日韩精品福利网| 色美美综合视频| 亚洲丝袜制服诱惑| 99视频有精品| 136国产福利精品导航| 成人精品亚洲人成在线| 中文字幕第一区| 成人av在线资源网| 亚洲人成在线观看一区二区| 99在线精品一区二区三区| 亚洲欧美一区二区在线观看| 波多野结衣一区二区三区| 国产精品久久久久一区二区三区 | 美女免费视频一区| 91精品国产欧美日韩| 免费在线观看一区二区三区| 制服.丝袜.亚洲.另类.中文| 麻豆久久久久久久| 精品伦理精品一区| 国产精品一区二区无线| 国产农村妇女毛片精品久久麻豆 | 欧美亚洲国产一区二区三区| 一个色在线综合| 欧美日韩精品一区二区| 石原莉奈一区二区三区在线观看| 91精品国产欧美一区二区| 黄色精品一二区| 国产精品白丝在线| 欧美日韩情趣电影| 奇米四色…亚洲| 中文字幕+乱码+中文字幕一区| www.色精品| 亚洲一区在线观看免费| 91麻豆精品91久久久久同性| 国产一区视频导航| 亚洲欧洲精品天堂一级| 欧美三级中文字幕| 久国产精品韩国三级视频| 国产三级一区二区三区| 91豆麻精品91久久久久久| 日韩av电影免费观看高清完整版| 精品国产三级电影在线观看| 欧美v亚洲v综合ⅴ国产v| 精彩视频一区二区| 久久精品在这里| 日本久久一区二区三区| 日本一区中文字幕| 欧美国产97人人爽人人喊| 在线观看亚洲a| 国产精品一区二区黑丝| 337p粉嫩大胆噜噜噜噜噜91av| 亚洲一二三四在线| 欧美刺激午夜性久久久久久久| 成人午夜大片免费观看| 午夜精品国产更新| 国产色一区二区| 欧美猛男男办公室激情| 国产电影一区在线| 一区二区成人在线视频| 久久久久久久久久看片| 欧美亚洲愉拍一区二区| 国产一区二区免费视频| 亚洲成人av一区二区三区| 中文在线一区二区| 欧美一区二区三区人| 成人丝袜高跟foot| 美腿丝袜一区二区三区| 一区二区三区欧美日| 国产色综合一区| 日韩久久精品一区| 欧美日韩中文字幕一区二区| 9i看片成人免费高清| 国产一区在线观看麻豆| 视频一区在线播放| 亚洲视频一区二区在线|