package com.eactive.eai.agent.transformer;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.transformer.transform.TransformManager;

public class RemoveTransformCommand extends Command {
	private static final long serialVersionUID = 1L;

	public RemoveTransformCommand() {
		super("RemoveTransformCommand");
	}

	public Object execute() throws CommandException {
		Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
		if (logger.isInfo())
			logger.info(this.name + " is executed");

		if (!(args instanceof String)) {
			String rspErrorCode = "RECEAIMCM001";
			String msg = makeException(rspErrorCode, null);
			if (logger.isError())
				logger.error(msg);
			throw new CommandException(msg);
		}

		try {
			TransformManager manager = TransformManager.getManager();

			String transformName = (String) args;
			if (transformName != null && transformName.trim().length() > 0) {
				manager.remove(transformName);
				if (logger.isWarn())
					logger.warn("RemoveTransformCommand ] " + transformName + " 에 대한 Transform 정보가 삭제되었습니다.");
			} else {
				if (logger.isWarn())
					logger.warn("ReloadLayoutCommand ] Transform 명을 확인하세요 [" + transformName + "]");
			}
		} catch (Exception e) {
			String rspErrorCode = "RECEAIMCM002";
			String msg = makeException(rspErrorCode, e);
			if (logger.isError())
				logger.error(msg, e);
			throw new CommandException(msg);
		}
		return "success";

	}

//	   public static void main(String args[]) throws Exception {
//	   test();
//}

// private static void test() throws Exception {
//        
//        TransformManager manager = TransformManager.getManager();
//        
//        Command command = new RemoveTransformCommand();
//        command.setArgs("");
//        AgentUtil.broadcast(command);
//        
//    }
}
