⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandfactory.java

📁 关于 RFID 读写器的相关内容
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				return ncCommand.addSources(srcs);
			}
			else if (command.equals("removeSources")) {
				Source[] srcs = toSourceArray(params[0].getCollection());
				return ncCommand.removeSources(srcs);
			}
			else if (command.equals("getAllSources")) {
				return ncCommand.getAllSources();
			}
			else if (command.equals("addNotificationTriggers")) {
				Trigger[] trgs = toTriggerArray(params[0].getCollection());
				return ncCommand.addNotificationTriggers(trgs);
			}
			else if (command.equals("removeNotificationTriggers")) {
				Trigger[] trgs = toTriggerArray(params[0].getCollection());
				return ncCommand.removeNotificationTriggers(trgs);
			}
			else if (command.equals("removeAllNotificationTriggers")) {
				return ncCommand.removeAllNotificationTriggers();
			}
			else if (command.equals("getNotificationTrigger")) {
				return ncCommand.getNotificationTrigger(params[0].getString());
			}
			else if (command.equals("getAllNotificationTriggers")) {
				return ncCommand.getAllNotificationTriggers();
			}
			else if (command.equals("readQueuedData")) {
				NotificationChannelCommand.ReadQueuedData rq = cmdFactory.createNotificationChannelCommandReadQueuedData();
				if (params.length > 0) {
					return ncCommand.readQueuedData(params[0].getBoolean());
				} else {
					return ncCommand.readQueuedData();
				}
			}
		}
		else if (object.equals("Trigger")) {
			TriggerSerializer trgCommand = new org.fosstrak.reader.rp.proxy.msg.stubs.serializers.text.TriggerSerializerImpl(getNextId(),target);
			if (command.equals("create")) {
				return trgCommand.create(params[0].getString(),params[1].getString(),params[2].getString());
			}
			else if (command.equals("getMaxNumberSupported")) {
				return trgCommand.getMaxNumberSupported();
			}
			else if (command.equals("getName")) {
				return trgCommand.getName();
			}
			else if (command.equals("getType")) {
				return trgCommand.getType();
			}
			else if (command.equals("getValue")) {
				return trgCommand.getValue();
			}
			else if (command.equals("fire")) {
				return trgCommand.fire();
			}
		
		}
		else if (object.equals("EventType")) {
			EventTypeSerializer evCommand = new org.fosstrak.reader.rp.proxy.msg.stubs.serializers.text.EventTypeSerializerImpl(getNextId(), target);
			if (command.equals("getSupportedTypes")) {
				return evCommand.getSupportedTypes();
			}
		}
		else if (object.equals("TriggerType")) {
			TriggerTypeSerializer ttCommand = new org.fosstrak.reader.rp.proxy.msg.stubs.serializers.text.TriggerTypeSerializerImpl(getNextId(), target);
			if (command.equals("getSupportedTypes")) {
				return ttCommand.getSupportedTypes();
			}
			
			
		}
		else if (object.equals("FieldName")) {
			FieldNameSerializer fnCommand = new org.fosstrak.reader.rp.proxy.msg.stubs.serializers.text.FieldNameSerializerImpl(getNextId(), target);
			if (command.equals("getSupportedNames")) {
				return fnCommand.getSupportedNames();
			}
			
		}
		else if (object.equals("TagField")) {
			TagFieldSerializer tfCommand = new org.fosstrak.reader.rp.proxy.msg.stubs.serializers.text.TagFieldSerializerImpl(getNextId(), target);
			if (command.equals("create")) {
				return tfCommand.create(params[0].getString());
			}
			else if (command.equals("getName")) {
				return tfCommand.getName();
			}
			else if (command.equals("getTagFieldName")) {
				return tfCommand.getTagFieldName();
			}
			else if (command.equals("setTagFieldName")) {
				return tfCommand.setTagFieldName(params[0].getString());
			}
			else if (command.equals("getMemoryBank")) {
				return tfCommand.getMemoryBank();
			}
			else if (command.equals("setMemoryBank")) {
				return tfCommand.setMemoryBank(params[0].getInt());
			}
			else if (command.equals("getOffset")) {
				return tfCommand.getOffset();
			}
			else if (command.equals("setOffset")) {
				return tfCommand.setOffset(params[0].getInt());
			}
			else if (command.equals("getLength")) {
				return tfCommand.getLength();
			}
			else if (command.equals("setLength")) {
				return tfCommand.setLength(params[0].getInt());
			}
			
		}
		else if (object.equals("IOPorts")) {
			
		}
		
		String xmlCommand = serializeCommand(cmd);
		return xmlCommand;
		
	}
	
	//
	// private methods
	//
	
	/** the msg command JAXBContext **/
	private static JAXBContext context = null;
	
	/** the msg command Marshaller **/
	private static Marshaller marshaller = null;
	
	/**
	 * This method serialize a command.
	 * 
	 * @param cmd command to serialize
	 * @return the serialized command as string
	 */
	private static String serializeCommand(Command cmd) {
		
		try {
			if (context == null) {
			   context = JAXBContext
			         .newInstance("org.fosstrak.reader.rprm.core.msg.command");
			}
			if (marshaller == null) {
			   marshaller = context.createMarshaller();
			   marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT,
			         Boolean.TRUE );
			}
			StringWriter sw = new StringWriter();
			try {
				marshaller.marshal(cmd,sw);
			} catch (JAXBException e) {
				throw new MessageSerializingException(e);
			}
			return sw.getBuffer().toString();
		} catch (Exception e) {
			return "";
		}
		
	}
	
	/**
	 * This method returns the next message id.
	 * 
	 * @return next message id
	 */
	private static int getNextId() {
		
		counter++;
		return counter;
		
	}
	
	/**
	 * This method transforms a collection of sources to a source array.
	 * 
	 * @param collection of sources
	 * @return source array
	 */
	private static Source[] toSourceArray(Collection collection) {
		
		try {
			Source[] sources = new Source[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				Source src = Source.create((String)it.next());
				sources[index] = src;
				index++;
			}
			return sources;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of data selectors to a data selector array.
	 * 
	 * @param collection of data selectors
	 * @return data selector array
	 */
	private static DataSelector[] toDataSelectorArray(Collection collection) {
		
		try {
			DataSelector[] dataSelectors = new DataSelector[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				DataSelector ds = DataSelector.create((String)it.next());
				dataSelectors[index] = ds;
				index++;
			}
			return dataSelectors;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of notification channels to a notification channel array.
	 * 
	 * @param collection of notification channels
	 * @return notifiction channel array
	 */
	private static NotificationChannel[] toNotificationChannelArray(Collection collection) {
		
		try {
			NotificationChannel[] notificationChannels = new NotificationChannel[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				NotificationChannel nc = NotificationChannel.create((String)it.next(), null);
				notificationChannels[index] = nc;
				index++;
			}
			return notificationChannels;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of triggers to a trigger array.
	 * 
	 * @param collection of triggers
	 * @return trigger array
	 */
	private static Trigger[] toTriggerArray(Collection collection) {
		
		try {
			Trigger[] triggers = new Trigger[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				Trigger trg = Trigger.create((String)it.next());
				triggers[index] = trg;
				index++;
			}
			return triggers;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of tag selectors to a tag selector array.
	 * 
	 * @param collection of tag selectors
	 * @return tag selector array
	 */
	private static TagSelector[] toTagSelectorArray(Collection collection) {
		
		try {
			TagSelector[] tagSelectors = new TagSelector[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				TagSelector ts = TagSelector.create((String)it.next(),null,null,null,false);
				tagSelectors[index] = ts;
				index++;
			}
			return tagSelectors;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of tag fields to a tag field array.
	 * 
	 * @param collection of tag fields
	 * @return tag field array
	 */
	private static TagField[] toTagFieldArray(Collection collection) {
		
		try {
			TagField[] tagFields = new TagField[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				TagField tf = TagField.create((String)it.next());
				tagFields[index] = tf;
				index++;
			}
			return tagFields;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of read point to a read point array.
	 * 
	 * @param collection of read points
	 * @return read point array
	 */
	private static ReadPoint[] toReadPointArray(Collection collection) {
		
		try {
			ReadPoint[] readPoints = new ReadPoint[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				ReadPoint rp = ReadPoint.create((String)it.next(),null,null);
				readPoints[index] = rp;
				index++;
			}
			return readPoints;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This method transforms a collection of tag field values to a tag field value array.
	 * 
	 * @param collection of tag field values
	 * @return tag field value array
	 */
	private static TagFieldValue[] toTagFieldValueArray(Collection collection) {
		
		try {
			TagFieldValue[] readPoints = new TagFieldValue[collection.size()];
			Iterator it = collection.iterator();
			int index = 0;
			while(it.hasNext()) {
				//TODO: implementation not finished
				String tagFieldValue = (String)it.next();
				int commaPosition = tagFieldValue.indexOf(';');
				TagFieldValue rp = new TagFieldValue(tagFieldValue.substring(1, commaPosition), tagFieldValue.substring(commaPosition + 1, tagFieldValue.length() - 1));
				readPoints[index] = rp;
				index++;
			}
			return readPoints;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -