您的位置:首页 > 其它

Command

2012-04-13 17:24 60 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/standyxu/article/details/84185830

 

public abstract class Command
{

protected SecurityContext securityContext = null;
protected Map<String, Object> arguments = null;
protected Command.status status = null;
protected Command.exitCode exitCode = null;
private final static String ERROR_MESSAGE = "errorMessage";
private final static String EXIT_CODE = "exitCode";
private Map<String, Object> exitStatus;

public enum status
{

WAITING, RUNNING, FINISHED
}

public enum exitCode
{

UNKNOWN, SUCCESS, FAILURE
}

public Command()
{
this.arguments = new ConcurrentHashMap<String, Object>(10, 0.9f, 8);
this.exitStatus = new ConcurrentHashMap<String, Object>(10, 0.9f, 8);

// Set default
exitStatus.put(EXIT_CODE, exitCode.UNKNOWN);
}

/**
* Executes this command. Override this method to implement your service-
* specific behaviour.
*
* @param parameters the parameters
* @return the result
*/
public abstract Object execute(Object... parameters) throws FrameworkException;

/**
* Returns the service class this command belongs to. Implement this method
* in an abstrac base class and derive all you service commands from this
* class.
*
* @return the service this command belongs to
*/
public abstract Class getServiceClass();

/**
* Sets an argument for this command. Call this method from within
* {@see org.structr.core.Service#injectArguments}.
*
* @param key   the key
* @param value the value
*/
public final void setArgument(String key, Object value)
{
if (key != null && value != null)
{
this.arguments.put(key, value);
}
}

/**
* Returns a previously set argument for this command.
*
* @param key the key
* @return the argument or null if no such argument exists.
*/
public final Object getArgument(String key)
{
return (this.arguments.get(key));
}

public Command.status getStatus()
{
return status;
}

public void setStatus(final Command.status status)
{
this.status = status;
}

public Command.exitCode getExitCode()
{
return (Command.exitCode) exitStatus.get(EXIT_CODE);
}

public void setExitCode(final Command.exitCode exitCode)
{
if (exitCode != null)
{
this.exitStatus.put(EXIT_CODE, exitCode);
}
}

public String getErrorMessage()
{
return (String) exitStatus.get("errorMessage");
}

public void setErrorMessage(final String errorMessage)
{
if (errorMessage != null)
{
this.exitStatus.put(ERROR_MESSAGE, errorMessage);
}
}

public void setSecurityContext(SecurityContext securityContext)
{
this.securityContext = securityContext;
}
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: