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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? readerconfigurator.java

?? 關(guān)于 RFID 讀寫器的相關(guān)內(nèi)容
?? 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.configurator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.fosstrak.reader.rp.proxy.DataSelector;
import org.fosstrak.reader.rp.proxy.NotificationChannel;
import org.fosstrak.reader.rp.proxy.RPProxyException;
import org.fosstrak.reader.rp.proxy.ReaderDevice;
import org.fosstrak.reader.rp.proxy.Source;
import org.fosstrak.reader.rp.proxy.Trigger;
import org.fosstrak.reader.rp.proxy.configurator.DataSelectorConfiguration.EventFilters;
import org.fosstrak.reader.rp.proxy.configurator.DataSelectorConfiguration.FieldNames;
import org.fosstrak.reader.rp.proxy.configurator.DataSelectorConfiguration.TagFields;
import org.fosstrak.reader.rp.proxy.configurator.NotificationChannelConfiguration.NotificationTriggers;
import org.fosstrak.reader.rp.proxy.factories.DataSelectorFactory;
import org.fosstrak.reader.rp.proxy.factories.NotificationChannelFactory;
import org.fosstrak.reader.rp.proxy.factories.ReaderDeviceFactory;
import org.fosstrak.reader.rp.proxy.factories.TriggerFactory;
import org.fosstrak.reader.rp.proxy.msg.Handshake;
import org.fosstrak.reader.rprm.core.TriggerType;
import org.apache.log4j.Logger;

/**
 * This class configurate a reader on the basis of a configuration file.
 * 
 * @author regli
 */
public class ReaderConfigurator {

	/** the logger */
	private static final Logger LOG = Logger.getLogger(ReaderConfigurator.class);
	
	/** the jaxb context */
	private static final String JAXB_CONTEXT = "org.fosstrak.reader.rp.proxy.configurator";

	/** the reader device to configurate */
	private static ReaderDevice readerDevice;
	
	/**
	 * This method configurates a reader on the basis of a configuration file and returns his proxy.
	 * 
	 * @param configFilePath filepath to the configuration file
	 * @return proxy of the reader device
	 * @throws RPProxyException if configuration fails
	 */
	public static ReaderDevice initReaderDeviceConfiguration(String configFilePath) throws RPProxyException {
	
		// read configuration file
		ReaderDeviceConfiguration config = readFile(configFilePath);
		
		// get reader device proxy
		readerDevice = getReaderDevice(config.getReaderConfig());
		
		// get elements
		List<Object> elements = config.getTriggersOrDataSelectorsOrNotificationChannels();
		if (elements != null) {
			
			// create triggers, data selectors
			for (Object element : elements) {
				if (element instanceof Triggers) {
					for (Object trigger : ((Triggers)element).getContinuousTriggerOrTimerTriggerOrIoEdgeTrigger()) {
						createTrigger(trigger);
					}
				} else if (element instanceof DataSelectors) {
					for (DataSelectorConfiguration dataSelector : ((DataSelectors)element).getDataSelector()) {
						createDataSelector(dataSelector);
					}
				}
			}
			
			// create notification channels
			for (Object element : elements) {
				if (element instanceof NotificationChannels) {
					for (NotificationChannelConfiguration channelConfig : ((NotificationChannels)element).getNotificationChannel()) {
						createNotificationChannel(channelConfig);
					}
				} else if (element instanceof Sources) {
					for (SourceConfiguration sourceConfig : ((Sources)element).getSource()) {
						addTriggersToSource(sourceConfig);
					}
				}
			}
		}
		
		LOG.info("Configuration of ReaderDevice terminated");
		return readerDevice;
		
	}
	
	//
	// private methods
	//
	
	/**
	 * This method reads and parses the configuration file.
	 * 
	 * @param configFilePath filepath to the configuration file
	 * @return the parsed configuration as object
	 * @throws RPProxyException if configuration file could not be read or parsed
	 */
	private static ReaderDeviceConfiguration readFile(String configFilePath) throws RPProxyException {
		
		// try to parse reader configuration file
		LOG.debug("Parse configuration file '" + configFilePath + "'");
		try {
			
			// check if config file exists
			File configFile = new File(configFilePath);
			if (!configFile.exists()) {
				throw new RPProxyException("Configuration File '" + configFilePath + "' not found.");
			}
			
			// initialize jaxb context and unmarshaller
			JAXBContext context = JAXBContext.newInstance(JAXB_CONTEXT);
			Unmarshaller unmarshaller = context.createUnmarshaller();
			
			// unmarshal logical reader configuration file
			return ((ConfigurationDocument)unmarshaller.unmarshal(configFile)).getReaderDeviceConfiguration();
			
		} catch (JAXBException e) {
			throw new RPProxyException("Unable to parse configuration file: " + e.getMessage());
		}
		
	}
	
	/**
	 * This method creates a reader device proxy for the reader specified in the configuration.
	 * 
	 * @param config configuration read from file
	 * @return reader device proxy
	 * @throws RPProxyException if reader device proxy could not be created
	 */
	private static ReaderDevice getReaderDevice(ReaderConfiguration config) throws RPProxyException {
		
		// read config parameters
		String host = config.getCommandChannelHost();
		int port = config.getCommandChannelPort();
		int format;
		if (config.getTransportFormat() == TransportFormat.XML) {
			format = Handshake.FORMAT_XML;
		} else {
			format = Handshake.FORMAT_TEXT;
		}
		int protocol;
		if (config.getTransportProtocol() == TransportProtocol.HTTP) {
			protocol = Handshake.HTTP;
		} else {
			protocol = Handshake.TCP;
		}
		
		LOG.debug("Get Reader Device (host = '" + host + "' | port = '" + port + "' | format = '"
				+ format + "' | protocol = '" + protocol + "')");

		// create handshake
		Handshake handshake = new Handshake();
		handshake.setMessageFormat(format);
		handshake.setTransportProtocol(protocol);
		
		// create and return reader device proxy
		return ReaderDeviceFactory.getReaderDevice(host, port, handshake);
		
	}
	
	/**
	 * This method creates and configurates a notification channel on the basis of the notification channel configuration.
	 * 
	 * @param channelConfig notification channel configuration
	 * @throws RPProxyException if notification channel could not be created or configurated
	 */
	private static void createNotificationChannel(NotificationChannelConfiguration channelConfig) throws RPProxyException {
		
		// read parameters
		String name = channelConfig.getName();
		String protocol = channelConfig.getTransportProtocol().name().toLowerCase();
		String host = channelConfig.getNotificationChannelHost();
		int port = channelConfig.getNotificationChannelPort();
		String mode = channelConfig.getNotificationChannelMode().name().toLowerCase();
		
		String address = protocol + "://" + host + ":" + port + "?mode=" + mode;
		
		// remove notification channel if it already exists
		NotificationChannel notificationChannel = null;
		try {
			notificationChannel = readerDevice.getNotificationChannel(name);
		} catch (RPProxyException e) {}
		if (notificationChannel != null) {
			LOG.debug("Remove old NotificationChannel '" + name + "'");
			readerDevice.removeNotificationChannels(new NotificationChannel[] {notificationChannel});
		}
		
		// create notification channel
		LOG.debug("Create NotificationChannel '" + name + "'");
		notificationChannel = NotificationChannelFactory.createNotificationChannel(name, address, readerDevice);
		
		// add sources
		org.fosstrak.reader.rp.proxy.configurator.NotificationChannelConfiguration.Sources sources = channelConfig.getSources();
		if (sources != null) {
			for (String sourceName : sources.getSource()) {
				LOG.debug("Add Source '" + sourceName + "' to NotificationChannel '" + name + "'");
				Source source = readerDevice.getSource(sourceName);
				notificationChannel.addSources(new Source[] {source});
			}
		}
		
		// add triggers
		NotificationTriggers triggers = channelConfig.getNotificationTriggers();
		if (triggers != null) {
			for (String triggerName : triggers.getTriggerName()) {
				LOG.debug("Add NotificationTrigger '" + triggerName + "' to NotificationChannel '" + name + "'");
				Trigger trigger = readerDevice.getTrigger(triggerName);
				notificationChannel.addNotificationTriggers(new Trigger[] {trigger});
			}
		}
		
		// add data selector
		String dataSelectorName = channelConfig.getDataSelector();
		if (dataSelectorName != null) {
			LOG.debug("Set DataSelector '" + dataSelectorName + "' of NotificationChannel '" + name + "'");
			DataSelector dataSelector = readerDevice.getDataSelector(dataSelectorName);
			notificationChannel.setDataSelector(dataSelector);
		}
		
	}

	/**
	 * This method creates and configurates a data selector on the basis of the data selector configuration.
	 * 
	 * @param dataSelectorConfig data selector configuration
	 * @throws RPProxyException if the data selector could not be created or configurated
	 */
	private static void createDataSelector(DataSelectorConfiguration dataSelectorConfig) throws RPProxyException {
		
		// read parameters
		String name = dataSelectorConfig.getName();
		List<String> events = new ArrayList<String>();
		List<String> fieldNames = new ArrayList<String>();
		List<String> tagFields = new ArrayList<String>();
		List<Object> elements = dataSelectorConfig.getFieldNamesOrEventFiltersOrTagFields();
		for (Object element : elements) {
			if (element instanceof EventFilters) {
				for (EventFilter eventFilter : ((EventFilters)element).getEventFilter()) {
					events.add(eventFilter.value());
				}
			} else if (element instanceof FieldNames) {
				for (FieldName fieldName : ((FieldNames)element).getFieldName()) {
					fieldNames.add(fieldName.value());
				} 
			} else if (element instanceof TagFields) {
				for (TagField tagField : ((TagFields)element).getTagField()) {
					tagFields.add(tagField.value());
				}
			}
		}

		// remove data selector if it already exists
		DataSelector dataSelector = null;
		try {
			dataSelector = readerDevice.getDataSelector(name);
		} catch (RPProxyException e) {}
		if (dataSelector != null) {
			LOG.debug("Remove old DataSelector '" + name + "'");
			readerDevice.removeDataSelectors(new DataSelector[] {dataSelector});
		}
		
		// create data selector
		LOG.debug("Create DataSelector '" + name + "'");
		dataSelector = DataSelectorFactory.createDataSelector(name, readerDevice);
		dataSelector.addEventFilters(events.toArray(new String[0]));
		dataSelector.addFieldNames(fieldNames.toArray(new String[0]));
		dataSelector.addTagFieldNames(tagFields.toArray(new String[0]));
		
	}

	/**
	 * This method creates and configurates a trigger on the basis of the trigger configuration.
	 * 
	 * @param triggerConfig trigger configuration
	 * @throws RPProxyException if the trigger could not be created or configurated
	 */
	private static void createTrigger(Object triggerConfig) throws RPProxyException {
		
		// read parameters
		String name;
		String type;
		String triggerValue;
		if (triggerConfig instanceof ContinuousTriggerConfiguration) {
			
			// continuous trigger
			ContinuousTriggerConfiguration continuousTrigger = (ContinuousTriggerConfiguration)triggerConfig;
			name = continuousTrigger.getName();
			type = TriggerType.CONTINUOUS;
			triggerValue = null;			
		} else if (triggerConfig instanceof TimerTriggerConfiguration) {
			
			// timer trigger
			TimerTriggerConfiguration timerTrigger = (TimerTriggerConfiguration)triggerConfig;
			name = timerTrigger.getName();
			type = TriggerType.TIMER;
			int interval = timerTrigger.getValue();
			triggerValue = "ms=" + interval;
		} else if (triggerConfig instanceof IOEdgeTriggerConfiguration) {
			
			// io edge trigger
			IOEdgeTriggerConfiguration ioEdgeTrigger = (IOEdgeTriggerConfiguration)triggerConfig;
			name = ioEdgeTrigger.getName();
			type = TriggerType.IO_EDGE;
			IOEdgeType edgeType = ioEdgeTrigger.getType();
			int port = ioEdgeTrigger.getPort();
			int pin = ioEdgeTrigger.getPin();
			triggerValue = "type=" + edgeType + ";port=" + port + ";pin=" + pin;
		} else if (triggerConfig instanceof IOValueTriggerConfiguration) {
			
			// io value trigger
			IOValueTriggerConfiguration ioValueTrigger = (IOValueTriggerConfiguration)triggerConfig;
			name = ioValueTrigger.getName();
			type = TriggerType.IO_VALUE;
			int port = ioValueTrigger.getPort();
			String value = ioValueTrigger.getValue();
			String mask = ioValueTrigger.getMask();
			triggerValue = "port=" + port + ";value=" + value + (mask != null ? ";mask" + mask : "");
		} else {
			throw new RPProxyException("Unkown TriggerType");
		}
		
		// remove trigger if it already exists
		Trigger trigger = null;
		try {
			trigger = readerDevice.getTrigger(name);
		} catch (RPProxyException e) {}
		if (trigger != null) {
			LOG.debug("Remove old Trigger '" + name + "'");
			readerDevice.removeTriggers(new Trigger[] {trigger});
		}
		
		// create trigger
		LOG.debug("Create Trigger '" + name + "'");
		trigger = TriggerFactory.createTrigger(name, type, triggerValue, readerDevice);
		
	}
	
	/**
	 * This method adds read triggers to sources on the basis of the source configuration.
	 * 
	 * @param sourceConfig source configuration
	 * @throws RPProxyException if a read trigger could not be added
	 */
	private static void addTriggersToSource(SourceConfiguration sourceConfig) throws RPProxyException {
		
		// read parameters
		String sourceName = sourceConfig.getName();
		Source source = readerDevice.getSource(sourceName);
		
		// add triggers to source
		for (String triggerName : sourceConfig.getTriggerName()) {
			LOG.debug("Add ReadTrigger '" + triggerName + "' to Source '" + sourceName + "'");
			Trigger trigger = readerDevice.getTrigger(triggerName);
			source.addReadTriggers(new Trigger[] {trigger});
		}
		
	}
	
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩中文字幕av电影| 国产成人av资源| 亚洲成av人影院| 亚洲国产另类av| 亚洲免费在线观看视频| 国产精品乱人伦中文| 成人欧美一区二区三区1314| 中文字幕中文字幕一区二区 | 亚洲人成精品久久久久久| 欧美韩日一区二区三区四区| 日本一区二区三级电影在线观看 | 精品久久久久久亚洲综合网| 99久久久精品| 国产成人在线网站| 国产精品乡下勾搭老头1| 国产在线精品免费| 国产69精品久久久久毛片| 国产成人av电影在线| www.色综合.com| 91久久久免费一区二区| 在线观看国产一区二区| 91精品国产综合久久香蕉麻豆| 欧美日本在线观看| 精品少妇一区二区三区在线视频| 日韩精品一区二区三区在线观看 | 亚洲最快最全在线视频| 亚洲国产综合视频在线观看| 日韩中文字幕亚洲一区二区va在线 | 精品精品国产高清一毛片一天堂| 亚洲精品一区在线观看| 国产欧美日韩亚州综合| 亚洲精品国产高清久久伦理二区 | 欧美日韩成人一区| 2023国产精品| 亚洲桃色在线一区| 午夜激情一区二区三区| 久久精品99国产精品日本| 成人免费视频视频| 欧美性淫爽ww久久久久无| 欧美成人a视频| 亚洲欧洲日本在线| 日韩和欧美的一区| 国产成人综合精品三级| 日本高清视频一区二区| 欧美一区二区久久| 国产精品欧美经典| 强制捆绑调教一区二区| 9l国产精品久久久久麻豆| 欧美另类高清zo欧美| 欧美国产激情一区二区三区蜜月| 一区二区三区国产精品| 韩国欧美国产1区| 欧美在线制服丝袜| 久久亚洲精华国产精华液 | 蜜桃av一区二区| av一本久道久久综合久久鬼色| 欧美日韩亚洲综合一区 | 免费看日韩精品| 91原创在线视频| 日韩欧美国产麻豆| 亚洲精品一二三四区| 国产福利一区二区三区视频| 欧美日韩中文字幕精品| 欧美高清在线一区二区| 日韩精彩视频在线观看| 99在线精品观看| 2019国产精品| 日日夜夜免费精品视频| 99久久婷婷国产| 久久久久久久久99精品| 日韩福利电影在线观看| 色94色欧美sute亚洲线路二 | 92精品国产成人观看免费| 欧美大片日本大片免费观看| 夜夜精品视频一区二区| www.在线欧美| 国产亚洲一二三区| 青青草精品视频| 欧美体内she精高潮| 亚洲视频一二三区| 精品系列免费在线观看| 欧美日韩高清影院| 亚洲美女视频一区| 丁香六月综合激情| 国产午夜亚洲精品不卡| 老司机免费视频一区二区三区| 欧美日韩国产a| 亚洲成人av电影| 欧美在线视频全部完| 亚洲天堂免费看| 成人av免费在线观看| 久久久综合精品| 久久99蜜桃精品| 制服丝袜亚洲网站| 亚洲成av人片一区二区梦乃| 91福利视频久久久久| 亚洲视频小说图片| 99国产精品久| 中文字幕亚洲一区二区va在线| 成人毛片视频在线观看| 中文字幕高清一区| 成人av电影免费在线播放| 久久嫩草精品久久久精品| 国产综合一区二区| 精品av综合导航| 国产美女在线观看一区| 久久综合色综合88| 国产精选一区二区三区| 欧美国产日韩a欧美在线观看| 国产精品888| 日本一区二区三区国色天香| 成人ar影院免费观看视频| 亚洲欧洲日韩女同| 欧洲一区二区三区免费视频| 一区二区三区高清在线| 欧美午夜在线观看| 日韩黄色片在线观看| 欧美电影精品一区二区| 激情综合色综合久久| 日韩女优视频免费观看| 激情五月激情综合网| 久久亚洲精精品中文字幕早川悠里 | 久久激情五月婷婷| 国产精品免费丝袜| 6080yy午夜一二三区久久| 国产激情一区二区三区| 一区二区三区欧美亚洲| 日韩欧美精品在线| 91亚洲资源网| 激情文学综合网| 亚洲一区二区三区精品在线| 久久午夜电影网| 欧美日韩亚洲综合在线| 成人国产精品免费观看视频| 日韩av电影天堂| 亚洲欧美日韩国产综合| 精品久久一二三区| 欧美日免费三级在线| 丰满白嫩尤物一区二区| 日韩成人精品视频| 日韩毛片精品高清免费| 久久人人97超碰com| 欧美日韩高清一区二区不卡| 99久久免费视频.com| 黄色日韩三级电影| 视频一区二区欧美| 亚洲美女屁股眼交| 欧美激情在线观看视频免费| 一区二区三区电影在线播| 久久久久97国产精华液好用吗| 欧美日韩国产天堂| 91免费在线播放| 国产成人综合在线| 久久狠狠亚洲综合| 污片在线观看一区二区| 亚洲一区二区三区中文字幕| 中文字幕一区二区三区精华液| 国产亚洲综合在线| 精品久久久久99| 欧美一区二区三区性视频| 欧美在线色视频| 91视频在线观看| 波多野结衣的一区二区三区| 国产精品456露脸| 久久66热偷产精品| 日av在线不卡| 视频在线观看一区二区三区| 亚洲最新视频在线观看| 亚洲激情图片一区| **欧美大码日韩| 国产精品护士白丝一区av| 国产色综合久久| 国产午夜精品美女毛片视频| 欧美zozo另类异族| 26uuu色噜噜精品一区| 日韩三级精品电影久久久| 6080yy午夜一二三区久久| 欧美丰满少妇xxxxx高潮对白| 欧美日韩视频在线观看一区二区三区| 在线视频欧美精品| 欧美午夜精品一区二区三区| 欧美视频日韩视频| 欧美日韩一级视频| 欧美高清你懂得| 4438x亚洲最大成人网| 在线观看91精品国产麻豆| 在线播放一区二区三区| 欧美一区二区视频在线观看2020| 91精品国产欧美日韩| 日韩无一区二区| 欧美tk丨vk视频| 亚洲精品一区二区三区99| 国产亚洲女人久久久久毛片| 国产日韩欧美高清在线| 国产精品高潮久久久久无| 亚洲精品大片www| 亚洲五月六月丁香激情| 欧美bbbbb| 国产精品自拍一区| 成人av网站免费|