1 28 29 package org.objectweb.ccm.scripts; 30 31 39 40 public abstract class OptionsManager_impl 41 implements OptionsManager 42 { 43 44 50 53 public 54 OptionsManager_impl(String indentation) 55 { 56 indentation_ = indentation; 57 options_ = new java.util.Hashtable (); 58 others_ = new StringBuffer (""); 59 } 60 61 67 protected String indentation_; 68 69 protected StringBuffer others_; 70 71 protected java.util.Hashtable options_; 72 73 79 82 protected void 83 optionsUsage(String prefix) 84 { 85 java.util.Enumeration elements = options_.elements(); 86 Option opt = null; 87 while (elements.hasMoreElements()) 88 { 89 opt = (Option)elements.nextElement(); 90 if (opt.cmd_.startsWith(prefix)) 91 System.err.println(opt.usage_); 92 } 93 } 94 95 99 protected int 100 analyseOptions(String [] commandline,int n) 101 { 102 Option opt = null; 103 for (int i=0;i<commandline.length-n;i++) 104 { 105 if (options_.containsKey(commandline[i])) 106 { 107 try 108 { 109 opt = (Option)options_.get(commandline[i]); 110 for(int j=0;j<opt.paramNumber_;j++) 111 opt.value_.add(commandline[i+j+1]); 112 opt.isSet_ = true; 113 i += opt.paramNumber_; 114 } 115 catch (java.lang.ArrayIndexOutOfBoundsException e) 116 { 117 System.err.println("Missing parameter for option " + opt.cmd_); 118 return -1; 119 } 120 } 121 else 122 { 123 others_.append(" "+commandline[i]+" "); 124 } 125 } 126 return 0; 127 } 128 129 135 138 public void 139 addOption(Option opt) 140 { 141 options_.put(opt.cmd_,opt); 142 } 143 144 147 public boolean 148 isSet(String opt) 149 { 150 if (!options_.containsKey(opt)) 151 return false; 152 return ((Option)options_.get(opt)).isSet_; 153 } 154 155 158 public String [] 159 get(String opt) 160 { 161 if (!options_.containsKey(opt)) 162 return null; 163 return (String [])((Option)options_.get(opt)).value_.toArray(new String [0]); 164 } 165 166 170 public String 171 getOthers() 172 { 173 return others_.toString(); 174 } 175 176 179 public abstract void 180 usage(); 181 182 186 public abstract int 187 analyse(String [] commandline); 188 189 } 190 | Popular Tags |