1 16 17 package org.apache.axis2.wsdl.codegen; 18 19 import java.util.*; 20 21 25 public class CommandLineOptionParser implements CommandLineOptionConstants { 26 27 private Map commandLineOptions; 28 29 public CommandLineOptionParser(Map commandLineOptions){ 30 this.commandLineOptions = commandLineOptions; 31 } 32 public CommandLineOptionParser(String [] args) { 33 this.commandLineOptions = this.parse(args); 34 35 } 36 37 43 private Map parse(String [] args){ 44 Map commandLineOptions = new HashMap(); 45 46 if(0 == args.length) 47 return commandLineOptions; 48 49 53 int state = 0; 54 ArrayList optionBundle = null; 55 String optionType = null; 56 CommandLineOption commandLineOption ; 57 58 for(int i=0; i< args.length ; i++){ 59 60 if(args[i].substring(0,1).equals("-")){ 61 if(0 == state){ 62 state = 1; 64 optionType = args[i]; 65 }else if(2 == state || 1 == state){ 66 commandLineOption = new CommandLineOption(optionType, optionBundle); 68 commandLineOptions.put(commandLineOption.getType(), commandLineOption); 69 state = 1; 70 optionType = args[i]; 71 optionBundle = null; 72 73 } 74 }else{ 75 if(0 == state){ 76 commandLineOption = new CommandLineOption(CommandLineOptionConstants.SOLE_INPUT, args); 77 commandLineOptions.put(commandLineOption.getType(), commandLineOption); 78 return commandLineOptions; 79 80 }else if(1 == state){ 81 optionBundle = new ArrayList(); 82 optionBundle.add(args[i]); 83 state =2; 84 85 }else if(2 == state){ 86 optionBundle.add(args[i]); 87 } 88 89 } 90 91 92 } 93 94 commandLineOption = new CommandLineOption(optionType, optionBundle); 95 commandLineOptions.put(commandLineOption.getType(), commandLineOption); 96 return commandLineOptions; 97 98 } 99 public Map getAllOptions() { 100 return this.commandLineOptions; 101 } 102 103 public List getInvalidOptions() { 104 List faultList = new ArrayList(); 105 Iterator iterator = this.commandLineOptions.values().iterator(); 106 while (iterator.hasNext()) { 107 CommandLineOption commandLineOption = ((CommandLineOption) (iterator 108 .next())); 109 if (commandLineOption.isInvalid()) { 110 faultList.add(commandLineOption); 111 } 112 } 113 114 return faultList; 115 } 116 117 118 119 } | Popular Tags |