1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind.model;
7
8 import gov.nist.secauto.metaschema.core.model.IBoundObject;
9 import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
10 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
11 import gov.nist.secauto.metaschema.databind.io.BindingException;
12 import gov.nist.secauto.metaschema.databind.model.impl.InstanceModelChoiceGroup;
13 import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler;
14 import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler;
15
16 import java.io.IOException;
17 import java.lang.reflect.Field;
18
19 import javax.xml.namespace.QName;
20
21 import edu.umd.cs.findbugs.annotations.NonNull;
22 import edu.umd.cs.findbugs.annotations.Nullable;
23
24
25
26
27 public interface IBoundInstanceModelChoiceGroup
28 extends IBoundInstanceModel<IBoundObject>, IBoundContainerModelChoiceGroup, IChoiceGroupInstance {
29
30
31
32
33
34
35
36
37
38
39 @NonNull
40 static IBoundInstanceModelChoiceGroup newInstance(
41 @NonNull Field field,
42 @NonNull IBoundDefinitionModelAssembly containingDefinition) {
43 return InstanceModelChoiceGroup.newInstance(field, containingDefinition);
44 }
45
46 @Override
47 default String getJsonName() {
48
49 return ObjectUtils.requireNonNull(getGroupAsName());
50 }
51
52 @Override
53 @NonNull
54 IBoundDefinitionModelAssembly getOwningDefinition();
55
56 @Override
57 default IBoundDefinitionModelAssembly getContainingDefinition() {
58 return getOwningDefinition();
59 }
60
61
62
63
64
65
66
67
68
69 @Nullable
70 IBoundInstanceModelGroupedNamed getGroupedModelInstance(@NonNull Class<?> clazz);
71
72
73
74
75
76
77
78
79
80
81
82 @Nullable
83 IBoundInstanceModelGroupedNamed getGroupedModelInstance(@NonNull QName name);
84
85
86
87
88
89
90
91
92
93
94
95 @Nullable
96 IBoundInstanceModelGroupedNamed getGroupedModelInstance(@NonNull String discriminator);
97
98
99
100
101
102
103
104
105
106 @Override
107 @NonNull
108 default IBoundInstanceModelGroupedNamed getItemInstance(Object item) {
109 return ObjectUtils.requireNonNull(getGroupedModelInstance(item.getClass()));
110 }
111
112 @Override
113 default IBoundObject readItem(IBoundObject parent, IItemReadHandler handler) throws IOException {
114 return handler.readChoiceGroupItem(ObjectUtils.requireNonNull(parent, "parent"), this);
115 }
116
117 @Override
118 default void writeItem(IBoundObject item, IItemWriteHandler handler) throws IOException {
119 handler.writeChoiceGroupItem(item, this);
120 }
121
122 @Override
123 default IBoundObject deepCopyItem(IBoundObject item, IBoundObject parentInstance) throws BindingException {
124 IBoundInstanceModelGroupedNamed itemInstance = getItemInstance(item);
125 return itemInstance.deepCopyItem(item, parentInstance);
126 }
127
128 @Override
129 default boolean canHandleXmlQName(@NonNull QName qname) {
130 return getGroupedModelInstance(qname) != null;
131 }
132 }