1 26 27 package org.objectweb.util.cmdline.lib; 28 29 import org.objectweb.util.cmdline.api.Iterator; 30 import org.objectweb.util.cmdline.api.Option; 31 32 42 43 public abstract class DefaultOptionBase 44 extends DefaultUsage 45 implements Option 46 { 47 53 54 protected boolean mandatory_; 55 56 57 protected boolean set_; 58 59 65 71 public 72 DefaultOptionBase() 73 { 74 this("", new String [0], null, false); 75 } 76 77 86 public 87 DefaultOptionBase(String label, 88 String argument, 89 String [] description) 90 { 91 this(label, new String [] { argument }, description, false); 92 } 93 94 103 public 104 DefaultOptionBase(String label, 105 String [] arguments, 106 String [] description) 107 { 108 this(label, arguments, description, false); 109 } 110 111 120 public 121 DefaultOptionBase(String [] labels, 122 String argument, 123 String [] description) 124 { 125 this(labels, new String [] { argument }, description, false); 126 } 127 128 137 public 138 DefaultOptionBase(String [] labels, 139 String [] arguments, 140 String [] description) 141 { 142 this(labels, arguments, description, false); 143 } 144 145 154 public 155 DefaultOptionBase(String [] labels, 156 String argument, 157 String description) 158 { 159 this(labels, new String [] { argument }, 160 new String [] { description }, false); 161 } 162 163 172 public 173 DefaultOptionBase(String [] labels, 174 String [] arguments, 175 String description) 176 { 177 this(labels, arguments, new String [] { description }, false); 178 } 179 180 189 public 190 DefaultOptionBase(String label, 191 String argument, 192 String [] description, 193 boolean mandatory) 194 { 195 this(new String [] { label }, new String [] { argument }, 196 description, mandatory); 197 } 198 199 208 public 209 DefaultOptionBase(String label, 210 String [] arguments, 211 String [] description, 212 boolean mandatory) 213 { 214 this(new String [] { label }, arguments, description, mandatory); 215 } 216 217 226 public 227 DefaultOptionBase(String [] labels, 228 String argument, 229 String [] description, 230 boolean mandatory) 231 { 232 this(labels, new String [] { argument }, description, mandatory); 233 } 234 235 244 public 245 DefaultOptionBase(String [] labels, 246 String [] arguments, 247 String [] description, 248 boolean mandatory) 249 { 250 super(labels, arguments, description); 251 setMandatory(mandatory); 252 set_ = false; 253 } 254 255 261 268 protected String 269 consumeArgument(Iterator iterator) 270 { 271 try { 272 String argument = iterator.next(); 273 iterator.remove(); 274 return argument; 275 } catch(java.util.NoSuchElementException exc) { 276 throw new Error ("Missed argument"); 277 } 278 } 279 280 285 protected void 286 checkAlreadySet(org.objectweb.util.cmdline.api.Iterator iterator) 287 { 288 if(set_) 289 throw new Error ("Twice uses"); 290 set_ = true; 291 } 292 293 299 304 public boolean 305 isMandatory() 306 { 307 return mandatory_; 308 } 309 310 315 public void 316 setMandatory(boolean mandatory) 317 { 318 mandatory_ = mandatory; 319 } 320 321 327 public boolean 328 isSet() 329 { 330 return set_; 331 } 332 333 340 public boolean 341 check(String current) 342 { 343 String [] labels = getLabels(); 344 for(int i=0; i<labels.length; i++) 345 { 346 if(current.equals(labels[i])) 347 return true; 348 } 349 350 return false; 351 } 352 353 360 abstract public void 361 consume(org.objectweb.util.cmdline.api.Iterator iterator); 362 363 } 369 | Popular Tags |