1 16 package org.jmanage.cmdui; 17 18 import org.jmanage.cmdui.commands.*; 19 20 import java.util.*; 21 22 27 public class CommandHandlerFactory implements CommandConstants { 28 29 private static Map commandNameToInstanceMap = new HashMap(); 30 private static Set commandNames = new TreeSet(); 31 32 static{ 33 commandNameToInstanceMap.put(APPS, new ListApplicationsHandler()); 34 commandNameToInstanceMap.put(MBEANS, new MBeansHandler()); 35 commandNameToInstanceMap.put(QUERY_MBEANS, new QueryMBeansHandler()); 36 commandNameToInstanceMap.put(INFO, new InfoHandler()); 37 commandNameToInstanceMap.put(GET, new GetHandler()); 38 commandNameToInstanceMap.put(SET, new SetHandler()); 39 commandNameToInstanceMap.put(SET_ATTRS, new SetAttributesHandler()); 40 commandNameToInstanceMap.put(PRINT, new PrintHandler()); 41 commandNameToInstanceMap.put(EXECUTE, new ExecuteHandler()); 42 commandNameToInstanceMap.put(HELP, new HelpHandler()); 43 commandNameToInstanceMap.put(EXIT, new ExitHandler()); 44 45 46 commandNames.addAll(commandNameToInstanceMap.keySet()); 47 } 48 49 public static CommandHandler getHandler(String commandName) 50 throws InvalidCommandException { 51 52 CommandHandler handler = 53 (CommandHandler)commandNameToInstanceMap.get(commandName); 54 if(handler == null){ 55 throw new InvalidCommandException(commandName); 56 } 57 return handler; 58 } 59 60 public static Collection getCommandNames(){ 61 return commandNames; 62 } 63 64 static void validateCommand(String commandName) 65 throws InvalidCommandException { 66 67 if(!commandNameToInstanceMap.containsKey(commandName)){ 68 throw new InvalidCommandException(commandName); 69 } 70 } 71 } 72 | Popular Tags |