Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) SiteWhere, LLC. All rights reserved. http://www.sitewhere.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
  package com.sitewhere.device.communication;
  
 import java.util.Map;
 
 
Implementation of com.sitewhere.spi.device.communication.IOutboundCommandRouter that maps specification ids to com.sitewhere.spi.device.communication.ICommandDestination ids and routes accordingly.

Author(s):
Derek
 
Static logger instance
 
 	private static Logger LOGGER = Logger.getLogger(SpecificationMappingCommandRouter.class);

Map of specification tokens to command destination ids
 
 	private Map<StringStringmappings = new HashMap<StringString>();

Default destination for unmapped specifications
 
 	private String defaultDestination = null;
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#start()
 	 */
 	public void start() throws SiteWhereException {
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#getLogger()
 	 */
 	public Logger getLogger() {
 		return ;
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#stop()
 	 */
 	public void stop() throws SiteWhereException {
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see
 	 * com.sitewhere.spi.device.communication.IOutboundCommandRouter#routeCommand(com.
 	 * sitewhere.spi.device.command.IDeviceCommandExecution,
 	 * com.sitewhere.spi.device.IDeviceNestingContext,
 	 * com.sitewhere.spi.device.IDeviceAssignment)
 	 */
 	public void routeCommand(IDeviceCommandExecution executionIDeviceNestingContext nesting,
 			IDeviceAssignment assignmentthrows SiteWhereException {
 		ICommandDestination<?, ?> destination = getDestinationForDevice(nesting);
 		destination.deliverCommand(executionnestingassignment);
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see
 	 * com.sitewhere.spi.device.communication.IOutboundCommandRouter#routeSystemCommand
 	 * (com.sitewhere.spi.device.command.ISystemCommand,
 	 * com.sitewhere.spi.device.IDeviceNestingContext,
 	 * com.sitewhere.spi.device.IDeviceAssignment)
 	 */
 	public void routeSystemCommand(ISystemCommand commandIDeviceNestingContext nesting,
 			IDeviceAssignment assignmentthrows SiteWhereException {
 		ICommandDestination<?, ?> destination = getDestinationForDevice(nesting);
 		destination.deliverSystemCommand(commandnestingassignment);
 	}

Get com.sitewhere.spi.device.communication.ICommandDestination for device based on specification token associated with the device.

Parameters:
device
Returns:
Throws:
com.sitewhere.spi.SiteWhereException
		String specToken = nesting.getGateway().getSpecificationToken();
		String destinationId = .get(specToken);
		if (destinationId == null) {
			if (getDefaultDestination() != null) {
				destinationId = getDefaultDestination();
else {
				throw new SiteWhereException("No command destination mapping for specification: " + specToken);
			}
		}
		ICommandDestination<?, ?> destination = getDestinations().get(destinationId);
		if (destination == null) {
			throw new SiteWhereException("No destination found for destination id: " + destinationId);
		}
		return destination;
	}
	public Map<StringStringgetMappings() {
		return ;
	}
	public void setMappings(Map<StringStringmappings) {
		this. = mappings;
	}
	}
	public void setDefaultDestination(String defaultDestination) {
		this. = defaultDestination;
	}
New to GrepCode? Check out our FAQ X