|
1 |
| -/** |
2 |
| -* OWASP Benchmark Project |
3 |
| -* |
4 |
| -* This file is part of the Open Web Application Security Project (OWASP) |
5 |
| -* Benchmark Project For details, please see |
6 |
| -* <a href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>. |
7 |
| -* |
8 |
| -* The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms |
9 |
| -* of the GNU General Public License as published by the Free Software Foundation, version 2. |
10 |
| -* |
11 |
| -* The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
12 |
| -* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
| -* GNU General Public License for more details |
14 |
| -* |
15 |
| -* @author Nick Sanidas |
16 |
| -* @created 2015 |
17 |
| -*/ |
18 |
| - |
19 |
| -package org.owasp.benchmark.helpers; |
20 |
| - |
21 |
| -import java.io.InputStream; |
22 |
| -import java.lang.reflect.Constructor; |
23 |
| -import java.util.Properties; |
24 |
| - |
25 |
| -public class ThingFactory { |
26 |
| - |
27 |
| - public static ThingInterface createThing() { |
28 |
| - |
29 |
| - Properties props = new Properties(); |
30 |
| - |
31 |
| - // create a thing using reflection |
32 |
| - try (InputStream thingproperties = ThingFactory.class.getClassLoader().getResourceAsStream("thing.properties")) { |
33 |
| - if (thingproperties == null) { |
34 |
| - System.out.println("Can't find thing.properties"); |
35 |
| - return new Thing2(); |
36 |
| - } |
37 |
| - props.load(thingproperties); |
38 |
| - String which = "org.owasp.benchmark.helpers." + props.getProperty("thing"); |
39 |
| - |
40 |
| - Class<?> thing = Class.forName(which); |
41 |
| - Constructor<?> thingConstructor = thing.getConstructor(); |
42 |
| - Object thingInstance = thingConstructor.newInstance(); |
43 |
| - |
44 |
| - return (ThingInterface)thingInstance; |
45 |
| - |
46 |
| - } catch (Exception e) { |
47 |
| - System.out.println("Error constructing Thing."); |
48 |
| - e.printStackTrace(); |
49 |
| - return new Thing1(); |
50 |
| - } |
51 |
| - } |
52 |
| - |
53 |
| -} |
| 1 | +/** |
| 2 | +* OWASP Benchmark Project |
| 3 | +* |
| 4 | +* This file is part of the Open Web Application Security Project (OWASP) |
| 5 | +* Benchmark Project For details, please see |
| 6 | +* <a href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>. |
| 7 | +* |
| 8 | +* The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms |
| 9 | +* of the GNU General Public License as published by the Free Software Foundation, version 2. |
| 10 | +* |
| 11 | +* The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
| 12 | +* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +* GNU General Public License for more details |
| 14 | +* |
| 15 | +* @author Nick Sanidas |
| 16 | +* @created 2015 |
| 17 | +*/ |
| 18 | + |
| 19 | +package org.owasp.benchmark.helpers; |
| 20 | + |
| 21 | +import java.io.InputStream; |
| 22 | +import java.lang.reflect.Constructor; |
| 23 | +import java.util.Properties; |
| 24 | + |
| 25 | +public class ThingFactory { |
| 26 | + |
| 27 | + public static ThingInterface createThing() { |
| 28 | + |
| 29 | + Properties props = new Properties(); |
| 30 | + |
| 31 | + // create a thing using reflection |
| 32 | + try (InputStream thingproperties = ThingFactory.class.getClassLoader().getResourceAsStream("thing.properties")) { |
| 33 | + if (thingproperties == null) { |
| 34 | + System.out.println("Can't find thing.properties"); |
| 35 | + return new Thing2(); |
| 36 | + } |
| 37 | + props.load(thingproperties); |
| 38 | + String which = "org.owasp.benchmark.helpers." + props.getProperty("thing"); |
| 39 | + |
| 40 | + Class<?> thing = Class.forName(which); |
| 41 | + Constructor<?> thingConstructor = thing.getConstructor(); |
| 42 | + Object thingInstance = thingConstructor.newInstance(); |
| 43 | + |
| 44 | + return (ThingInterface)thingInstance; |
| 45 | + |
| 46 | + } catch (Exception e) { |
| 47 | + System.out.println("Error constructing Thing."); |
| 48 | + e.printStackTrace(); |
| 49 | + return new Thing1(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments