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; 00018 00019 import org.ros.internal.message.service.ServiceRequestMessageFactory; 00020 import org.ros.internal.message.service.ServiceResponseMessageFactory; 00021 import org.ros.message.MessageDefinitionProvider; 00022 import org.ros.message.MessageDeserializer; 00023 import org.ros.message.MessageFactory; 00024 import org.ros.message.MessageIdentifier; 00025 import org.ros.message.MessageSerializationFactory; 00026 import org.ros.message.MessageSerializer; 00027 00031 public class DefaultMessageSerializationFactory implements MessageSerializationFactory { 00032 00033 private final MessageFactory topicMessageFactory; 00034 private final ServiceRequestMessageFactory serviceRequestMessageFactory; 00035 private final ServiceResponseMessageFactory serviceResponseMessageFactory; 00036 00037 public DefaultMessageSerializationFactory(MessageDefinitionProvider messageDefinitionProvider) { 00038 topicMessageFactory = new DefaultMessageFactory(messageDefinitionProvider); 00039 serviceRequestMessageFactory = new ServiceRequestMessageFactory(messageDefinitionProvider); 00040 serviceResponseMessageFactory = new ServiceResponseMessageFactory(messageDefinitionProvider); 00041 } 00042 00043 @SuppressWarnings("unchecked") 00044 @Override 00045 public <T> MessageSerializer<T> newMessageSerializer(String messageType) { 00046 return (MessageSerializer<T>) new DefaultMessageSerializer(); 00047 } 00048 00049 @Override 00050 public <T> MessageDeserializer<T> newMessageDeserializer(String messageType) { 00051 return new DefaultMessageDeserializer<T>(MessageIdentifier.of(messageType), 00052 topicMessageFactory); 00053 } 00054 00055 @SuppressWarnings("unchecked") 00056 @Override 00057 public <T> MessageSerializer<T> newServiceRequestSerializer(String serviceType) { 00058 return (MessageSerializer<T>) new DefaultMessageSerializer(); 00059 } 00060 00061 @Override 00062 public <T> org.ros.message.MessageDeserializer<T> 00063 newServiceRequestDeserializer(String serviceType) { 00064 return new DefaultMessageDeserializer<T>(MessageIdentifier.of(serviceType), 00065 serviceRequestMessageFactory); 00066 } 00067 00068 @SuppressWarnings("unchecked") 00069 @Override 00070 public <T> org.ros.message.MessageSerializer<T> newServiceResponseSerializer(String serviceType) { 00071 return (MessageSerializer<T>) new DefaultMessageSerializer(); 00072 } 00073 00074 @Override 00075 public <T> org.ros.message.MessageDeserializer<T> newServiceResponseDeserializer( 00076 String serviceType) { 00077 return new DefaultMessageDeserializer<T>(MessageIdentifier.of(serviceType), 00078 serviceResponseMessageFactory); 00079 } 00080 }