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.jspecify.annotations.Nullable;
25 import org.mybatis.generator.exception.InvalidConfigurationException;
26
27 public class Configuration {
28 private final List<Context> contexts;
29 private final List<String> classPathEntries;
30
31 public Configuration() {
32 contexts = new ArrayList<>();
33 classPathEntries = new ArrayList<>();
34 }
35
36 public void addClasspathEntry(@Nullable String entry) {
37 if (entry != null) {
38 classPathEntries.add(entry);
39 }
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(getString("ValidationError.32"), 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 }