KickJava   Java API By Example, From Geeks To Geeks.

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


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.OutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Properties JavaDoc;
32
33
34 /**
35  *
36  * @author Bruno Dillenseger
37  */

38 public class TestPlanWriter
39 {
40     static public void write2prop(OutputStream JavaDoc out, Map JavaDoc testPlan)
41         throws IOException JavaDoc
42     {
43         TestPlanWriter writer = new TestPlanWriter(out);
44         writer.write2prop(testPlan);
45         writer.close();
46     }
47
48
49     OutputStream JavaDoc out;
50
51
52     public TestPlanWriter(OutputStream JavaDoc out)
53     {
54         this.out = out;
55     }
56
57
58     public void close()
59         throws IOException JavaDoc
60     {
61         out.close();
62     }
63
64
65     public void flush()
66         throws IOException JavaDoc
67     {
68         out.flush();
69     }
70
71
72     public void write2prop(Map JavaDoc testPlan)
73         throws IOException JavaDoc
74     {
75         Iterator JavaDoc entries = testPlan.entrySet().iterator();
76         int n = 0;
77         Properties JavaDoc props = new Properties JavaDoc();
78         while (entries.hasNext())
79         {
80             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)entries.next();
81             String JavaDoc prefix = TestPlanReader.BLADE_PROP + "." + n++ + ".";
82             props.setProperty(prefix + TestPlanReader.ID_PROP, (String JavaDoc)entry.getKey());
83             ClifDeployDefinition def = (ClifDeployDefinition)entry.getValue();
84             if (def.isProbe())
85             {
86                 props.setProperty(
87                     prefix + TestPlanReader.PROBE_PROP,
88                     (String JavaDoc)def.getContext().get("insert"));
89             }
90             else
91             {
92                 props.setProperty(
93                     prefix + TestPlanReader.INJECTOR_PROP,
94                     (String JavaDoc)def.getContext().get("insert"));
95             }
96             props.setProperty(prefix + TestPlanReader.SERVER_PROP, def.getServerName());
97             props.setProperty(prefix + TestPlanReader.ARGUMENT_PROP, def.getArgument());
98             props.setProperty(prefix + TestPlanReader.COMMENT_PROP, def.getComment());
99         }
100         props.store(out, "CLIF test plan");
101     }
102 }
103
Popular Tags