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.qname.IEnhancedQName;
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.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  import edu.umd.cs.findbugs.annotations.NonNull;
19  import edu.umd.cs.findbugs.annotations.Nullable;
20  
21  public interface IBoundFieldValue extends IFeatureScalarItemValueHandler, IBoundProperty<Object> {
22    @Override
23    @Nullable
24    Object getDefaultValue();
25  
26    /**
27     * Get the field definition that contain's the field value.
28     *
29     * @return the parent field definition
30     */
31    @NonNull
32    IBoundDefinitionModelFieldComplex getParentFieldDefinition();
33  
34    /**
35     * Get the name of the JSON value key flag.
36     * <p>
37     * Note: if a JSON value key flag is specified, then the JSON value key name is
38     * expected to be ignored.
39     *
40     * @return the flag name or {@code null} if no JSON value key flag is configured
41     * @see #getJsonValueKeyName()
42     */
43    @Nullable
44    String getJsonValueKeyFlagName();
45  
46    /**
47     * Get the name of the JSON value key.
48     * <p>
49     * Note: if a JSON value key flag is specified, then this value is expected to
50     * be ignored.
51     *
52     * @return the name
53     * @see #getJsonValueKeyFlagName()
54     */
55    @NonNull
56    String getJsonValueKeyName();
57  
58    @Override
59    default Object getEffectiveDefaultValue() {
60      return getDefaultValue();
61    }
62  
63    @Override
64    default Object readItem(IBoundObject parent, IItemReadHandler handler) throws IOException {
65      return handler.readItemFieldValue(ObjectUtils.requireNonNull(parent, "parent"), this);
66    }
67  
68    @Override
69    default void writeItem(Object item, IItemWriteHandler handler) throws IOException {
70      handler.writeItemFieldValue(item, this);
71    }
72  
73    @Override
74    default void deepCopy(@NonNull IBoundObject fromInstance, @NonNull IBoundObject toInstance) throws BindingException {
75      Object value = getValue(fromInstance);
76      if (value != null) {
77        setValue(toInstance, value);
78      }
79    }
80  
81    @Override
82    default boolean canHandleXmlQName(IEnhancedQName qname) {
83      // REFACTOR: Is this correct?
84      return getJavaTypeAdapter().canHandleQName(qname);
85    }
86  
87  }