CommandFactory.java 1.25 KB
Newer Older
TongZuu committed
1 2
package com.csc.library.factory;

TongZuu committed
3 4 5
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
TongZuu committed
6 7 8

import com.csc.library.command.CommandBase;
import com.csc.library.command.CscCommand;
TongZuu committed
9
import com.csc.library.modecontroller.CMDModeManagement;
TongZuu committed
10 11 12
import com.csc.library.properties.CscSession;
import com.csc.library.request.CMDMode;
import com.csc.library.request.RequestWebsocket;
TongZuu committed
13
import com.csc.library.session.InitialEnvironment;
TongZuu committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

public class CommandFactory {
	private static CommandFactory instance;
	
	private CommandFactory(){
	}
	
	public static CommandFactory getInstance(){
		if(instance == null){
			instance = new CommandFactory();
		}
		return instance;
	}
	
	public CscCommand getCommand(CscSession session ,RequestWebsocket req){
		CommandBase command = null;
TongZuu committed
30 31 32 33 34 35 36 37 38 39
		try{
			CMDModeManagement.ModeBuilder builder = CMDModeFactory.getInstance().getModeBuilder(req.getCommandMode());
			String className = builder.getClassName(req.getCommandCode());
			Class c = Class.forName("com.csc.library.command."+className);
			command = (CommandBase)c.newInstance();
			command.setRequest(req);
			command.setSession(session);
			command.setParamConfig(builder.getParamConfig(req.getCommandCode()));
		}catch(Exception e){
			e.printStackTrace();
TongZuu committed
40 41 42 43
		}
		return command;
	}
}