ServiceDefinitionResourceProvider.java
Go to the documentation of this file.
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.service;
00018 
00019 import com.google.common.base.Preconditions;
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 ServiceDefinitionResourceProvider implements MessageDefinitionProvider {
00031 
00032   private final StringResourceProvider stringResourceProvider;
00033 
00034   public ServiceDefinitionResourceProvider() {
00035     stringResourceProvider = new StringResourceProvider();
00036   }
00037 
00038   private String serviceTypeToResourceName(String serviceType) {
00039     Preconditions.checkArgument(serviceType.contains("/"), "Service type must be fully qualified: "
00040         + serviceType);
00041     String[] packageAndType = serviceType.split("/", 2);
00042     return String.format("/%s/srv/%s.srv", packageAndType[0], packageAndType[1]);
00043   }
00044 
00045   @Override
00046   public String get(String serviceType) {
00047     return stringResourceProvider.get(serviceTypeToResourceName(serviceType));
00048   }
00049 
00050   @Override
00051   public boolean has(String serviceType) {
00052     return stringResourceProvider.has(serviceTypeToResourceName(serviceType));
00053   }
00054 
00055   public void add(String serviceType, String serviceDefinition) {
00056     stringResourceProvider.addStringToCache(serviceTypeToResourceName(serviceType),
00057         serviceDefinition);
00058   }
00059 
00060   @Override
00061   public Collection<String> getPackages() {
00062     throw new UnsupportedOperationException();
00063   }
00064 
00065   @Override
00066   public Collection<MessageIdentifier> getMessageIdentifiersByPackage(String pkg) {
00067     throw new UnsupportedOperationException();
00068   }
00069 }


rosjava_bootstrap
Author(s): Daniel Stonier , Damon Kohler
autogenerated on Fri Aug 28 2015 12:41:44