LOG.debug("The '" + actionConfig.getName()
+ viewActionPostfix + "' action is overridden in '"
+ packageName + "' package.");
}
} else {
ResultConfig inputResultConfig = actionConfig.getResults().get(
Action.INPUT);
if (inputResultConfig == null) {
throw new ConfigurationException("There is no '"
+ Action.INPUT + "' result defined for action '"
+ actionConfig.getName() + "' in '" + packageName
+ "' package.", actionConfig);
}
ResultConfig resultConfig = new ResultConfig.Builder(
Action.SUCCESS, inputResultConfig.getClassName())
.addParams(inputResultConfig.getParams()).build();
// build action configuration
ActionConfig act = new ActionConfig.Builder(packageName,
actionConfig.getName() + viewActionPostfix,
actionConfig.getClassName())
.methodName(viewActionMethod)
.addInterceptors(actionConfig.getInterceptors())
.addResultConfig(resultConfig).build();
viewActionConfigs.add(act);
}
String nextKey = null;
if (mapkeyitr.hasNext()) {
// peek
nextKey = mapkeyitr.next();
mapkeyitr.previous();
}
String nextActionVal = null;
String prevActionVal = null;
if (nextKey == null) {
nextActionVal = null;
} else {
ActionConfig nextActionConfig = actionsStepMap.get(nextKey);
nextActionVal = nextActionConfig.getName();
}
if (prevKey == null) {
prevActionVal = ActionFlowInterceptor.FIRST_FLOW_ACTION_NAME;
// first action
ActionFlowStepConfig.Builder stepConfigBuilder = new ActionFlowStepConfig.Builder(
0, actionConfig.getName(),
ActionFlowInterceptor.FIRST_FLOW_ACTION_NAME);
ActionFlowStepConfig stepConfig = stepConfigBuilder.build();
actionFlows.put(ActionFlowInterceptor.FIRST_FLOW_ACTION_NAME,
stepConfig);
} else {
prevActionVal = actionsStepMap.get(prevKey).getName();
}
ActionFlowStepConfig.Builder stepConfigBuilder = new ActionFlowStepConfig.Builder(
index, nextActionVal, prevActionVal);
ActionFlowStepConfig stepConfig = stepConfigBuilder.build();
actionFlows.put(actionConfig.getName(), stepConfig);
prevKey = key;
index++;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Created action flow mapping: " + actionFlows);
}
if (actionFlows != null && !actionFlows.isEmpty()) {
// build new package configuration with special actions
PackageConfig.Builder pcb = new PackageConfig.Builder(packageConfig);
// view global result check
if (packageConfig.getAllGlobalResults().containsKey(
ActionFlowInterceptor.GLOBAL_VIEW_RESULT)) {
ResultConfig rs = packageConfig.getAllGlobalResults().get(
ActionFlowInterceptor.GLOBAL_VIEW_RESULT);
if (!ServletActionRedirectResult.class.getName().equals(
rs.getClassName())) {
throw new ConfigurationException(
"The '"
+ ActionFlowInterceptor.GLOBAL_VIEW_RESULT
+ "' global result type must be 'redirectAction' in package '"
+ packageName + "'.", rs);
} else if (!("${" + ActionFlowInterceptor.VIEW_ACTION_PARAM + "}")
.equals(rs.getParams().get(
ServletActionRedirectResult.DEFAULT_PARAM))) {
throw new ConfigurationException("The '"
+ ActionFlowInterceptor.GLOBAL_VIEW_RESULT
+ "' global result '"
+ ServletActionRedirectResult.DEFAULT_PARAM
+ "' parameter must be '${"
+ ActionFlowInterceptor.VIEW_ACTION_PARAM
+ "}' in package '" + packageName + "'.", rs);
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("There is no 'view' global result with name '"
+ ActionFlowInterceptor.GLOBAL_VIEW_RESULT
+ "' defined in '" + packageName
+ "' package. Creating one.", packageConfig);
}
// add view global result
ResultConfig viewGlobalResult = new ResultConfig.Builder(
ActionFlowInterceptor.GLOBAL_VIEW_RESULT,
ServletActionRedirectResult.class.getName()).addParam(
ServletActionRedirectResult.DEFAULT_PARAM,
"${" + ActionFlowInterceptor.VIEW_ACTION_PARAM + "}")
.build();
pcb.addGlobalResultConfig(viewGlobalResult);
}
// add view actions
if (viewActionConfigs != null && !viewActionConfigs.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("View action configurations: "
+ viewActionConfigs);
}
for (ActionConfig ac : viewActionConfigs) {
pcb.addActionConfig(ac.getName(), ac);
}
}
// TODO add interceptors ?
// previous action
if (actionConfigs.containsKey(prevActionName)) {
if (LOG.isDebugEnabled()) {
LOG.debug("The '" + prevActionName
+ "' action is overridden in '" + packageName
+ "' package.");
}
// previous action check
Map<String, ResultConfig> rs = actionConfigs
.get(prevActionName).getResults();
if (rs == null
|| rs.isEmpty()
|| !rs.containsKey(Action.SUCCESS)
|| !ServletActionRedirectResult.class.getName().equals(
rs.get(Action.SUCCESS).getClassName())) {
throw new ConfigurationException("The '" + prevActionName
+ "' action must define '" + Action.SUCCESS
+ "' result of 'redirectAction' type in package '"
+ packageName + "'.",
actionConfigs.get(prevActionName));
} else if (!("${" + ActionFlowInterceptor.PREV_ACTION_PARAM + "}")
.equals(rs.get(Action.SUCCESS).getParams()
.get(ServletActionRedirectResult.DEFAULT_PARAM))) {
throw new ConfigurationException("The '" + prevActionName
+ "' action '" + Action.SUCCESS + "' result '"
+ ServletActionRedirectResult.DEFAULT_PARAM
+ "' parameter must be '${"
+ ActionFlowInterceptor.PREV_ACTION_PARAM
+ "}' in package '" + packageName + "'.",
rs.get(Action.SUCCESS));
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("There is no 'previous' action with name '"
+ prevActionName + "' found in '" + packageName
+ "' package. Creating one.");
}
// add previous action
ResultConfig prevResultConfig = new ResultConfig.Builder(
Action.SUCCESS,
ServletActionRedirectResult.class.getName()).addParam(
ServletActionRedirectResult.DEFAULT_PARAM,
"${" + ActionFlowInterceptor.PREV_ACTION_PARAM + "}")
.build();
// build previous action configuration
ActionConfig prevAct = new ActionConfig.Builder(packageName,
prevActionName, "").addResultConfig(prevResultConfig)
.build();
pcb.addActionConfig(prevAct.getName(), prevAct);
}
// next action
if (actionConfigs.containsKey(nextActionName)) {
if (LOG.isDebugEnabled()) {
LOG.debug("The '" + nextActionName
+ "' action is overridden in '" + packageName
+ "' package.");
}
// next action check
Map<String, ResultConfig> rs = actionConfigs
.get(nextActionName).getResults();
if (rs == null
|| rs.isEmpty()
|| !ActionChainResult.class.getName().equals(
rs.get(Action.SUCCESS).getClassName())) {
throw new ConfigurationException("The '" + nextActionName
+ "' action must define '" + Action.SUCCESS
+ "' result of 'chain' type in package '"
+ packageName + "'.",
actionConfigs.get(nextActionName));
} else if (!("${" + ActionFlowInterceptor.NEXT_ACTION_PARAM + "}")
.equals(rs.get(Action.SUCCESS).getParams()
.get(ActionChainResult.DEFAULT_PARAM))) {
throw new ConfigurationException("The '" + nextActionName
+ "' action '" + Action.SUCCESS + "' result '"
+ ActionChainResult.DEFAULT_PARAM
+ "' parameter must be '${"
+ ActionFlowInterceptor.NEXT_ACTION_PARAM
+ "}' in package '" + packageName + "'.",
rs.get(Action.SUCCESS));
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("There is no 'next' action with name '"
+ nextActionName + "' found in '" + packageName
+ "' package. Creating one.");
}
// add next action
ResultConfig nextResultConfig = new ResultConfig.Builder(
Action.SUCCESS, ActionChainResult.class.getName())
.addParam(
ActionChainResult.DEFAULT_PARAM,
"${" + ActionFlowInterceptor.NEXT_ACTION_PARAM
+ "}").build();