import java.util.Map; import java.util.logging.Logger; import javax.inject.Inject; import oracle.dbtools.plugin.api.cmdline.CommandProvider; import oracle.dbtools.plugin.api.cmdline.annotations.Argument; import oracle.dbtools.plugin.api.cmdline.annotations.Command; import oracle.dbtools.plugin.api.cmdline.annotations.Option; import oracle.dbtools.plugin.api.di.annotations.Provides; import oracle.dbtools.plugin.api.i18n.annotations.TranslatableText; /** * This example plugin demonstrates how to create a command line plugin. * * * *

Testing the command plugin

* * * @author cdivilly * @see EchoMessages */ @Provides @Command(name = "echo", description = @TranslatableText( type = EchoMessages.class, id = EchoMessages.DESCRIPTION), arguments = { @Argument(name = "text", type = String[].class, description = @TranslatableText(type = EchoMessages.class, id = EchoMessages.TEXT)) }, options = @Option(name = "case", description = @TranslatableText(type = EchoMessages.class, id = EchoMessages.CASE))) class EchoCommand implements CommandProvider { @Inject EchoCommand(Logger logger) { this.logger = logger; } @Override public void execute(Map values) throws Exception { /* Get the value of the --case option */ final TextCase textCase = TextCase.parse((String) values.get("case")); /* Get the values of the text argument */ final String[] text = (String[]) values.get("text"); /* Build the message */ StringBuilder msg = new StringBuilder(); for (String segment : text) { msg.append(segment); msg.append(' '); } String fullMsg = msg.toString(); /* Adjust the case of the message */ switch (textCase) { case UPPER: fullMsg = fullMsg.toUpperCase(); break; case LOWER: fullMsg = fullMsg.toLowerCase(); default: } /* Echo the message */ logger.info(fullMsg); } private final Logger logger; /** * Enum representing the legal values of the --case option * * @author cdivilly * */ private enum TextCase { LOWER, PRESERVE, UPPER; static TextCase parse(String value) { TextCase textCase = PRESERVE; if (value != null) { try { textCase = valueOf(value.toUpperCase()); } catch (IllegalArgumentException e) { } } return textCase; } }; }