ArgsParserpublic class ArgsParser extends Object Parse the arguments for the upgrade tool
and invoke the appropriate handler |
Fields Summary |
---|
public static final String | SOURCE | public static final String | SOURCE_SHORT | public static final String | TARGET | public static final String | TARGET_SHORT | public static final String | DOMAIN | public static final String | DOMAIN_SHORT | public static final String | NSSPWD | public static final String | NSSPWDFILE | public static final String | NSSPWDFILE_SHORT | public static final String | TARGETNSSPWD | public static final String | TARGETNSSPWDFILE | public static final String | TARGETNSSPWDFILE_SHORT | public static final String | JKSPWD | public static final String | JKSPWDFILE | public static final String | JKSPWDFILE_SHORT | public static final String | CAPWD | public static final String | CAPWDFILE | public static final String | CAPWDFILE_SHORT | public static final String | ADMINUSER | public static final String | ADMINUSER_SHORT | public static final String | ADMINPASSWORD | public static final String | ADMINPASSWORD_SHORT | public static final String | MASTERPASSWORD | public static final String | MASTERPASSWORD_SHORT | public static final String | CLINSTANCEINFO | public static final String | CLINSTANCEINFO_SHORT | private static Logger | _logger | private String[] | arguments | private CommonInfoModel | commonInfo | private HashMap | interactiveMap | private com.sun.enterprise.util.i18n.StringManager | sm |
Constructors Summary |
---|
public ArgsParser(String[] args, CommonInfoModel infoModel, HashMap hMap)Creates a new instance of ArgsParser
sm = StringManager.getManager(LogService.UPGRADE_CLI_LOGGER);
commonInfo = infoModel;
interactiveMap = hMap;
arguments = args;
| public ArgsParser(String[] args, CommonInfoModel infoModel)
this(args, infoModel, new HashMap());
|
Methods Summary |
---|
private java.lang.Class | getHandler(java.lang.String cmd)
Class instructionHandler = null;
try {
//start CR 6396918
if(cmd.equals(ADMINPASSWORD_SHORT) || cmd.equals(ADMINPASSWORD)
|| cmd.equals(MASTERPASSWORD_SHORT) || cmd.equals(MASTERPASSWORD))
instructionHandler = null;
else if (cmd.equals("v")) {
// CR 6568819 - adds support for -v option. For -v option use
// the class ARG_V.java (same as for -V option).
instructionHandler =
Class.forName("com.sun.enterprise.tools.upgrade.common.arguments.ARG_" + "V");
} else {
//end CR 6396918
instructionHandler =
Class.forName("com.sun.enterprise.tools.upgrade.common.arguments.ARG_" + cmd);
}
return instructionHandler;
} catch (ClassNotFoundException cnf) {
} catch (Exception e1) {
_logger.log(Level.INFO, sm.getString("enterprise.tools.upgrade.cli.invalid_option",e1), e1);
}
return null;
| public void | helpUsage(java.lang.String str)
System.out.println("\n" + str + "\n");
helpUsage();
| public void | helpUsage()
helpUsage(0);
| public void | helpUsage(int exitCode)
new ARG_help(new ParsedArgument(null, null, null, commonInfo, null), exitCode);
| public java.util.HashMap | parse()
return parse(null);
| public java.util.HashMap | parse(InteractiveInput interactiveParser)Method to parse and process the arguments passed through CLI.
Method to collect the missing arguments from the user.
String cmd = null;
Vector parameters = new Vector();
Vector instructions = new Vector();
Class instructionHandler = null;
//Iterate through arguments and Parse the instructions
for(int i=0;i<arguments.length;i++) {
if(arguments[i].startsWith(UpgradeConstants.CLI_OPTION_HYPHEN)){
String rawArg = arguments[i];
//Strip - or --
String argument = rawArg.substring(
rawArg.lastIndexOf(UpgradeConstants.CLI_OPTION_HYPHEN) + 1,
rawArg.length());
String delimeters = "=";
StringTokenizer st = new StringTokenizer(argument, delimeters,
false);
if ( st.hasMoreTokens() ) {
cmd = st.nextToken();
instructionHandler = getHandler(cmd);
parameters = new Vector();
}
if (st.hasMoreTokens()) { //there was an equal sign
parameters.add(st.nextToken());
}
while(i + 1 < arguments.length &&
!arguments[i + 1].startsWith(
UpgradeConstants.CLI_OPTION_HYPHEN)) {
i++;
parameters.add(arguments[i]);
}
if ( instructionHandler != null ) {
interactiveMap.put(cmd, parameters);
instructions.addElement(new ParsedArgument(instructionHandler,
cmd, parameters, commonInfo, interactiveMap));
} else {
String msg = sm.getString("enterprise.tools.upgrade.cli.invalid_option",
rawArg);
if (cmd.equals(ADMINPASSWORD_SHORT) || cmd.equals(ADMINPASSWORD)) {
msg = msg + "\n" +
sm.getString("enterprise.tools.upgrade.cli.deprecated_option",rawArg) +
" " +
sm.getString("enterprise.tools.upgrade.cli.deprecated_option.adminpassword");
} else if (cmd.equals(MASTERPASSWORD_SHORT) || cmd.equals(MASTERPASSWORD)) {
msg = msg + "\n" +
sm.getString("enterprise.tools.upgrade.cli.deprecated_option",rawArg) +
" " +
sm.getString("enterprise.tools.upgrade.cli.deprecated_option.masterpassword");
}
helpUsage(msg);
commonInfo.recover();
System.exit(1);
}
}
}
//Process the parsed instructions for all arguments passed.
Enumeration e = instructions.elements();
while ( e.hasMoreElements() ) {
ParsedArgument pi = (ParsedArgument )e.nextElement();
instructionHandler = pi.getHandler();
try {
Class [] parameterTypes = new Class [] {pi.getClass()};
Constructor constructor =
instructionHandler.getConstructor(parameterTypes);
constructor.newInstance(new Object [] { pi });
} catch (Exception ex) {
_logger.log(Level.INFO,
sm.getString("enterprise.tools.upgrade.cli.invalid_option",
pi.getMneumonic()), ex);
commonInfo.recover();
System.exit(1);
}
}
//Collect missing arguments that were not passed.
if(interactiveParser != null) {
interactiveParser.collectMissingArguments(interactiveMap);
}
return interactiveMap;
|
|