use of org.glassfish.config.support.GenericCrudCommand in project Payara by payara.
the class CommandRunnerImpl method injectParameters.
public static boolean injectParameters(final CommandModel model, final Object injectionTarget, final InjectionResolver<Param> injector, final ActionReport report) {
if (injectionTarget instanceof GenericCrudCommand) {
GenericCrudCommand c = GenericCrudCommand.class.cast(injectionTarget);
c.setInjectionResolver(injector);
}
// inject
try {
injectionMgr.inject(injectionTarget, injector);
} catch (UnsatisfiedDependencyException e) {
Param param = e.getAnnotation(Param.class);
CommandModel.ParamModel paramModel = null;
for (CommandModel.ParamModel pModel : model.getParameters()) {
if (pModel.getParam().equals(param)) {
paramModel = pModel;
break;
}
}
String errorMsg;
final String usage = getUsageText(model);
if (paramModel != null) {
String paramName = paramModel.getName();
String paramDesc = paramModel.getLocalizedDescription();
if (param.primary()) {
errorMsg = adminStrings.getLocalString("commandrunner.operand.required", "Operand required.");
} else if (param.password()) {
errorMsg = adminStrings.getLocalString("adapter.param.missing.passwordfile", "{0} command requires the passwordfile " + "parameter containing {1} entry.", model.getCommandName(), paramName);
} else if (paramDesc != null) {
errorMsg = adminStrings.getLocalString("admin.param.missing", "{0} command requires the {1} parameter ({2})", model.getCommandName(), paramName, paramDesc);
} else {
errorMsg = adminStrings.getLocalString("admin.param.missing.nodesc", "{0} command requires the {1} parameter", model.getCommandName(), paramName);
}
} else {
errorMsg = adminStrings.getLocalString("admin.param.missing.nofound", "Cannot find {1} in {0} command model, file a bug", model.getCommandName(), e.getUnsatisfiedName());
}
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(errorMsg);
report.setFailureCause(e);
ActionReport.MessagePart childPart = report.getTopMessagePart().addChild();
childPart.setMessage(usage);
return false;
} catch (MultiException e) {
// If the cause is UnacceptableValueException -- we want the message
// from it. It is wrapped with a less useful Exception.
Exception exception = null;
for (Throwable th : e.getErrors()) {
Throwable cause = th;
while (cause != null) {
if ((cause instanceof UnacceptableValueException) || (cause instanceof IllegalArgumentException)) {
exception = (Exception) th;
break;
}
cause = cause.getCause();
}
}
if (exception == null) {
// Not an UnacceptableValueException or IllegalArgumentException
exception = e;
}
logger.log(Level.SEVERE, KernelLoggerInfo.invocationException, exception);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(exception.getMessage());
report.setFailureCause(exception);
ActionReport.MessagePart childPart = report.getTopMessagePart().addChild();
childPart.setMessage(getUsageText(model));
return false;
}
checkAgainstBeanConstraints(injectionTarget, model.getCommandName());
return true;
}
Aggregations