1 19 package org.netbeans.api.sendopts; 20 21 import java.util.Collections ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.Set ; 25 import junit.framework.Assert; 26 import org.netbeans.spi.sendopts.OptionGroups; 27 import org.netbeans.spi.sendopts.Env; 28 import org.netbeans.spi.sendopts.Option; 29 import org.netbeans.spi.sendopts.OptionProcessor; 30 import org.openide.util.Lookup; 31 import org.openide.util.lookup.AbstractLookup; 32 import org.openide.util.lookup.InstanceContent; 33 34 public final class Provider extends AbstractLookup { 35 static { 36 System.setProperty("org.openide.util.Lookup", "org.netbeans.api.sendopts.Provider"); 37 } 38 39 final InstanceContent ic; 40 41 public Provider() { 42 this(new InstanceContent()); 43 } 44 45 private Provider(InstanceContent ic) { 46 super(ic); 47 this.ic = ic; 48 } 49 50 51 public static void clearAll() { 52 Lookup l = Lookup.getDefault(); 53 Assert.assertEquals("Our class", org.netbeans.api.sendopts.Provider.class, l.getClass()); 54 55 org.netbeans.api.sendopts.Provider p = (org.netbeans.api.sendopts.Provider)l; 56 p.ic.set(Collections.emptyList(), null); 57 } 58 59 public static void add(Processor proc, Option... options) { 60 Lookup l = Lookup.getDefault(); 61 Assert.assertEquals("Our class", org.netbeans.api.sendopts.Provider.class, l.getClass()); 62 63 org.netbeans.api.sendopts.Provider p = (org.netbeans.api.sendopts.Provider)l; 64 p.ic.add(new DefProvider(options, proc)); 65 } 66 67 public static void assertOptionValues(Map <Option, String []> optionValues) { 68 for (Map.Entry <Option,String []> entry : optionValues.entrySet()) { 69 if (entry.getValue() == null) { 70 Assert.fail("No value for option: " + entry.getKey()); 71 } 72 } 73 } 74 75 private static final class DefProvider extends OptionProcessor { 76 private Processor p; 77 private Option o; 78 79 public DefProvider(Option[] arr, Processor p) { 80 this(OptionGroups.someOf(arr), p); 81 } 82 private DefProvider(Option o, Processor p) { 83 this.p = p; 84 this.o = o; 85 } 86 87 protected Set <Option> getOptions() { 88 return Collections.singleton(o); 89 } 90 91 protected void process(Env env, Map <Option, String []> optionValues) throws CommandException { 92 Map <Option, String []> minus = new HashMap <Option, String []>(optionValues); 93 minus.remove(o); 94 assertOptionValues(optionValues); 95 96 p.process(env, minus); 97 } 98 } 99 } 100 | Popular Tags |