Message02Factory.java 900 Bytes
package com.bsth.socket.protocol;

import com.bsth.util.ConvertUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Hill
 */
public class Message02Factory {
	
	private final static Logger log = LoggerFactory.getLogger(Message02Factory.class);

	public static IMessageBody02 create(int commandType, byte[] data, int idx) {
		String pkgName = Message02Factory.class.getPackage().getName();
		IMessageBody02 body = null;
		try {
			System.out.println(pkgName + ".Message02" + String.format("%02x", commandType));
			Class<?> cls = Class.forName(pkgName + ".Message02" + String.format("%02x", commandType));
			body = (IMessageBody02)cls.newInstance();
			body.read(data, idx);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error("Message02Factory create: " + ConvertUtil.toHexString(data), e);
			throw new RuntimeException();
		}

		return body;
	}
}