00001 /* 00002 * Copyright (C) 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 00005 * use this file except in compliance with the License. You may obtain a copy of 00006 * the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 00013 * License for the specific language governing permissions and limitations under 00014 * the License. 00015 */ 00016 00017 package org.ros.internal.message.topic; 00018 00019 import com.google.common.annotations.VisibleForTesting; 00020 00021 import org.ros.internal.message.StringResourceProvider; 00022 import org.ros.message.MessageDefinitionProvider; 00023 import org.ros.message.MessageIdentifier; 00024 00025 import java.util.Collection; 00026 00030 public class TopicDefinitionResourceProvider implements MessageDefinitionProvider { 00031 00032 private final StringResourceProvider stringResourceProvider; 00033 00034 public TopicDefinitionResourceProvider() { 00035 stringResourceProvider = new StringResourceProvider(); 00036 } 00037 00038 private String topicTypeToResourceName(String topicType) { 00039 MessageIdentifier messageIdentifier = MessageIdentifier.of(topicType); 00040 return String.format("/%s/msg/%s.msg", messageIdentifier.getPackage(), 00041 messageIdentifier.getName()); 00042 } 00043 00044 @Override 00045 public String get(String topicType) { 00046 return stringResourceProvider.get(topicTypeToResourceName(topicType)); 00047 } 00048 00049 @Override 00050 public boolean has(String topicType) { 00051 return stringResourceProvider.has(topicTypeToResourceName(topicType)); 00052 } 00053 00054 @VisibleForTesting 00055 public void add(String topicType, String topicDefinition) { 00056 stringResourceProvider.addStringToCache(topicTypeToResourceName(topicType), topicDefinition); 00057 } 00058 00059 @Override 00060 public Collection<String> getPackages() { 00061 throw new UnsupportedOperationException(); 00062 } 00063 00064 @Override 00065 public Collection<MessageIdentifier> getMessageIdentifiersByPackage(String pkg) { 00066 throw new UnsupportedOperationException(); 00067 } 00068 }