1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind.model.info;
7
8 import gov.nist.secauto.metaschema.core.model.IBoundObject;
9 import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
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.IBoundDefinitionModelComplex;
13 import gov.nist.secauto.metaschema.databind.model.IBoundProperty;
14
15 import java.lang.reflect.Constructor;
16 import java.lang.reflect.InvocationTargetException;
17 import java.util.Map;
18 import java.util.function.Supplier;
19
20 import edu.umd.cs.findbugs.annotations.NonNull;
21 import edu.umd.cs.findbugs.annotations.Nullable;
22
23 public interface IFeatureComplexItemValueHandler extends IItemValueHandler<IBoundObject> {
24
25
26
27
28
29 @NonNull
30 IBoundDefinitionModelComplex getDefinition();
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 @NonNull
48 Map<String, IBoundProperty<?>> getJsonProperties();
49
50
51 @Override
52 @NonNull
53 IBoundObject deepCopyItem(
54 @NonNull IBoundObject item,
55 @Nullable IBoundObject parentInstance) throws BindingException;
56
57
58
59
60
61
62 @NonNull
63 Class<? extends IBoundObject> getBoundClass();
64
65
66
67
68
69
70
71
72
73
74
75
76
77 @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
78 @NonNull
79 default <CLASS extends IBoundObject> CLASS newInstance(@Nullable Supplier<IMetaschemaData> supplier) {
80 Class<?> clazz = getBoundClass();
81 try {
82 CLASS retval;
83 if (supplier != null) {
84 @SuppressWarnings("unchecked")
85 Constructor<CLASS> constructor
86 = (Constructor<CLASS>) clazz.getDeclaredConstructor(IMetaschemaData.class);
87 retval = constructor.newInstance(supplier.get());
88 } else {
89 @SuppressWarnings("unchecked")
90 Constructor<CLASS> constructor
91 = (Constructor<CLASS>) clazz.getDeclaredConstructor();
92 retval = constructor.newInstance();
93 }
94 return ObjectUtils.notNull(retval);
95 } catch (NoSuchMethodException ex) {
96 String msg = String.format("Class '%s' does not have a required no-arg constructor.", clazz.getName());
97 throw new RuntimeException(msg, ex);
98 } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
99 throw new RuntimeException(ex);
100 }
101 }
102
103 void callBeforeDeserialize(
104 @NonNull IBoundObject targetObject,
105 @Nullable IBoundObject parentObject) throws BindingException;
106
107 void callAfterDeserialize(
108 @NonNull IBoundObject targetObject,
109 @Nullable IBoundObject parentObject) throws BindingException;
110 }