/** * Returns a collection of parameter model for all the parameters supported * by this command. * * @return the command's parameters models. */ public Collection<ParamModel> getParameters() { ArrayList<ParamModel> copy = new ArrayList<ParamModel>(); for (String name : getParametersNames()) { copy.add(getModelFor(name)); } return copy; }
/** * Returns a collection of parameter model for all the parameters supported * by this command. * * @return the command's parameters models. */ public Collection<ParamModel> getParameters() { ArrayList<ParamModel> copy = new ArrayList<ParamModel>(); for (String name : getParametersNames()) { copy.add(getModelFor(name)); } return copy; }
@Override public boolean isOptional(AnnotatedElement element, Param annotation) { String name = CommandModel.getParamName(annotation, element); CommandModel.ParamModel param = model.getModelFor(name); return param.getParam().optional(); }
@Override public boolean isOptional(AnnotatedElement element, Param annotation) { String name = CommandModel.getParamName(annotation, element); CommandModel.ParamModel param = model.getModelFor(name); return param.getParam().optional(); }
@Override public boolean isOptional(AnnotatedElement element, Param annotation) { String name = CommandModel.getParamName(annotation, element); CommandModel.ParamModel param = model.getModelFor(name); return param.getParam().optional(); }
@Override public boolean isOptional(AnnotatedElement element, Param annotation) { String name = CommandModel.getParamName(annotation, element); CommandModel.ParamModel param = model.getModelFor(name); return param.getParam().optional(); }
@Override public boolean isOptional(AnnotatedElement element, Param annotation) { String name = CommandModel.getParamName(annotation, element); CommandModel.ParamModel param = model.getModelFor(name); return param.getParam().optional(); }
/** * Get option values, that might come from the command line * or from the environment. Return the default value for the * option if not otherwise specified. This method works with options * for with multiple() is true. */ protected List<String> getOptions(String name) { List<String> val = options.get(name); if (val.isEmpty()) { String v = env.getStringOption(name); if (v != null) { val.add(v); } } if (val.isEmpty()) { // no value, find the default ParamModel opt = commandModel.getModelFor(name); // if no value was specified and there's a default value, return it if (opt != null) { String def = opt.getParam().defaultValue(); if (ok(def)) { val.add(def); } } } return val; } /**
public void postConstruct() { super.postConstruct(); listing = targetMethod.getAnnotation(Listing.class); resolverType = listing.resolver(); try { // we pass false for "useAnnotations" as the @Param declarations on // the target type are not used for the List method parameters. model = new GenericCommandModel(targetType, false, null, listing.i18n(), new LocalStringManagerImpl(targetType), habitat.getComponent(DomDocument.class), commandName, listing.resolver(), null); if (logger.isLoggable(level)) { for (String paramName : model.getParametersNames()) { CommandModel.ParamModel param = model.getModelFor(paramName); logger.fine("I take " + param.getName() + " parameters"); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); logger.severe(msg); throw new ComponentException(msg, e); } }
/** * Get an option value, that might come from the command line * or from the environment. Return the default value for the * option if not otherwise specified. */ protected String getOption(String name) { String val = options.getOne(name); if (val == null) val = env.getStringOption(name); if (val == null) { // no value, find the default ParamModel opt = commandModel.getModelFor(name); // if no value was specified and there's a default value, return it if (opt != null) { String def = opt.getParam().defaultValue(); if (ok(def)) val = def; } } return val; }
/** * Get an option value, that might come from the command line * or from the environment. Return the default value for the * option if not otherwise specified. */ private String getOption(String name) { String val = options.getOne(name); if (val == null) val = getFromEnvironment(name); if (val == null) { // no value, find the default ParamModel opt = commandModel.getModelFor(name); // if no value was specified and there's a default value, return it if (opt != null) { String def = opt.getParam().defaultValue(); if (ok(def)) val = def; } } return val; }
@Override public void postConstruct() { super.postConstruct(); listing = targetMethod.getAnnotation(Listing.class); resolverType = listing.resolver(); try { // we pass false for "useAnnotations" as the @Param declarations on // the target type are not used for the List method parameters. cmdModel = new GenericCommandModel(targetType, false, null, listing.i18n(), new LocalStringManagerImpl(targetType), habitat.<DomDocument>getService(DomDocument.class), commandName, false, listing.resolver(), GenericListCommand.class); targetModel = habitat.<DomDocument>getService(DomDocument.class).buildModel(targetType); if (logger.isLoggable(level)) { for (String paramName : cmdModel.getParametersNames()) { CommandModel.ParamModel param = cmdModel.getModelFor(paramName); logger.log(Level.FINE, "I take {0} parameters", param.getName()); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); LogHelper.log(logger, Level.SEVERE,ConfigApiLoggerInfo.GENERIC_CREATE_CMD_FAILED, e, commandName); throw new RuntimeException(msg, e); } }
/** * Inject this instance with the final values of all the command * parameters. * * @throws CommandException if execution of the command fails * @throws CommandValidationException if there's something wrong * with the options or arguments */ protected void inject() throws CommandException { // injector expects operands to be in the ParameterMap with the key // "DEFAULT" options.set("DEFAULT", operands); // if command has a "terse" option, set it from ProgramOptions if (commandModel.getModelFor("terse") != null) options.set("terse", Boolean.toString(programOpts.isTerse())); // initialize the injector. InjectionResolver<Param> injector = new MapInjectionResolver(commandModel, options); // inject try { injectionMgr.inject(this, injector); } catch (UnsatisfiedDependencyException e) { throw new CommandValidationException(e.getMessage(), e); } }
/** * Get an option value, that might come from the command line * or from the environment. Return the default value for the * option if not otherwise specified. */ private String getOption(String name) { String val = options.getOne(name); if (val == null) val = getFromEnvironment(name); if (val == null) { // no value, find the default ParamModel opt = commandModel.getModelFor(name); // if no value was specified and there's a default value, return it if (opt != null) { String def = opt.getParam().defaultValue(); if (ok(def)) val = def; } } return val; }
/** * Get an option value, that might come from the command line * or from the environment. Return the default value for the * option if not otherwise specified. */ protected String getOption(String name) { String val = options.getOne(name); if (val == null) { val = env.getStringOption(name); } if (val == null) { // no value, find the default ParamModel opt = commandModel.getModelFor(name); // if no value was specified and there's a default value, return it if (opt != null) { String def = opt.getParam().defaultValue(); if (ok(def)) { val = def; } } } return val; }
@Override public void postConstruct() { super.postConstruct(); delete = targetMethod.getAnnotation(Delete.class); resolverType = delete.resolver(); try { // we pass false for "useAnnotations" as the @Param declarations on // the target type are not used for the Delete method parameters. model = new GenericCommandModel(targetType, false, delete.cluster(), delete.i18n(), new LocalStringManagerImpl(targetType), habitat.getComponent(DomDocument.class), commandName, delete.resolver(), delete.decorator()); if (logger.isLoggable(level)) { for (String paramName : model.getParametersNames()) { CommandModel.ParamModel param = model.getModelFor(paramName); logger.fine("I take " + param.getName() + " parameters"); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); logger.severe(msg); throw new ComponentException(msg, e); } }
/** * Get an option value, that might come from the command line * or from the environment. Return the default value for the * option if not otherwise specified. */ private String getOption(String name) { String val = options.getOne(name); if (val == null) { val = getFromEnvironment(name); } if (val == null) { // no value, find the default ParamModel opt = commandModel.getModelFor(name); // if no value was specified and there's a default value, return it if (opt != null) { String def = opt.getParam().defaultValue(); if (ok(def)) { val = def; } } } return val; }
/** * Inject this instance with the final values of all the command * parameters. * * @throws CommandException if execution of the command fails * @throws CommandValidationException if there's something wrong * with the options or arguments */ protected void inject() throws CommandException { // injector expects operands to be in the ParameterMap with the key // "DEFAULT" options.set("DEFAULT", operands); // if command has a "terse" option, set it from ProgramOptions if (commandModel.getModelFor("terse") != null) options.set("terse", Boolean.toString(programOpts.isTerse())); // initialize the injector. InjectionResolver<Param> injector = new MapInjectionResolver(commandModel, options); // inject try { injectionMgr.inject(this, injector); } catch (UnsatisfiedDependencyException e) { throw new CommandValidationException(e.getMessage(), e); } }
@Override public void postConstruct() { super.postConstruct(); delete = targetMethod.getAnnotation(Delete.class); resolverType = delete.resolver(); try { // we pass false for "useAnnotations" as the @Param declarations on // the target type are not used for the Delete method parameters. model = new GenericCommandModel(targetType, false, delete.cluster(), delete.i18n(), new LocalStringManagerImpl(targetType), habitat.<DomDocument>getService(DomDocument.class), commandName, AnnotationUtil.presentTransitive(ManagedJob.class, delete.decorator()), delete.resolver(), delete.decorator()); if (logger.isLoggable(level)) { for (String paramName : model.getParametersNames()) { CommandModel.ParamModel param = model.getModelFor(paramName); logger.log(Level.FINE, "I take {0} parameters", param.getName()); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); LogHelper.log(logger, Level.SEVERE, ConfigApiLoggerInfo.GENERIC_CREATE_CMD_FAILED, e, new Object[] {commandName}); throw new RuntimeException(msg, e); } }
options.set("DEFAULT", operands); if (commandModel.getModelFor("terse") != null) options.set("terse", Boolean.toString(terse));