001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.metaschema.databind.model.info; 007 008import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter; 009import gov.nist.secauto.metaschema.core.model.IBoundObject; 010import gov.nist.secauto.metaschema.databind.io.BindingException; 011import gov.nist.secauto.metaschema.databind.model.IValuedMutable; 012 013import edu.umd.cs.findbugs.annotations.NonNull; 014 015public interface IFeatureScalarItemValueHandler 016 extends IItemValueHandler<Object>, IValuedMutable { 017 018 /** 019 * Apply the string value. 020 * <p> 021 * This first parses the value using the underlying data type implementation and 022 * then applies the parsed value. 023 * 024 * @param parent 025 * the parent object to apply the value to 026 * @param text 027 * the value to parse 028 * @throws IllegalArgumentException 029 * if the text was malformed 030 * @see #getJavaTypeAdapter() 031 */ 032 default void setValue(@NonNull Object parent, @NonNull String text) { 033 Object item = getValueFromString(text); 034 setValue(parent, item); 035 } 036 037 /** 038 * Parse a string value using the underlying data type implementation. 039 * 040 * @param text 041 * the value to parse 042 * @return the parsed value 043 * @throws IllegalArgumentException 044 * if the text was malformed 045 * @see #getJavaTypeAdapter() 046 */ 047 default Object getValueFromString(@NonNull String text) { 048 return getJavaTypeAdapter().parse(text); 049 } 050 051 /** 052 * Get the data type adapter supporting the scalar value. 053 * 054 * @return the data type adapter 055 */ 056 @NonNull 057 IDataTypeAdapter<?> getJavaTypeAdapter(); 058 059 @Override 060 default Object deepCopyItem(Object source, IBoundObject parentInstance) throws BindingException { 061 return getJavaTypeAdapter().copy(source); 062 } 063}