1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.ant;
22
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Properties;
26 import java.util.Set;
27
28 import org.apache.tools.ant.ProjectComponent;
29 import org.apache.tools.ant.taskdefs.Property;
30 import org.dbunit.DatabaseUnitException;
31 import org.dbunit.database.DatabaseConfig;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36
37
38
39
40
41
42
43 public class DbConfig extends ProjectComponent
44 {
45
46
47
48 private static final Logger logger = LoggerFactory.getLogger(AbstractStep.class);
49
50 private Set properties = new HashSet();
51 private Set features = new HashSet();
52
53 public DbConfig()
54 {
55 }
56
57 public void addProperty(Property property)
58 {
59 logger.trace("addProperty(property={}) - start)", property);
60
61 this.properties.add(property);
62 }
63
64 public void addFeature(Feature feature)
65 {
66 logger.trace("addFeature(feature={}) - start)", feature);
67
68 this.features.add(feature);
69 }
70
71
72
73
74
75
76
77 public void copyTo(DatabaseConfig config) throws DatabaseUnitException
78 {
79 Properties javaProps = new Properties();
80
81 for (Iterator iterator = this.features.iterator(); iterator.hasNext();) {
82 Feature feature = (Feature)iterator.next();
83
84 String propName = feature.getName();
85 String propValue = String.valueOf(feature.isValue());
86
87 logger.debug("Setting property {}", feature);
88 javaProps.setProperty(propName, propValue);
89 }
90
91
92 for (Iterator iterator = this.properties.iterator(); iterator.hasNext();) {
93 Property prop = (Property) iterator.next();
94
95 String propName = prop.getName();
96 String propValue = prop.getValue();
97
98 if(propName==null)
99 throw new NullPointerException("The propName must not be null");
100
101 if(propValue==null)
102 throw new NullPointerException("The propValue must not be null");
103
104 logger.debug("Setting property {}", prop);
105 javaProps.setProperty(propName, propValue);
106 }
107
108 config.setPropertiesByString(javaProps);
109 }
110
111
112
113
114
115
116
117 public static class Feature
118 {
119 private String name;
120 private boolean value;
121
122 public String getName() {
123 return name;
124 }
125 public void setName(String name) {
126 this.name = name;
127 }
128 public boolean isValue() {
129 return value;
130 }
131 public void setValue(boolean value) {
132 this.value = value;
133 }
134 }
135 }