001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind.model;
007
008import gov.nist.secauto.metaschema.core.model.IBoundObject;
009import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
010import gov.nist.secauto.metaschema.core.model.IFeatureDefinitionInstanceInlined;
011import gov.nist.secauto.metaschema.core.util.ObjectUtils;
012import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler;
013import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler;
014import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler;
015
016import java.io.IOException;
017
018public interface IBoundInstanceModelFieldScalar
019    extends IBoundInstanceModelField<Object>,
020    IBoundDefinitionModelField<Object>, IFeatureScalarItemValueHandler,
021    IFeatureDefinitionInstanceInlined<IBoundDefinitionModelField<Object>, IBoundInstanceModelFieldScalar> {
022
023  // integrate above
024  @Override
025  default IBoundDefinitionModelField<Object> getDefinition() {
026    return IFeatureDefinitionInstanceInlined.super.getDefinition();
027  }
028
029  @Override
030  default boolean isInline() {
031    return IFeatureDefinitionInstanceInlined.super.isInline();
032  }
033
034  @Override
035  default IBoundInstanceModelFieldScalar getInlineInstance() {
036    return IFeatureDefinitionInstanceInlined.super.getInlineInstance();
037  }
038
039  @Override
040  IBoundDefinitionModelAssembly getContainingDefinition();
041
042  @Override
043  default IContainerFlagSupport<IBoundInstanceFlag> getFlagContainer() {
044    return IContainerFlagSupport.empty();
045  }
046
047  @Override
048  default IBoundInstanceFlag getJsonKey() {
049    // no flags
050    return null;
051  }
052
053  @Override
054  default IBoundInstanceFlag getItemJsonKey(Object item) {
055    // no flags, no JSON key
056    return null;
057  }
058
059  @Override
060  default Object getFieldValue(Object item) {
061    // the item is the field value
062    return item;
063  }
064
065  @Override
066  default String getJsonValueKeyName() {
067    // no bound value, no value key name
068    return null;
069  }
070
071  @Override
072  default IBoundInstanceFlag getJsonValueKeyFlagInstance() {
073    // no bound value, no value key name
074    return null;
075  }
076
077  @Override
078  default Object readItem(IBoundObject parent, IItemReadHandler handler) throws IOException {
079    return handler.readItemField(ObjectUtils.requireNonNull(parent, "parent"), this);
080  }
081
082  @Override
083  default void writeItem(Object item, IItemWriteHandler handler) throws IOException {
084    handler.writeItemField(item, this);
085  }
086}