jl165 merging heads
[LibreOffice.git] / qadevOOo / runner / stats / OutProducerFactory.java
blobca569631f409def15151d14f6fa62ba9743c289f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package stats;
29 import share.LogWriter;
30 import java.util.Hashtable;
31 import util.DynamicClassLoader;
33 /**
34 * A factory class for creating out producers.
36 public class OutProducerFactory {
38 /**
39 * Create an out producer. The type that is created depends on the
40 * parameters given. These are:
41 * <ul>
42 * <li>DataBaseOut - If set to true, a database outproducer is created.
43 * <li>OutProducer - The value of this parameter names the class that is created.
44 * </ul>
45 * @param Parameters of the test.
46 * @return The created out producer.
48 public static LogWriter createOutProducer(Hashtable param) {
49 LogWriter dbOut = null;
50 boolean getDatabase = convertToBool(param.get("DataBaseOut"));
51 if (getDatabase) {
52 dbOut = createDataBaseOutProducer(param);
54 if (dbOut == null) {
55 DynamicClassLoader dcl = new DynamicClassLoader();
56 String outProducerName = (String)param.get("OutProducer");
57 if (outProducerName != null) {
58 try {
59 dbOut = (LogWriter)dcl.getInstance(outProducerName);
61 catch(IllegalArgumentException e) {
62 e.printStackTrace();
66 if (dbOut == null) {
67 dbOut = createSimpleOutProducer();
69 return dbOut;
72 /**
73 * Create a databbase out producer.
74 * @param The test parameters
75 * @return The database out producer, or null if it couldn't be created.
77 public static LogWriter createDataBaseOutProducer(Hashtable param) {
78 String dataProducerName = (String)param.get("DataBaseOutProducer");
79 if (dataProducerName == null) {
80 String testBaseName = (String)param.get("TestBase");
81 dataProducerName = testBaseName.substring(testBaseName.indexOf("_")+1);
82 dataProducerName = "stats." + makeFirstCharUpperCase(dataProducerName)
83 + "DataBaseOutProducer";
85 DynamicClassLoader dcl = new DynamicClassLoader();
86 LogWriter dbOut = null;
87 try {
88 dbOut = (LogWriter)dcl.getInstance(dataProducerName,
89 new Class[]{new Hashtable().getClass()}, new Object[]{param});
91 catch(IllegalArgumentException e) {
92 e.printStackTrace();
94 return dbOut;
97 /**
98 * As a fallback, create a simple out producer, if all else failed.
99 * @return A simple out producer, writing to the screen.
101 public static LogWriter createSimpleOutProducer() {
102 return new SimpleOutProducer();
105 private static boolean convertToBool(Object val) {
106 if(val != null) {
107 if ( val instanceof String ) {
108 String sVal = (String)val;
109 if ( sVal.equalsIgnoreCase("true") || sVal.equalsIgnoreCase("yes") ) {
110 return true;
114 else if (val instanceof Boolean) {
115 return ((Boolean)val).booleanValue();
118 return false;
122 * Make the first character to an upper case char.
123 * @param name The String to change
124 * @return The String with an upper case first char.
126 private static String makeFirstCharUpperCase(String name) {
127 return name.substring(0,1).toUpperCase() + name.substring(1);
130 /* public static void main(String[] args) {
131 Hashtable p = new Hashtable();
132 p.put("DataBaseOut", "yes");
133 p.put("TestBase", "java_complex");
134 p.put("Version", "srx645gggg");
135 createDataBaseOutProducer(p);
136 } */