1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.databind.model.info;
7   
8   import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
9   import gov.nist.secauto.metaschema.core.model.IBoundObject;
10  import gov.nist.secauto.metaschema.databind.io.BindingException;
11  import gov.nist.secauto.metaschema.databind.model.IValuedMutable;
12  
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  public interface IFeatureScalarItemValueHandler
16      extends IItemValueHandler<Object>, IValuedMutable {
17  
18    /**
19     * Apply the string value.
20     * <p>
21     * This first parses the value using the underlying data type implementation and
22     * then applies the parsed value.
23     *
24     * @param parent
25     *          the parent object to apply the value to
26     * @param text
27     *          the value to parse
28     * @throws IllegalArgumentException
29     *           if the text was malformed
30     * @see #getJavaTypeAdapter()
31     */
32    default void setValue(@NonNull Object parent, @NonNull String text) {
33      Object item = getValueFromString(text);
34      setValue(parent, item);
35    }
36  
37    /**
38     * Parse a string value using the underlying data type implementation.
39     *
40     * @param text
41     *          the value to parse
42     * @return the parsed value
43     * @throws IllegalArgumentException
44     *           if the text was malformed
45     * @see #getJavaTypeAdapter()
46     */
47    default Object getValueFromString(@NonNull String text) {
48      return getJavaTypeAdapter().parse(text);
49    }
50  
51    /**
52     * Get the data type adapter supporting the scalar value.
53     *
54     * @return the data type adapter
55     */
56    @NonNull
57    IDataTypeAdapter<?> getJavaTypeAdapter();
58  
59    @Override
60    default Object deepCopyItem(Object source, IBoundObject parentInstance) throws BindingException {
61      return getJavaTypeAdapter().copy(source);
62    }
63  }