120 lines
3.2 KiB
Java
120 lines
3.2 KiB
Java
package com.eactive.eai.agent.command;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
* 1. 기능 : Agent에 의해 실행될 Command 를 정의하기 위한 base class
|
|
* 2. 처리 개요 : Agent에 의해 실행될 Command 를 정의하기 위한 base class
|
|
* 3. 주의사항
|
|
*
|
|
* @author
|
|
* @version v 1.0.0
|
|
* @see 관련 기능을 참조
|
|
* @since
|
|
*
|
|
*/
|
|
public abstract class Command implements Serializable {
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
/** Command object name */
|
|
protected String name;
|
|
/** Command Arguments */
|
|
protected Object args;
|
|
|
|
private HashMap<String,String> errorCode ;
|
|
|
|
static {
|
|
HashMap<String,String> errorCode = new HashMap<String,String>();
|
|
errorCode.put("RECEAIMCM001", "Command 이름[{1}] 유효하지 않은 파라메터 타입 - {2}");
|
|
errorCode.put("RECEAIMCM002", "Command 이름[{1}] execute 메소드 실행중 에러가 발생 - {2}");
|
|
}
|
|
|
|
|
|
/**
|
|
* 1. 기능 : Default Constructor
|
|
* 2. 처리 개요 : name을 Class name으로 setting한다.
|
|
* 3. 주의사항
|
|
*
|
|
**/
|
|
public Command() {
|
|
this.name = this.getClass().getName();
|
|
}
|
|
|
|
/**
|
|
* 1. 기능 : 파리미터의 name을 setting하는 Constructor
|
|
* 2. 처리 개요 :
|
|
* 3. 주의사항
|
|
*
|
|
* @param name Command object name
|
|
**/
|
|
public Command(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
/**
|
|
* 1. 기능 : command의 arguments를 setting하는 setter method
|
|
* 2. 처리 개요 : command의 arguments를 setting하는 setter method
|
|
* 3. 주의사항
|
|
*
|
|
* @param args command arguments
|
|
**/
|
|
public void setArgs(Object args) {
|
|
this.args = args;
|
|
}
|
|
|
|
|
|
/**
|
|
* 1. 기능 : command의 business logic method<br>
|
|
* 2. 처리 개요 : command의 business logic method<br>
|
|
* 3. 주의사항
|
|
*
|
|
* @exception CommandException
|
|
**/
|
|
public abstract Object execute() throws CommandException;
|
|
|
|
/**
|
|
* 1. 기능 : 에러 Message 생성
|
|
* 2. 처리 개요 : 에러코드와 Exception cause로 에러 메시지 생성
|
|
* 3. 주의사항
|
|
*
|
|
* @param rspErrorcode EAI 에러코드
|
|
* @param cause Exception cause
|
|
* @return String 에러 메시지
|
|
* @exception CommandException
|
|
**/
|
|
protected String makeException(String rspErrorCode, Throwable cause) throws CommandException{
|
|
String[] msgArgs = new String[2];
|
|
msgArgs[0] = name;
|
|
if(cause == null){
|
|
msgArgs[1] = args.toString();
|
|
}
|
|
else{
|
|
msgArgs[1] = cause.getMessage();
|
|
}
|
|
String msg = makeMessage((String)errorCode.get(rspErrorCode),msgArgs) ;
|
|
|
|
return msg;
|
|
}
|
|
|
|
protected static String makeMessage(String msg, String[] args) {
|
|
String keyword = null, head = null, tail = null;
|
|
int idx = -1;
|
|
for(int i=0;i<args.length;i++) {
|
|
keyword = "{"+(i+1)+"}";
|
|
idx = msg.indexOf(keyword);
|
|
if(idx == -1) {
|
|
continue;
|
|
}
|
|
head = msg.substring(0,idx);
|
|
tail = msg.substring(idx+keyword.length());
|
|
msg = head+args[i]+tail;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
|
|
}
|