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

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

?? proxyinvocationhandler.java

?? 關于 RFID 讀寫器的相關內容
?? JAVA
字號:
/*
 * Copyright (C) 2007 ETH Zurich
 *
 * This file is part of Fosstrak (www.fosstrak.org).
 *
 * Fosstrak is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software Foundation.
 *
 * Fosstrak is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Fosstrak; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package org.fosstrak.reader.rp.proxy.invocationHandlers;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;

import org.fosstrak.reader.rprm.core.msg.reply.ReadReportType;
import org.fosstrak.reader.rprm.core.msg.reply.Reply;
import org.fosstrak.reader.rp.proxy.RPProxyException;
import org.fosstrak.reader.rp.proxy.ReadReport;
import org.fosstrak.reader.rp.proxy.msg.ProxyConnection;

/**
 * This class is the core piece of the reader device proxy. Each call to a proxy method will be intercepted by this class.
 * The call will be redirected to the proxy connection and the achieved result will be transformed to a suitable type.
 * 
 * @author regli
 */
public class ProxyInvocationHandler implements InvocationHandler {

	/** the proxy connection which is used for command executions */
	protected ProxyConnection proxyConnection;
	
	/** the type of the object to which the proxy of this invocation handler belong to */
	private final String object;
	
	/** the name of the object to which the proxy of this invocation handler belongs to */
	private final String target;

	/**
	 * Constructor sets the parameters.
	 * 
	 * @param object the type of the object
	 * @param target the name of the object
	 * @param proxyConnection the connection for command execution
	 */
	public ProxyInvocationHandler(String object, String target, ProxyConnection proxyConnection) {
		
		super();
		this.proxyConnection = proxyConnection;
		this.object = object;
		this.target = target;
		
	}
	
	/**
	 * This method intercepts all method calls to a proxy. It redirects the calls to the proxy connection and generates
	 * from his reply the result in a suitable form.
	 */
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		
		// handle toString method
		if ("toString".equals(method.getName())) {
			return toString();
		}
		
		// handle goodbye method
		if ("goodbye".equals(method.getName())) {
			if (proxyConnection.isConnected()) {
				proxyConnection.disconnect();
			}
			return null;
		}
		
		// handle reboot method
		if ("reboot".equals(method.getName()) && "".equals(target) && args == null) {
			proxyConnection.executeCommand(object, "reboot", new Class[0], null, target, true);
			while (!proxyConnection.connect()) {
				Thread.sleep(100);
			}
			return null;
		}
			
		// get method information
		Class returnType = method.getReturnType();
		Class[] parameterTypes = method.getParameterTypes();
		
		// prepare parameter
		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isArray()) {
				Object[] arrayValues = (Object[])args[i];
				if (arrayValues != null) {
					String stringValue = "";
					for (int j = 0; j < arrayValues.length; j++) {
						if (j > 0) stringValue += ", ";
						stringValue += arrayValues[j].toString();
					}
					args[i] = stringValue;
				} else {
					args[i] = null;
				}
				parameterTypes[i] = Collection.class;
			} else {
				if (parameterTypes[i] == int.class) {
					parameterTypes[i] = Integer.class;
				} else if (parameterTypes[i] == boolean.class) {
					parameterTypes[i] = Boolean.class;
				} else if (parameterTypes[i] != Integer.class && parameterTypes[i] != Boolean.class && parameterTypes[i] != Collection.class) {
					parameterTypes[i] = String.class;
				}
			}
		}
		
		// execute
		Reply reply = proxyConnection.executeCommand(object, method.getName(), parameterTypes, args, target, false);
		
		// convert result
		Object result = null;
		if (returnType != Void.TYPE) {
			if (reply == null) {
				if (returnType == int.class) {
					return new Integer(-1);
				} else if (returnType == boolean.class) {
					return new Boolean(false);
				} else {
					return null;
				}
			} else {
				try {
					Object typedReply = reply.getClass().getMethod("get" + object, new Class[0]).invoke(reply, new Object[0]);
					if (typedReply == null) {
						result = reply.getClass().getMethod("getAny", new Class[0]).invoke(reply, new Object[0]);
					} else {
						Object replyObject = typedReply.getClass().getMethod("get" + method.getName().substring(0, 1).toUpperCase() + method.getName().substring(1), new Class[0]).invoke(typedReply, new Object[0]);
						result = replyObject.getClass().getMethod("getReturnValue", new Class[0]).invoke(replyObject, new Object[0]);
						try {
							result = result.getClass().getMethod("getList", new Class[0]).invoke(result, new Object[0]);
						} catch(NoSuchMethodException e) {
						}
						try {
							result = result.getClass().getMethod("getValue", new Class[0]).invoke(result, new Object[0]);
						} catch(NoSuchMethodException e) {
						}
					}
				} catch (NoSuchMethodException e) {
					result = reply.getClass().getMethod("getAny", new Class[0]).invoke(reply, new Object[0]);
				}

				if (returnType == int.class) {
					returnType = Integer.class;
				} else if (returnType == boolean.class) {
					returnType = Boolean.class;
				}
				if (returnType.isArray()) {
					if (!result.getClass().isArray()) {
						if (result instanceof ArrayList) {
							Class type = returnType.getComponentType();
							String[] resultStrings = ((ArrayList<String>)result).toArray(new String[0]);
							int length = resultStrings.length;
							result = Array.newInstance(type, length);
							for (int i = 0; i < length; i++) {
								Array.set(result, i, createObject(type, resultStrings[i]));
							}
						}
					}
					if (result.getClass().getComponentType() != returnType.getComponentType()) {
						int arrayLength = ((Object[])result).length;
						Object resultArray = Array.newInstance(returnType.getComponentType(), arrayLength);
						for (int i = 0; i < arrayLength; i++) {
							Array.set(resultArray, i, returnType.getComponentType().cast(createObject(returnType.getComponentType(), ((String[])result)[i])));
						}
						result = resultArray;
					}
				}else if (returnType == ReadReport.class) {
					if (result instanceof ReadReportType) {
						result = new ReadReport((ReadReportType)result);
					} else {
						result = new ReadReport((String[])result);
					}
				} else {
					if (result.getClass().isArray() && ((Object[])result).length == 1) {
						result = ((Object[])result)[0];
					}
					if (returnType != String.class) {
						if (returnType == Integer.class) {
							result = new Integer((String)result);
						} else if (returnType == Boolean.class) {
							result = new Boolean((String)result);
						} else {
							result = createObject(returnType, (String)result);
						}
					}
				}
			}
		}
		
		return result;
		
	}

	//
	// private methods
	//
	
	/**
	 * This method parses a result set and returns the content in a string array.
	 */
	private String[] getResultSet(String resultString) {
		
		ArrayList results = new ArrayList();
		int start = resultString.indexOf("<value>", 0);
		int end = resultString.indexOf("</value>", start);
		while (start > -1 && end > start) {
			results.add(resultString.substring(start + "<value>".length(), end));
			start = resultString.indexOf("<value>", end);
			end = resultString.indexOf("</value>", start);
		}
		return (String[])results.toArray(new String[0]);
		
	}

	/**
	 * This method creates an object of type returnType with the initialize value initValue.
	 * If the returnType is an interface the method createObjectForInterface() is invoked.
	 * 
	 * @param returnType the type of the new object
	 * @param initValue the initialize value of the new object
	 * @return an object of type returnType with initialize value initValue
	 * @throws Exception if the new object could not be created
	 */
	private Object createObject(Class returnType, String initValue) throws Exception {
		
		if (returnType.isInterface()) {
			return createObjectForInterface(returnType, initValue);
		} else {
			Constructor constructor = returnType.getConstructor(new Class[]{String.class});
			return constructor.newInstance(new Object[]{initValue});
		}
		
	}

	/**
	 * This method creates an object which implements the interface interfaceType by calling
	 * the getInterfaceType() method of the InterfaceMethodFactory with the value initValue.
	 * 
	 * @param interfaceType the type of the new object
	 * @param initValue the initialize value
	 * @return a new object which implements the interface interfaceType
	 * @throws RPProxyException if the new object could not be created
	 */
	private Object createObjectForInterface(Class interfaceType, String initValue) throws RPProxyException {
		
		String proxyFactoryPackageName = interfaceType.getPackage().getName() + ".factories";
		String proxyFactoryName = proxyFactoryPackageName + "." + interfaceType.getSimpleName().substring(0, interfaceType.getSimpleName().length()) + "Factory";
		String methodName = "get" + interfaceType.getSimpleName().substring(0, interfaceType.getSimpleName().length());
		Class proxyFactory;
		try {
			proxyFactory = Class.forName(proxyFactoryName);
		} catch (ClassNotFoundException e) {
			throw new RPProxyException("Factory '" + proxyFactoryName + "' to create a " + interfaceType.getSimpleName() + "-proxy not found.");
		}
		Method getProxyMethod = null;
		try {
			getProxyMethod = proxyFactory.getDeclaredMethod(methodName, new Class[]{String.class, ProxyConnection.class});
		} catch (NoSuchMethodException e) {
			throw new RPProxyException("Method '" + methodName + "' in factory '" + proxyFactoryName + "' not found.");
		} catch (SecurityException e) {
			throw new RPProxyException("Security problem with method '" + methodName + "' in factory '" + proxyFactoryName + "'.");
		}
		try {
			return getProxyMethod.invoke(proxyFactory, new Object[]{initValue, proxyConnection});
		} catch (Exception e) {
			throw new RPProxyException("Create new " + interfaceType.getName() + "-proxy failed.");
		}
		
	}
	
	/**
	 * This method returns the name of the object.
	 */
	public String toString() {
		
		return target;
		
	}
	
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产亚洲人成网站| 亚洲麻豆国产自偷在线| 精品国产99国产精品| 国产亚洲一区二区在线观看| 一区二区视频免费在线观看| 午夜精品福利在线| 国产精品一区二区三区网站| 一本色道综合亚洲| 91视频免费看| 精品福利一二区| 亚洲一级二级三级在线免费观看| 蜜桃一区二区三区在线| 97久久精品人人做人人爽| 色8久久人人97超碰香蕉987| 久久亚洲一区二区三区四区| 国产精品视频在线看| 亚洲h精品动漫在线观看| 粉嫩aⅴ一区二区三区四区| 日韩电影在线观看电影| 亚洲色图制服诱惑| 国产精品嫩草99a| 亚洲综合无码一区二区| 精品在线免费观看| 欧美精品v日韩精品v韩国精品v| 国产日韩欧美一区二区三区综合 | 成人亚洲精品久久久久软件| 精品少妇一区二区三区日产乱码| 亚洲成av人综合在线观看| 欧美性大战久久久| 亚洲成a人片在线观看中文| 欧洲在线/亚洲| 亚洲国产精品久久不卡毛片 | 亚洲色图视频网| 97成人超碰视| 亚洲精品乱码久久久久久久久 | 亚洲一线二线三线视频| 欧美亚洲一区二区在线观看| 亚洲一二三四区不卡| 欧美在线短视频| 亚洲成av人**亚洲成av**| 欧美日韩国产大片| 久久精品国产在热久久| 日韩欧美另类在线| 国产成人亚洲综合a∨婷婷图片| 欧美经典一区二区| 色乱码一区二区三区88| 亚洲一区二区三区视频在线| 91精品婷婷国产综合久久| 免费不卡在线观看| 国产精品午夜电影| 欧美在线看片a免费观看| 婷婷中文字幕一区三区| 欧美一级淫片007| 成人综合婷婷国产精品久久| 洋洋av久久久久久久一区| 69久久99精品久久久久婷婷| 国产乱国产乱300精品| 亚洲欧美偷拍三级| 欧美一区二区三区免费视频 | 中文字幕的久久| 日本高清免费不卡视频| 日韩精品一卡二卡三卡四卡无卡| 精品久久久久久久久久久院品网 | 亚洲日本在线a| 欧美精品久久天天躁| 国产精品系列在线播放| 亚洲小说春色综合另类电影| 欧美成人精品福利| 99久久国产综合色|国产精品| 天堂成人免费av电影一区| 国产无一区二区| 欧美日本高清视频在线观看| 国产成a人无v码亚洲福利| 视频精品一区二区| 国产精品久久久久桃色tv| 欧美精品99久久久**| 从欧美一区二区三区| 久久精品国产精品青草| 亚洲精选一二三| 欧美激情综合网| 日韩精品专区在线影院重磅| 色八戒一区二区三区| 国产成人免费视频精品含羞草妖精| 午夜影院久久久| 自拍偷拍亚洲欧美日韩| 久久久久久久久岛国免费| 欧美一区二区三区人| 欧美体内she精高潮| 99久久er热在这里只有精品15| 蜜臀精品久久久久久蜜臀| 亚洲一区二区视频在线观看| 国产精品久久久久久久蜜臀 | 制服丝袜在线91| 91福利国产精品| 国产不卡视频一区| 久久精品国产一区二区| 图片区小说区国产精品视频| 亚洲天堂精品在线观看| 国产午夜一区二区三区| 日韩亚洲欧美中文三级| 欧美电影在线免费观看| 欧美午夜片在线看| 欧美伊人精品成人久久综合97 | 一区二区三区不卡在线观看| 亚洲欧洲精品一区二区三区| 中文字幕的久久| 国产精品亲子乱子伦xxxx裸| 久久亚洲免费视频| 久久久久久9999| 久久久777精品电影网影网 | 亚洲bdsm女犯bdsm网站| 亚洲国产裸拍裸体视频在线观看乱了| 亚洲同性同志一二三专区| 国产精品狼人久久影院观看方式| 久久久久久99精品| 中文字幕第一页久久| 国产精品大尺度| 专区另类欧美日韩| 亚洲精品中文字幕乱码三区| 亚洲综合免费观看高清完整版在线| 亚洲视频免费看| 一区二区三区成人在线视频| 亚洲一区二区三区精品在线| 三级亚洲高清视频| 国内欧美视频一区二区| 丰满亚洲少妇av| 91免费看`日韩一区二区| 欧美性xxxxx极品少妇| 51精品秘密在线观看| 精品国产露脸精彩对白| 国产精品久线在线观看| 一区二区三区四区不卡在线| 丝袜诱惑制服诱惑色一区在线观看| 日韩av电影天堂| 国产精品一区二区不卡| 色综合久久88色综合天天 | 99re这里都是精品| 欧美日韩视频在线一区二区| 日韩欧美中文字幕精品| 国产色婷婷亚洲99精品小说| 亚洲免费观看视频| 免费在线成人网| 丰满白嫩尤物一区二区| 欧美伊人久久久久久久久影院| 日韩视频一区二区在线观看| 国产亚洲精品超碰| 一区2区3区在线看| 激情五月激情综合网| 色94色欧美sute亚洲13| 精品剧情在线观看| 亚洲女爱视频在线| 国产一区二区h| 色综合中文字幕国产| 欧美日韩一区 二区 三区 久久精品 | 精品国产免费久久| 亚洲欧美偷拍三级| 黄页网站大全一区二区| 在线免费观看不卡av| 精品国产伦一区二区三区观看方式| 国产精品卡一卡二| 精品亚洲porn| 欧美视频在线不卡| 国产精品夫妻自拍| 极品美女销魂一区二区三区免费| 色综合久久中文字幕综合网| 精品三级av在线| 午夜影院久久久| 色综合久久久久综合| 久久精品视频免费| 免费看黄色91| 欧美日韩一区视频| 国产精品色哟哟网站| 久久精品久久综合| 欧美日韩电影在线播放| 亚洲同性gay激情无套| 成人一区二区三区在线观看| 日韩一级二级三级| 日韩国产欧美在线播放| 欧美在线影院一区二区| 1区2区3区国产精品| 成人免费毛片片v| 久久精品亚洲国产奇米99| 精品综合久久久久久8888| 91 com成人网| 性做久久久久久免费观看欧美| 91网站最新网址| 国产精品免费视频网站| 国产不卡视频在线播放| 久久综合九色综合欧美亚洲| 蜜乳av一区二区| 日韩视频中午一区| 奇米四色…亚洲| 欧美videos大乳护士334| 蜜臀av一级做a爰片久久| 欧美一级片在线| 日本亚洲最大的色成网站www| 欧美日韩在线三区| 日韩有码一区二区三区| 91精品国产综合久久精品性色| 午夜精品久久久久久久99樱桃|