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.util.ObjectUtils;
010import gov.nist.secauto.metaschema.databind.io.BindingException;
011import gov.nist.secauto.metaschema.databind.model.info.IFeatureScalarItemValueHandler;
012import gov.nist.secauto.metaschema.databind.model.info.IItemReadHandler;
013import gov.nist.secauto.metaschema.databind.model.info.IItemWriteHandler;
014
015import java.io.IOException;
016
017import javax.xml.namespace.QName;
018
019import edu.umd.cs.findbugs.annotations.NonNull;
020import edu.umd.cs.findbugs.annotations.Nullable;
021
022public interface IBoundFieldValue extends IFeatureScalarItemValueHandler, IBoundProperty<Object> {
023  @Override
024  @Nullable
025  Object getDefaultValue();
026
027  /**
028   * Get the field definition that contain's the field value.
029   *
030   * @return the parent field definition
031   */
032  @NonNull
033  IBoundDefinitionModelFieldComplex getParentFieldDefinition();
034
035  /**
036   * Get the name of the JSON value key flag.
037   * <p>
038   * Note: if a JSON value key flag is specified, then the JSON value key name is
039   * expected to be ignored.
040   *
041   * @return the flag name or {@code null} if no JSON value key flag is configured
042   * @see #getJsonValueKeyName()
043   */
044  @Nullable
045  String getJsonValueKeyFlagName();
046
047  /**
048   * Get the name of the JSON value key.
049   * <p>
050   * Note: if a JSON value key flag is specified, then this value is expected to
051   * be ignored.
052   *
053   * @return the name
054   * @see #getJsonValueKeyFlagName()
055   */
056  @NonNull
057  String getJsonValueKeyName();
058
059  @Override
060  default Object getEffectiveDefaultValue() {
061    return getDefaultValue();
062  }
063
064  @Override
065  default Object readItem(IBoundObject parent, IItemReadHandler handler) throws IOException {
066    return handler.readItemFieldValue(ObjectUtils.requireNonNull(parent, "parent"), this);
067  }
068
069  @Override
070  default void writeItem(Object item, IItemWriteHandler handler) throws IOException {
071    handler.writeItemFieldValue(item, this);
072  }
073
074  @Override
075  default void deepCopy(@NonNull IBoundObject fromInstance, @NonNull IBoundObject toInstance) throws BindingException {
076    Object value = getValue(fromInstance);
077    setValue(toInstance, value);
078  }
079
080  @Override
081  default boolean canHandleXmlQName(QName qname) {
082    // REFACTOR: Is this correct?
083    return getJavaTypeAdapter().canHandleQName(qname);
084  }
085
086}