| 1 | |
package org.webslinger.util; |
| 2 | |
|
| 3 | |
public abstract class BaseMain { |
| 4 | |
protected String[] args; |
| 5 | |
protected int i; |
| 6 | |
|
| 7 | 0 | public BaseMain(String[] args) { |
| 8 | 0 | this.args = args; |
| 9 | 0 | i = 0; |
| 10 | 0 | } |
| 11 | |
|
| 12 | |
protected String getValue(String optName, String arg) { |
| 13 | 0 | if (arg.substring(optName.length()).startsWith("=")) return arg.substring(optName.length() + 1); |
| 14 | 0 | if (i + 1 == args.length) throw new IllegalArgumentException("no value"); |
| 15 | 0 | i++; |
| 16 | 0 | return args[i]; |
| 17 | |
} |
| 18 | |
|
| 19 | |
public void run() throws Exception { |
| 20 | 0 | for (i = 0; i < args.length; i++) { |
| 21 | 0 | String arg = args[i]; |
| 22 | 0 | if (processArg(arg)) break; |
| 23 | |
} |
| 24 | 0 | } |
| 25 | |
|
| 26 | |
protected abstract boolean processArg(String arg) throws Exception; |
| 27 | |
} |
| 28 | |
|