1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.xml;
18
19 import static java.util.Objects.isNull;
20
21 import lombok.AccessLevel;
22 import lombok.EqualsAndHashCode;
23 import lombok.Getter;
24 import lombok.RequiredArgsConstructor;
25 import lombok.ToString;
26
27
28
29
30
31
32 public interface JaxbContextMember {
33
34
35
36
37
38
39
40 static ClazzBuilder byClass(Class<?> clazz) {
41 return new ClazzBuilderImpl(clazz);
42 }
43
44
45
46
47
48
49
50 static PakkageBuilder byPackage(Package pakkage) {
51 return new PakkageBuilderImpl(pakkage);
52 }
53
54
55
56
57
58
59 Class<?> getClazz();
60
61
62
63
64
65
66 default String getClazzElementSchemaLocation() {
67 return null;
68 }
69
70
71
72
73
74
75 default String getClazzTypeSchemaLocation() {
76 return null;
77 }
78
79
80
81
82
83
84 default Package getPakkage() {
85 return null;
86 }
87
88
89
90
91
92
93 default String getPakkageSchemaLocation() {
94 return null;
95 }
96
97
98
99
100 interface PakkageBuilder {
101
102
103
104
105
106
107
108 PakkageBuilder schemaLocation(String schemaLocation);
109
110
111
112
113
114
115 JaxbContextMember build();
116 }
117
118
119
120
121 @SuppressWarnings("SameNameButDifferent")
122 @EqualsAndHashCode
123 @ToString
124 @RequiredArgsConstructor(access = AccessLevel.PACKAGE)
125 class PakkageBuilderImpl implements PakkageBuilder {
126
127 private final Package pakkage;
128
129 private String schemaLocation;
130
131 @Override
132 public PakkageBuilder schemaLocation(String schemaLocation) {
133 this.schemaLocation = schemaLocation;
134 return this;
135 }
136
137 @Override
138 public JaxbContextMember build() {
139 if (isNull(this.pakkage)) {
140 throw new IllegalStateException("Package of jaxb context must be present.");
141 }
142 return new JaxbContextMemberImpl(this.pakkage, this.schemaLocation);
143 }
144 }
145
146
147
148
149 interface ClazzBuilder {
150
151
152
153
154
155
156
157 ClazzBuilder clazzElementSchemaLocation(String clazzElementSchemaLocation);
158
159
160
161
162
163
164
165 ClazzBuilder clazzTypeSchemaLocation(String clazzTypeSchemaLocation);
166
167
168
169
170
171
172 JaxbContextMember build();
173 }
174
175
176
177
178 @SuppressWarnings("SameNameButDifferent")
179 @EqualsAndHashCode
180 @ToString
181 @RequiredArgsConstructor(access = AccessLevel.PACKAGE)
182 class ClazzBuilderImpl implements ClazzBuilder {
183
184 private final Class<?> clazz;
185
186 private String clazzElementSchemaLocation;
187
188 private String clazzTypeSchemaLocation;
189
190 @Override
191 public ClazzBuilder clazzElementSchemaLocation(String clazzElementSchemaLocation) {
192 this.clazzElementSchemaLocation = clazzElementSchemaLocation;
193 return this;
194 }
195
196 @Override
197 public ClazzBuilder clazzTypeSchemaLocation(String clazzTypeSchemaLocation) {
198 this.clazzTypeSchemaLocation = clazzTypeSchemaLocation;
199 return this;
200 }
201
202 @Override
203 public JaxbContextMember build() {
204 if (isNull(this.clazz)) {
205 throw new IllegalStateException("Class of jaxb context must be present.");
206 }
207 return new JaxbContextMemberImpl(
208 this.clazz,
209 this.clazzElementSchemaLocation,
210 this.clazzTypeSchemaLocation);
211 }
212 }
213
214
215
216
217 @SuppressWarnings("SameNameButDifferent")
218 @Getter
219 @EqualsAndHashCode
220 @ToString
221 class JaxbContextMemberImpl implements JaxbContextMember {
222
223 private final Class<?> clazz;
224
225 private final String clazzElementSchemaLocation;
226
227 private final String clazzTypeSchemaLocation;
228
229 private final Package pakkage;
230
231 private final String pakkageSchemaLocation;
232
233
234
235
236
237
238
239
240
241
242 JaxbContextMemberImpl(
243 Class<?> clazz,
244 String clazzElementSchemaLocation,
245 String clazzTypeSchemaLocation,
246 Package pakkage,
247 String pakkageSchemaLocation) {
248 this.clazz = clazz;
249 this.clazzElementSchemaLocation = clazzElementSchemaLocation;
250 this.clazzTypeSchemaLocation = clazzTypeSchemaLocation;
251 this.pakkage = pakkage;
252 this.pakkageSchemaLocation = pakkageSchemaLocation;
253 }
254
255
256
257
258
259
260
261
262 JaxbContextMemberImpl(
263 Class<?> clazz,
264 String clazzElementSchemaLocation,
265 String clazzTypeSchemaLocation) {
266 this(clazz, clazzElementSchemaLocation, clazzTypeSchemaLocation, null, null);
267 }
268
269
270
271
272
273
274
275 JaxbContextMemberImpl(Package pakkage, String schemaLocation) {
276 this(null, null, null, pakkage, schemaLocation);
277 }
278 }
279
280 }