1 28 29 package org.objectweb.util.launcher.option; 30 31 32 import java.util.Vector ; 33 34 import org.objectweb.util.cmdline.api.Iterator; 35 import org.objectweb.util.cmdline.lib.DefaultOptionArgument; 36 37 import org.objectweb.util.launcher.CommandJava; 38 import org.objectweb.util.launcher.CommandFactory; 39 40 import org.objectweb.util.launcher.parser.ContextDescription; 41 import org.objectweb.util.launcher.parser.Repository; 42 43 44 54 public class OptionContext 55 extends DefaultOptionArgument 56 implements OptionLauncher 57 { 58 59 public final static String shortTag = "-ctx" ; 60 61 public final static String longTag = "--context" ; 62 63 64 protected Vector contexts_ ; 65 66 69 public OptionContext(){ 70 super(new String []{shortTag, longTag}, 71 "<ContextID>", 72 "The name of a context", 73 ""); 74 contexts_=new Vector (); 75 } 76 77 78 84 protected class ContextBuilder 85 { 86 87 protected String opt ; 88 89 93 public ContextBuilder(String arg) { 94 this.opt = arg ; 95 } 96 97 103 public void complete(Repository repository) { 104 ContextDescription desc = repository.getDescription(opt); 105 CommandFactory.instance().getDefaultClasspath().addAll(desc.getClasses()); 106 CommandFactory.instance().getDefaultArguments().addAll(desc.getArguments()); 107 CommandFactory.instance().getDefaultProperties().putAll(desc.getProperties()); 108 } 109 } 110 111 117 122 public void consume(Iterator iterator) { 123 setArgument(consumeArgument(iterator)); 124 contexts_.addElement(new ContextBuilder(getArgument())); 125 } 126 127 133 public CommandJava[] complete(Repository repository) { 134 java.util.Iterator contexts = contexts_.iterator(); 135 Vector list = new Vector (); 136 while (contexts.hasNext()) 137 ((ContextBuilder)contexts.next()).complete(repository); 138 return new CommandJava[0]; 139 } 140 141 146 public static String create(String opt) { 147 return shortTag+" "+opt+" " ; 148 } 149 } 150 | Popular Tags |