KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > console > lib > TestPlanReader


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004,2005 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF $Name: $
20 *
21 * Contact: clif@objectweb.org
22 */

23
24 package org.objectweb.clif.console.lib;
25
26
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Properties JavaDoc;
32
33
34 /**
35  *
36  * @author Bruno Dillenseger
37  */

38 public class TestPlanReader
39 {
40     static public final String JavaDoc BLADE_PROP = "blade";
41     static public final String JavaDoc SERVER_PROP = "server";
42     static public final String JavaDoc INJECTOR_PROP = "injector";
43     static public final String JavaDoc PROBE_PROP = "probe";
44     static public final String JavaDoc ARGUMENT_PROP = "argument";
45     static public final String JavaDoc COMMENT_PROP = "comment";
46     static public final String JavaDoc ID_PROP = "id";
47
48
49     static public Map JavaDoc readFromProp(InputStream JavaDoc in)
50         throws IOException JavaDoc
51     {
52         TestPlanReader reader = new TestPlanReader(in);
53         Map JavaDoc testPlan = reader.readFromProp();
54         reader.close();
55         return testPlan;
56     }
57
58
59     InputStream JavaDoc in;
60
61
62     public TestPlanReader(InputStream JavaDoc in)
63     {
64         this.in = in;
65     }
66
67
68     public void close()
69         throws IOException JavaDoc
70     {
71         in.close();
72     }
73
74
75     public Map JavaDoc readFromProp()
76         throws IOException JavaDoc
77     {
78         Map JavaDoc testPlan = new HashMap JavaDoc();
79         Properties JavaDoc props = new Properties JavaDoc();
80         props.load(in);
81         int n = 0;
82         String JavaDoc prefix = BLADE_PROP + "." + n + ".";
83         Map JavaDoc context;
84         while (props.getProperty(prefix + ID_PROP) != null)
85         {
86             context = new HashMap JavaDoc();
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 JavaDoc 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 JavaDoc("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