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