1
2
3
4
5
6 package dev.metaschema.databind;
7
8 import javax.xml.namespace.QName;
9
10 import dev.metaschema.core.model.IBoundObject;
11 import dev.metaschema.core.util.ObjectUtils;
12 import dev.metaschema.databind.IBindingContext.IBindingMatcher;
13 import dev.metaschema.databind.model.IBoundDefinitionModelAssembly;
14 import edu.umd.cs.findbugs.annotations.NonNull;
15 import nl.talsmasoftware.lazy4j.Lazy;
16
17
18
19
20
21
22
23
24 class RootAssemblyBindingMatcher implements IBindingMatcher {
25 @NonNull
26 private final IBoundDefinitionModelAssembly definition;
27 @NonNull
28 private final Lazy<QName> rootQName = ObjectUtils.notNull(
29 Lazy.of(() -> getDefinition().getRootQName().toQName()));
30
31
32
33
34
35
36
37 public RootAssemblyBindingMatcher(
38 @NonNull IBoundDefinitionModelAssembly definition) {
39 this.definition = definition;
40 }
41
42
43
44
45
46
47 protected IBoundDefinitionModelAssembly getDefinition() {
48 return definition;
49 }
50
51
52
53
54
55
56 protected Class<? extends IBoundObject> getClazz() {
57 return getDefinition().getBoundClass();
58 }
59
60
61
62
63
64
65 @NonNull
66 protected QName getRootQName() {
67 return ObjectUtils.notNull(rootQName.get());
68 }
69
70
71
72
73
74
75 @SuppressWarnings("null")
76 @NonNull
77 protected String getRootJsonName() {
78 return getDefinition().getRootJsonName();
79 }
80
81 @Override
82 public Class<? extends IBoundObject> getBoundClassForXmlQName(QName rootQName) {
83 return getRootQName().equals(rootQName) ? getClazz() : null;
84 }
85
86 @Override
87 public Class<? extends IBoundObject> getBoundClassForJsonName(String rootName) {
88 return getRootJsonName().equals(rootName) ? getClazz() : null;
89 }
90
91 @Override
92 public String toString() {
93 return getDefinition().getRootQName().toString();
94 }
95 }