1 16 package org.jmanage.cmdui; 17 18 import org.jmanage.core.services.ServiceFactory; 19 import org.jmanage.core.util.JManageProperties; 20 import org.jmanage.core.util.Loggers; 21 22 import java.util.logging.Logger ; 23 import java.util.logging.LogManager ; 24 import java.util.logging.ConsoleHandler ; 25 26 52 public class Main { 53 54 private static final Logger logger = Loggers.getLogger(Main.class); 55 56 static{ 57 58 if(JManageProperties.getJManageURL() == null){ 59 60 ServiceFactory.init(ServiceFactory.MODE_LOCAL); 61 }else{ 62 ServiceFactory.init(ServiceFactory.MODE_REMOTE); 63 } 64 } 65 66 public static void main(String [] args) 67 throws Exception { 68 69 Command command = Command.get(args); 70 71 72 setLogging(command); 73 74 75 if(command.isAuthRequired()){ 76 if(!command.authenticate()){ 77 System.out.println("Authentication failed."); 78 return; 79 } 80 } 81 82 if(command.getName() == null){ 83 84 PromptMode promptMode = new PromptMode(command); 85 promptMode.start(); 86 }else{ 87 88 command.execute(); 89 } 90 } 91 92 private static void setLogging(Command command){ 93 LogManager logManager = LogManager.getLogManager(); 94 logManager.reset(); 95 96 Logger rootLogger = Logger.getLogger(""); 97 rootLogger.setLevel(command.getLogLevel()); 98 ConsoleHandler consoleHandler = new ConsoleHandler (); 99 consoleHandler.setLevel(command.getLogLevel()); 100 rootLogger.addHandler(consoleHandler); 101 102 logger.fine("Log level=" + command.getLogLevel()); 103 } 104 } 105 | Popular Tags |