1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.config;
17
18 import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
19 import static org.mybatis.generator.internal.util.messages.Messages.getString;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.mybatis.generator.exception.InvalidConfigurationException;
25
26 public class Configuration {
27
28 private final List<Context> contexts;
29
30 private final List<String> classPathEntries;
31
32 public Configuration() {
33 super();
34 contexts = new ArrayList<>();
35 classPathEntries = new ArrayList<>();
36 }
37
38 public void addClasspathEntry(String entry) {
39 classPathEntries.add(entry);
40 }
41
42 public List<String> getClassPathEntries() {
43 return classPathEntries;
44 }
45
46
47
48
49
50
51
52
53
54 public void validate() throws InvalidConfigurationException {
55 List<String> errors = new ArrayList<>();
56
57 for (String classPathEntry : classPathEntries) {
58 if (!stringHasValue(classPathEntry)) {
59 errors.add(getString("ValidationError.19"));
60
61 break;
62 }
63 }
64
65 if (contexts.isEmpty()) {
66 errors.add(getString("ValidationError.11"));
67 } else {
68 for (Context context : contexts) {
69 context.validate(errors);
70 }
71 }
72
73 if (!errors.isEmpty()) {
74 throw new InvalidConfigurationException(errors);
75 }
76 }
77
78 public List<Context> getContexts() {
79 return contexts;
80 }
81
82 public void addContext(Context context) {
83 contexts.add(context);
84 }
85 }