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

rpc.turbo.serialization.SerializerFactory Maven / Gradle / Ivy

The newest version!
package rpc.turbo.serialization;

/**
 * 序列化器工厂方法
 * 
 * @author Hank
 *
 */
public final class SerializerFactory {

	/**
	 * 创建一个 Serializer
	 * 
	 * @param className
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Serializer createSerializer(String className) {
		try {
			Class clazz = Class.forName(className);

			if (!Serializer.class.isAssignableFrom(clazz)) {
				throw new RuntimeException(className + " is not instance of Serializer");
			}

			return createSerializer((Class) clazz);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 创建一个 Serializer
	 * 
	 * @param clazz
	 * @return
	 */
	public static Serializer createSerializer(Class clazz) {
		try {
			return clazz.getDeclaredConstructor().newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy