2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import share
.LogWriter
;
21 import java
.util
.HashMap
;
22 import util
.DynamicClassLoader
;
25 * A factory class for creating out producers.
27 public class OutProducerFactory
{
30 * Create an out producer. The type that is created depends on the
31 * parameters given. These are:
33 * <li>DataBaseOut - If set to true, a database outproducer is created.
34 * <li>OutProducer - The value of this parameter names the class that is created.
36 * @param param Parameters of the test.
37 * @return The created out producer.
39 public static LogWriter
createOutProducer(HashMap
<String
,Object
> param
) {
40 LogWriter dbOut
= null;
41 boolean getDatabase
= convertToBool(param
.get("DataBaseOut"));
43 dbOut
= createDataBaseOutProducer(param
);
46 DynamicClassLoader dcl
= new DynamicClassLoader();
47 String outProducerName
= (String
)param
.get("OutProducer");
48 if (outProducerName
!= null) {
50 dbOut
= (LogWriter
)dcl
.getInstance(outProducerName
);
52 catch(IllegalArgumentException e
) {
58 dbOut
= createSimpleOutProducer();
64 * Create a database out producer.
65 * @param param The test parameters
66 * @return The database out producer, or null if it couldn't be created.
68 private static LogWriter
createDataBaseOutProducer(HashMap
<String
,Object
> param
) {
69 String dataProducerName
= (String
)param
.get("DataBaseOutProducer");
70 if (dataProducerName
== null) {
71 String testBaseName
= (String
)param
.get("TestBase");
72 dataProducerName
= testBaseName
.substring(testBaseName
.indexOf('_')+1);
73 dataProducerName
= "stats." + makeFirstCharUpperCase(dataProducerName
)
74 + "DataBaseOutProducer";
76 DynamicClassLoader dcl
= new DynamicClassLoader();
77 LogWriter dbOut
= null;
79 dbOut
= (LogWriter
)dcl
.getInstance(dataProducerName
,
80 new Class
[]{HashMap
.class}, new Object
[]{param
});
82 catch(IllegalArgumentException e
) {
89 * As a fallback, create a simple out producer, if all else failed.
90 * @return A simple out producer, writing to the screen.
92 private static LogWriter
createSimpleOutProducer() {
93 return new SimpleOutProducer();
96 private static boolean convertToBool(Object val
) {
98 if ( val
instanceof String
) {
99 String sVal
= (String
)val
;
100 if ( sVal
.equalsIgnoreCase("true") || sVal
.equalsIgnoreCase("yes") ) {
105 else if (val
instanceof Boolean
) {
106 return ((Boolean
)val
).booleanValue();
113 * Make the first character to an upper case char.
114 * @param name The String to change
115 * @return The String with an upper case first char.
117 private static String
makeFirstCharUpperCase(String name
) {
118 return name
.substring(0,1).toUpperCase() + name
.substring(1);