update dev300-m58
[ooovba.git] / qadevOOo / runner / stats / OutProducerFactory.java
blob938d491ecf1aedc312ebb9ca5bc26880c9796fb3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OutProducerFactory.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package stats;
32 import share.LogWriter;
33 import java.util.Hashtable;
34 import util.DynamicClassLoader;
36 /**
37 * A factory class for creating out producers.
39 public class OutProducerFactory {
41 /**
42 * Create an out producer. The type that is created depends on the
43 * parameters given. These are:
44 * <ul>
45 * <li>DataBaseOut - If set to true, a database outproducer is created.
46 * <li>OutProducer - The value of this parameter names the class that is created.
47 * </ul>
48 * @param Parameters of the test.
49 * @return The created out producer.
51 public static LogWriter createOutProducer(Hashtable param) {
52 LogWriter dbOut = null;
53 boolean getDatabase = convertToBool(param.get("DataBaseOut"));
54 if (getDatabase) {
55 dbOut = createDataBaseOutProducer(param);
57 if (dbOut == null) {
58 DynamicClassLoader dcl = new DynamicClassLoader();
59 String outProducerName = (String)param.get("OutProducer");
60 if (outProducerName != null) {
61 try {
62 dbOut = (LogWriter)dcl.getInstance(outProducerName);
64 catch(IllegalArgumentException e) {
65 e.printStackTrace();
69 if (dbOut == null) {
70 dbOut = createSimpleOutProducer();
72 return dbOut;
75 /**
76 * Create a databbase out producer.
77 * @param The test parameters
78 * @return The database out producer, or null if it couldn't be created.
80 public static LogWriter createDataBaseOutProducer(Hashtable param) {
81 String dataProducerName = (String)param.get("DataBaseOutProducer");
82 if (dataProducerName == null) {
83 String testBaseName = (String)param.get("TestBase");
84 dataProducerName = testBaseName.substring(testBaseName.indexOf("_")+1);
85 dataProducerName = "stats." + makeFirstCharUpperCase(dataProducerName)
86 + "DataBaseOutProducer";
88 DynamicClassLoader dcl = new DynamicClassLoader();
89 LogWriter dbOut = null;
90 try {
91 dbOut = (LogWriter)dcl.getInstance(dataProducerName,
92 new Class[]{new Hashtable().getClass()}, new Object[]{param});
94 catch(IllegalArgumentException e) {
95 e.printStackTrace();
97 return dbOut;
101 * As a fallback, create a simple out producer, if all else failed.
102 * @return A simple out producer, writing to the screen.
104 public static LogWriter createSimpleOutProducer() {
105 return new SimpleOutProducer();
108 private static boolean convertToBool(Object val) {
109 if(val != null) {
110 if ( val instanceof String ) {
111 String sVal = (String)val;
112 if ( sVal.equalsIgnoreCase("true") || sVal.equalsIgnoreCase("yes") ) {
113 return true;
117 else if (val instanceof Boolean) {
118 return ((Boolean)val).booleanValue();
121 return false;
125 * Make the first character to an upper case char.
126 * @param name The String to change
127 * @return The String with an upper case first char.
129 private static String makeFirstCharUpperCase(String name) {
130 return name.substring(0,1).toUpperCase() + name.substring(1);
133 /* public static void main(String[] args) {
134 Hashtable p = new Hashtable();
135 p.put("DataBaseOut", "yes");
136 p.put("TestBase", "java_complex");
137 p.put("Version", "srx645gggg");
138 createDataBaseOutProducer(p);
139 } */