ParameterClient.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.node.client;
00018 
00019 import com.google.common.collect.Lists;
00020 
00021 import org.ros.internal.node.response.BooleanResultFactory;
00022 import org.ros.internal.node.response.IntegerResultFactory;
00023 import org.ros.internal.node.response.ObjectResultFactory;
00024 import org.ros.internal.node.response.Response;
00025 import org.ros.internal.node.response.StringListResultFactory;
00026 import org.ros.internal.node.response.StringResultFactory;
00027 import org.ros.internal.node.response.VoidResultFactory;
00028 import org.ros.internal.node.server.NodeIdentifier;
00029 import org.ros.internal.node.server.ParameterServer;
00030 import org.ros.internal.node.xmlrpc.ParameterServerXmlRpcEndpoint;
00031 import org.ros.namespace.GraphName;
00032 
00033 import java.net.URI;
00034 import java.util.List;
00035 import java.util.Map;
00036 
00043 public class ParameterClient extends Client<ParameterServerXmlRpcEndpoint> {
00044 
00045   private final NodeIdentifier nodeIdentifier;
00046   private final String nodeName;
00047 
00055   public ParameterClient(NodeIdentifier nodeIdentifier, URI uri) {
00056     super(uri, ParameterServerXmlRpcEndpoint.class);
00057     this.nodeIdentifier = nodeIdentifier;
00058     nodeName = nodeIdentifier.getName().toString();
00059   }
00060 
00061   public Response<Object> getParam(GraphName parameterName) {
00062     return Response.fromListCheckedFailure(xmlRpcEndpoint.getParam(nodeName, parameterName.toString()),
00063         new ObjectResultFactory());
00064   }
00065 
00066   public Response<Void> setParam(GraphName parameterName, Boolean parameterValue) {
00067     return Response.fromListChecked(
00068         xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
00069   }
00070 
00071   public Response<Void> setParam(GraphName parameterName, Integer parameterValue) {
00072     return Response.fromListChecked(
00073         xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
00074   }
00075 
00076   public Response<Void> setParam(GraphName parameterName, Double parameterValue) {
00077     return Response.fromListChecked(
00078         xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
00079   }
00080 
00081   public Response<Void> setParam(GraphName parameterName, String parameterValue) {
00082     return Response.fromListChecked(
00083         xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
00084   }
00085 
00086   public Response<Void> setParam(GraphName parameterName, List<?> parameterValue) {
00087     return Response.fromListChecked(
00088         xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
00089   }
00090 
00091   public Response<Void> setParam(GraphName parameterName, Map<?, ?> parameterValue) {
00092     return Response.fromListChecked(
00093         xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
00094   }
00095 
00096   public Response<GraphName> searchParam(GraphName parameterName) {
00097     Response<String> response =
00098         Response.fromListCheckedFailure(xmlRpcEndpoint.searchParam(nodeName, parameterName.toString()),
00099             new StringResultFactory());
00100     return new Response<GraphName>(response.getStatusCode(), response.getStatusMessage(),
00101         GraphName.of(response.getResult()));
00102   }
00103 
00104   public Response<Object> subscribeParam(GraphName parameterName) {
00105     return Response.fromListChecked(xmlRpcEndpoint.subscribeParam(nodeName, nodeIdentifier.getUri()
00106         .toString(), parameterName.toString()), new ObjectResultFactory());
00107   }
00108 
00109   public Response<Integer> unsubscribeParam(GraphName parameterName) {
00110     return Response.fromListChecked(
00111         xmlRpcEndpoint.unsubscribeParam(nodeName, nodeIdentifier.getUri().toString(),
00112             parameterName.toString()), new IntegerResultFactory());
00113   }
00114 
00115   public Response<Boolean> hasParam(GraphName parameterName) {
00116     return Response.fromListChecked(xmlRpcEndpoint.hasParam(nodeName, parameterName.toString()),
00117         new BooleanResultFactory());
00118   }
00119 
00120   public Response<Void> deleteParam(GraphName parameterName) {
00121     return Response.fromListChecked(xmlRpcEndpoint.deleteParam(nodeName, parameterName.toString()),
00122         new VoidResultFactory());
00123   }
00124 
00125   public Response<List<GraphName>> getParamNames() {
00126     Response<List<String>> response =
00127         Response.fromListChecked(xmlRpcEndpoint.getParamNames(nodeName), new StringListResultFactory());
00128     List<GraphName> graphNames = Lists.newArrayList();
00129     for (String name : response.getResult()) {
00130       graphNames.add(GraphName.of(name));
00131     }
00132     return new Response<List<GraphName>>(response.getStatusCode(), response.getStatusMessage(),
00133         graphNames);
00134   }
00135 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49