1 23 24 package org.objectweb.clif.console.lib; 25 26 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.util.Map ; 30 import java.util.HashMap ; 31 import java.util.Properties ; 32 33 34 38 public class TestPlanReader 39 { 40 static public final String BLADE_PROP = "blade"; 41 static public final String SERVER_PROP = "server"; 42 static public final String INJECTOR_PROP = "injector"; 43 static public final String PROBE_PROP = "probe"; 44 static public final String ARGUMENT_PROP = "argument"; 45 static public final String COMMENT_PROP = "comment"; 46 static public final String ID_PROP = "id"; 47 48 49 static public Map readFromProp(InputStream in) 50 throws IOException 51 { 52 TestPlanReader reader = new TestPlanReader(in); 53 Map testPlan = reader.readFromProp(); 54 reader.close(); 55 return testPlan; 56 } 57 58 59 InputStream in; 60 61 62 public TestPlanReader(InputStream in) 63 { 64 this.in = in; 65 } 66 67 68 public void close() 69 throws IOException 70 { 71 in.close(); 72 } 73 74 75 public Map readFromProp() 76 throws IOException 77 { 78 Map testPlan = new HashMap (); 79 Properties props = new Properties (); 80 props.load(in); 81 int n = 0; 82 String prefix = BLADE_PROP + "." + n + "."; 83 Map context; 84 while (props.getProperty(prefix + ID_PROP) != null) 85 { 86 context = new HashMap (); 87 if (props.containsKey(prefix + INJECTOR_PROP)) 88 { 89 context.put( 90 "insert", 91 props.getProperty(prefix + INJECTOR_PROP)); 92 context.put( 93 "datacollector", 94 "org.objectweb.clif.datacollector.lib.InjectorDataCollector"); 95 } 96 else if (props.containsKey(prefix + PROBE_PROP)) 97 { 98 String probeName = props.getProperty(prefix + PROBE_PROP); 99 context.put("insert", probeName); 100 context.put( 101 "datacollector", 102 probeName.substring(0, probeName.lastIndexOf('.')) + ".DataCollector"); 103 } 104 else 105 { 106 throw new IOException ("Bad test plan file format"); 107 } 108 testPlan.put( 109 props.getProperty(prefix + ID_PROP), 110 new ClifDeployDefinition( 111 props.getProperty(prefix + SERVER_PROP), 112 "org.objectweb.clif.server.lib.Blade", 113 context, 114 props.getProperty(prefix + ARGUMENT_PROP), 115 props.getProperty(prefix + COMMENT_PROP), 116 props.containsKey(prefix + PROBE_PROP))); 117 prefix = BLADE_PROP + "." + ++n + "."; 118 } 119 return testPlan; 120 } 121 } 122 | Popular Tags |