1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
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.IContainerFlagSupport;
10  import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
11  import gov.nist.secauto.metaschema.core.util.ObjectUtils;
12  import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler;
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  
18  public interface IBoundInstanceModelFieldScalar
19      extends IBoundInstanceModelField<Object>,
20      IBoundDefinitionModelField<Object>, IFeatureScalarItemValueHandler,
21      IFeatureDefinitionInstanceInlined<IBoundDefinitionModelField<Object>, IBoundInstanceModelFieldScalar> {
22  
23    // integrate above
24    @Override
25    default IBoundDefinitionModelField<Object> getDefinition() {
26      return IFeatureDefinitionInstanceInlined.super.getDefinition();
27    }
28  
29    @Override
30    default boolean isInline() {
31      return IFeatureDefinitionInstanceInlined.super.isInline();
32    }
33  
34    @Override
35    default IBoundInstanceModelFieldScalar getInlineInstance() {
36      return IFeatureDefinitionInstanceInlined.super.getInlineInstance();
37    }
38  
39    @Override
40    IBoundDefinitionModelAssembly getContainingDefinition();
41  
42    @Override
43    default IContainerFlagSupport<IBoundInstanceFlag> getFlagContainer() {
44      return IContainerFlagSupport.empty();
45    }
46  
47    @Override
48    default IBoundInstanceFlag getJsonKey() {
49      // no flags
50      return null;
51    }
52  
53    @Override
54    default IBoundInstanceFlag getItemJsonKey(Object item) {
55      // no flags, no JSON key
56      return null;
57    }
58  
59    @Override
60    default Object getFieldValue(Object item) {
61      // the item is the field value
62      return item;
63    }
64  
65    @Override
66    default String getJsonValueKeyName() {
67      // no bound value, no value key name
68      return null;
69    }
70  
71    @Override
72    default IBoundInstanceFlag getJsonValueKeyFlagInstance() {
73      // no bound value, no value key name
74      return null;
75    }
76  
77    @Override
78    default Object readItem(IBoundObject parent, IItemReadHandler handler) throws IOException {
79      return handler.readItemField(ObjectUtils.requireNonNull(parent, "parent"), this);
80    }
81  
82    @Override
83    default void writeItem(Object item, IItemWriteHandler handler) throws IOException {
84      handler.writeItemField(item, this);
85    }
86  }