Go to the documentation of this file.00001 package org.rosbuilding.common.media;
00002
00003 import java.util.Arrays;
00004 import java.util.List;
00005
00006 import smarthome_media_msgs.MediaAction;
00007 import smarthome_comm_msgs.Command;
00008
00009 import org.ros.node.ConnectedNode;
00010 import org.rosbuilding.common.IModule;
00011 import org.rosbuilding.common.MessageConverter;
00012
00013 public class MediaMessageConverter implements MessageConverter<MediaAction> {
00014 public MediaAction toMessage(ConnectedNode node, Command command) {
00015 MediaAction mediaAction = null;
00016
00017 if (node != null) {
00018 mediaAction = node.getTopicMessageFactory()
00019 .newFromType(MediaAction._TYPE);
00020
00021 String[] action = command.getAction().split(IModule.SEP);
00022
00023 if (action.length > 1) {
00024 mediaAction.setType(action[0]);
00025 mediaAction.setMethod(action[1]);
00026 } else {
00027 mediaAction.setMethod(action[0]);
00028 }
00029
00030 String subject = command.getSubject();
00031 if (subject.startsWith(IModule.URI_DATA)) {
00032 List<String> data = Arrays.asList(
00033 subject.substring(IModule.URI_DATA.length())
00034 .split(IModule.SEP));
00035
00036 mediaAction.setData(data);
00037 } else {
00038 mediaAction.setUri(command.getSubject());
00039 }
00040 }
00041 return mediaAction;
00042 }
00043 }