package com.dotosoft.dot4command.base;

import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dotosoft.dot4command.chain.Filter;
import com.dotosoft.dot4command.chain.Processing;

public abstract class CommandBase<K extends String, V extends Object, C extends Map<K, V>> implements Filter<K, V, C> {

	private Logger log;
	public Logger getLog() {
		return log;
	}
	
	public CommandBase() {
		log = LoggerFactory.getLogger(getClass().getName());
	}
	
	public void onStart(C context)	{ /* DO NOTHING */ }
	public void onLeave(C context)	{ /* DO NOTHING */ }
	public abstract Processing onExecute(C context) throws Exception;
	
	public void onSuccess(C context)				{ /* DO NOTHING */ }
	public void onError(C context, Exception ex)	{ /* DO NOTHING */ }

	@Override
	public boolean postprocess(C context, Exception exception) {
		return false;
	}
	
	@Override
	public final Processing execute(C context) {
		log.info(getClass().getName() + " is processing");
		onStart(context);
		Processing result = Processing.CONTINUE;
		try {
			result = onExecute(context);
			onSuccess(context);
		} catch (Exception ex) { 
			onError(context, ex);
		}
		onLeave(context);
		return result;
	}
	
	public final Object getProperty(Object data, String expression) {
		return getProperty(data, expression, null);
	}
	
	public final Object getProperty(Object data, String expression, Object defaultValue) {
		try {
			Object returnValue = PropertyUtils.getProperty(data, expression);
			if(returnValue != null) {
				return returnValue;
			}
		} catch (Exception ex) {}
		
		return defaultValue;
	}
}

@@ -987,16 +987,19 @@
 xt) %7B%0A%09%09
+// 
 log.info
@@ -1003,46 +1003,17 @@
 nfo(
-getClass().getName() + %22 is processing
+%22%3E%3E START
 %22);%0A
@@ -1083,16 +1083,43 @@
 %09%09try %7B%0A
+%09%09%09log.info(%22%3E%3E EXECUTE%22);%0A
 %09%09%09resul
@@ -1142,16 +1142,46 @@
 ntext);%0A
+%09%09%09// log.info(%22%3E%3E SUCCESS%22);%0A
 %09%09%09onSuc
@@ -1221,17 +1221,44 @@
 on ex) %7B
- 
+%0A%09%09%09// log.info(%22%3E%3E ERROR%22);
 %0A%09%09%09onEr
@@ -1279,16 +1279,43 @@
 x);%0A%09%09%7D%0A
+%09%09// log.info(%22%3E%3E LEAVE%22);%0A
 %09%09onLeav

Set Log