01: package org.ejbca.ui.cli;
02:
03: import java.lang.reflect.Constructor;
04:
05: public class LogAdminCommandFactory {
06:
07: private LogAdminCommandFactory() {
08: }
09:
10: private static final Class[] commandClasses = {
11: LogVerifyProtectedLogCommand.class,
12: LogAcceptProtectedLogCommand.class,
13: LogResetExportProtectedLogCommand.class,
14: LogResetProtectedLogCommand.class };
15:
16: private static final String[] commandNames = {
17: LogVerifyProtectedLogCommand.COMMAND_NAME,
18: LogAcceptProtectedLogCommand.COMMAND_NAME,
19: LogResetExportProtectedLogCommand.COMMAND_NAME,
20: LogResetProtectedLogCommand.COMMAND_NAME };
21:
22: public static IAdminCommand getCommand(String[] args) {
23: if (args.length >= 1) {
24: for (int i = 0; i < commandClasses.length; i++) {
25: if (commandNames[i].equalsIgnoreCase(args[0])) {
26: Class[] paramTypes = new Class[] { String[].class };
27: Constructor constructor;
28: try {
29: constructor = commandClasses[i]
30: .getConstructor(paramTypes);
31: Object[] params = new Object[1];
32: params[0] = args;
33: return (IAdminCommand) constructor
34: .newInstance(params);
35: } catch (Exception e) {
36: throw new RuntimeException(e);
37: }
38: }
39: }
40: }
41: return null;
42: } // getCommand
43:
44: public static String getAvailableCommands() {
45: String availableCommands = "";
46: for (int i = 0; i < commandNames.length; i++) {
47: availableCommands += commandNames[i]
48: + (commandNames.length - 1 != i ? " | " : "");
49: }
50: return availableCommands;
51: }
52: }
|