1
2
3
4
5
6 package dev.metaschema.databind.model;
7
8 import java.io.IOException;
9 import java.util.Map;
10 import java.util.function.Function;
11 import java.util.function.Predicate;
12 import java.util.stream.Collectors;
13 import java.util.stream.Stream;
14
15 import dev.metaschema.core.model.IAssemblyDefinition;
16 import dev.metaschema.core.model.IBoundObject;
17 import dev.metaschema.core.model.IChoiceInstance;
18 import dev.metaschema.core.model.IFeatureContainerModelAssembly;
19 import dev.metaschema.core.qname.IEnhancedQName;
20 import dev.metaschema.core.util.ObjectUtils;
21 import dev.metaschema.databind.model.info.IItemReadHandler;
22 import dev.metaschema.databind.model.info.IItemWriteHandler;
23 import edu.umd.cs.findbugs.annotations.NonNull;
24 import edu.umd.cs.findbugs.annotations.Nullable;
25
26
27
28
29 public interface IBoundDefinitionModelAssembly
30 extends IBoundDefinitionModelComplex, IAssemblyDefinition,
31 IFeatureContainerModelAssembly<
32 IBoundInstanceModel<?>,
33 IBoundInstanceModelNamed<?>,
34 IBoundInstanceModelField<?>,
35 IBoundInstanceModelAssembly,
36 IChoiceInstance,
37 IBoundInstanceModelChoiceGroup> {
38
39
40
41 @Override
42 @NonNull
43 default IBoundDefinitionModelAssembly getOwningDefinition() {
44 return this;
45 }
46
47 @Override
48 @NonNull
49 default IBoundDefinitionModelAssembly getDefinition() {
50 return this;
51 }
52
53 @Override
54 @Nullable
55 default IBoundInstanceModelAssembly getInlineInstance() {
56
57 return null;
58 }
59
60 @Override
61 @NonNull
62 default Map<String, IBoundProperty<?>> getJsonProperties(@Nullable Predicate<IBoundInstanceFlag> flagFilter) {
63 Stream<? extends IBoundInstanceFlag> flagStream = getFlagInstances().stream();
64
65 if (flagFilter != null) {
66 flagStream = flagStream.filter(flagFilter);
67 }
68
69 return ObjectUtils.notNull(Stream.concat(flagStream, getModelInstances().stream())
70 .collect(Collectors.toUnmodifiableMap(IBoundProperty::getJsonName, Function.identity())));
71 }
72
73 @Override
74 @NonNull
75 default IBoundObject readItem(@Nullable IBoundObject parent, @NonNull IItemReadHandler handler) throws IOException {
76 return handler.readItemAssembly(parent, this);
77 }
78
79 @Override
80 default void writeItem(IBoundObject item, IItemWriteHandler handler) throws IOException {
81 handler.writeItemAssembly(item, this);
82 }
83
84 @Override
85 default boolean canHandleXmlQName(@NonNull IEnhancedQName qname) {
86 return qname.equals(getRootQName());
87 }
88 }