use of org.apache.struts.chain.contexts.ActionContextBase in project sonarqube by SonarSource.
the class CopyFormToContext method findOrCreateForm.
/**
* <p>Actually find or create an instance of ActionForm configured under
* the form-bean-name <code>effectiveFormName</code>, looking in in the
* <code>ActionContext's</code> scope as identified by
* <code>effectiveScope</code>. If a form is created, it will also be
* stored in that scope.</p>
*
* <p><b>NOTE:</b> This specific method depends on the instance of
* <code>ActionContext</code> which is passed being a subclass of
* <code>ActionContextBase</code>, which implements the utility method
* <code>findOrCreateActionForm</code>. </p>
*
* @param ctx The ActionContext we are processing
* @param effectiveFormName the target form name
* @param effectiveScope The target scope
* @return ActionForm instnace, storing in scope if created
* @throws InstantiationException If ActionContext is not subsclass of
* ActionContextBase
* @throws InstantiationException If object cannot be created
* @throws IllegalArgumentException On form not found in/ scope
* @throws IllegalAccessException On failed instantiation
* @throws IllegalStateException If ActionContext is not a subclass of
* ActionBase
*/
protected ActionForm findOrCreateForm(ActionContext ctx, String effectiveFormName, String effectiveScope) throws IllegalAccessException, InstantiationException {
ActionContextBase context;
try {
context = (ActionContextBase) ctx;
} catch (ClassCastException e) {
throw new IllegalStateException("ActionContext [" + ctx + "]" + " must be subclass of ActionContextBase");
}
ActionForm form = context.findOrCreateActionForm(effectiveFormName, effectiveScope);
if (form == null) {
throw new IllegalArgumentException("No form found under scope [" + effectiveScope + "] and formName [" + effectiveFormName + "]");
}
return form;
}
Aggregations