All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ikasoa.rpc.handler.ProtocolHandlerFactory Maven / Gradle / Ivy

There is a newer version: 0.3.3-BETA3
Show newest version
package com.ikasoa.rpc.handler;

import lombok.SneakyThrows;

/**
 * 转换协议处理器工厂
 * 
 * @author Larry
 * @version 0.1
 */
public class ProtocolHandlerFactory {

	private static final String DEFAULT_PROTOCOL_HANDLER_CLASS_STRING = "com.ikasoa.rpc.handler.impl.JsonProtocolHandlerImpl";

	public ProtocolHandler getProtocolHandler(ReturnData resultData) {
		return getProtocolHandler(resultData, null);
	}

	@SneakyThrows
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public ProtocolHandler getProtocolHandler(ReturnData resultData,
			Class protocolHandlerClass) {
		Class[] paramTypes = { ReturnData.class };
		Object[] params = { resultData };
		return protocolHandlerClass == null
				? (ProtocolHandler) Class.forName(DEFAULT_PROTOCOL_HANDLER_CLASS_STRING)
						.getConstructor(paramTypes).newInstance(params)
				: (ProtocolHandler) protocolHandlerClass.getConstructor(paramTypes).newInstance(params);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy