home *** CD-ROM | disk | FTP | other *** search
- package com.commerceone.util.cmdline;
-
- import java.util.Hashtable;
- import java.util.Vector;
-
- public final class CmdLineApp$ArgumentParser extends Hashtable {
- private Vector vectRegisteredValues;
- String[] remainingArgs;
- // $FF: synthetic field
- final CmdLineApp this$0;
-
- protected void registerOption(String opt, String succinctExplain, String verboseExplain, boolean isBoolean) {
- if (!this.isRegistered(opt)) {
- this.vectRegisteredValues.addElement(new CmdLineApp.RegisteredOption(this.this$0, opt, succinctExplain, verboseExplain, isBoolean, true));
- }
-
- }
-
- protected void registerOption(String opt, String succinctExplain, String verboseExplain, boolean isBoolean, boolean shouldDisplay) {
- if (!this.isRegistered(opt)) {
- this.vectRegisteredValues.addElement(new CmdLineApp.RegisteredOption(this.this$0, opt, succinctExplain, verboseExplain, isBoolean, shouldDisplay));
- }
-
- }
-
- public CmdLineApp$ArgumentParser(CmdLineApp this$0) {
- (this.this$0 = this$0).getClass();
- this.vectRegisteredValues = new Vector();
- }
-
- public boolean isRegistered(String option) {
- for(int i = 0; i < this.vectRegisteredValues.size(); ++i) {
- Object object = this.vectRegisteredValues.elementAt(i);
- if (object instanceof CmdLineApp.RegisteredOption) {
- CmdLineApp.RegisteredOption foundOption = (CmdLineApp.RegisteredOption)object;
- if (foundOption != null && foundOption.getOption().equals(option)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- private int handleArg(String flag, String[] args, int currArgNum) {
- StringBuffer val = new StringBuffer();
- if (currArgNum >= args.length) {
- ((Hashtable)this).put(flag, val.toString());
- return currArgNum;
- } else if (args[currArgNum].startsWith("-")) {
- ((Hashtable)this).put(flag, val.toString());
- return currArgNum;
- } else if (this.isBoolean(flag)) {
- ((Hashtable)this).put(flag, val.toString());
- return currArgNum;
- } else {
- val.append(args[currArgNum]);
- ++currArgNum;
- ((Hashtable)this).put(flag, val.toString());
- return currArgNum;
- }
- }
-
- public Vector getRegisteredValues() {
- return this.vectRegisteredValues;
- }
-
- public void init(String[] args) {
- if (args != null) {
- int tokenNum = 0;
-
- while(tokenNum < args.length) {
- if (args[tokenNum].startsWith("-")) {
- tokenNum = this.handleArg(args[tokenNum].substring(1), args, tokenNum + 1);
- } else {
- this.remainingArgs = new String[args.length - tokenNum];
- System.arraycopy(args, tokenNum, this.remainingArgs, 0, args.length - tokenNum);
- tokenNum = args.length;
- }
- }
- }
-
- }
-
- public boolean isBoolean(String option) {
- for(int i = 0; i < this.vectRegisteredValues.size(); ++i) {
- Object object = this.vectRegisteredValues.elementAt(i);
- if (object instanceof CmdLineApp.RegisteredOption) {
- CmdLineApp.RegisteredOption foundOption = (CmdLineApp.RegisteredOption)object;
- if (foundOption != null && foundOption.getOption().equals(option)) {
- return foundOption.getIsBoolean();
- }
- }
- }
-
- return false;
- }
-
- public String[] getRemainingArgs() {
- return this.remainingArgs;
- }
- }
-