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