1 /*
2 * SPDX-FileCopyrightText: none
3 * SPDX-License-Identifier: CC0-1.0
4 */
5
6 package dev.metaschema.databind.model;
7
8 import java.lang.reflect.Field;
9
10 import dev.metaschema.core.model.IAnyContent;
11 import dev.metaschema.core.model.IAnyInstance;
12 import dev.metaschema.databind.model.impl.InstanceModelAny;
13 import edu.umd.cs.findbugs.annotations.NonNull;
14 import edu.umd.cs.findbugs.annotations.Nullable;
15
16 /**
17 * Represents an {@code any} instance bound to a Java field annotated with
18 * {@link dev.metaschema.databind.model.annotations.BoundAny @BoundAny}.
19 *
20 * <p>
21 * This interface bridges the core {@link IAnyInstance} with the databind
22 * binding layer, providing reflective access to the {@link IAnyContent} field
23 * on a bound object.
24 */
25 public interface IBoundInstanceModelAny extends IAnyInstance, IFeatureJavaField {
26
27 /**
28 * Create a new bound {@code any} instance.
29 *
30 * @param field
31 * the Java field annotated with {@code @BoundAny}
32 * @param containingDefinition
33 * the assembly definition containing this instance
34 * @return the new bound {@code any} instance
35 */
36 @NonNull
37 static IBoundInstanceModelAny newInstance(
38 @NonNull Field field,
39 @NonNull IBoundDefinitionModelAssembly containingDefinition) {
40 return InstanceModelAny.newInstance(field, containingDefinition);
41 }
42
43 /**
44 * Get the containing assembly definition for this instance.
45 *
46 * @return the containing assembly definition
47 */
48 @Override
49 @NonNull
50 IBoundDefinitionModelAssembly getContainingDefinition();
51
52 /**
53 * Get the {@link IAnyContent} value from the parent bound object.
54 *
55 * @param parent
56 * the parent object containing the bound field
57 * @return the captured unmodeled content, or {@code null} if no content has
58 * been captured
59 */
60 @Nullable
61 default IAnyContent getAnyContent(@NonNull Object parent) {
62 return (IAnyContent) getValue(parent);
63 }
64
65 /**
66 * Set the {@link IAnyContent} value on the parent bound object.
67 *
68 * @param parent
69 * the parent object containing the bound field
70 * @param value
71 * the unmodeled content to set, or {@code null} to clear it
72 */
73 default void setAnyContent(@NonNull Object parent, @Nullable IAnyContent value) {
74 setValue(parent, value);
75 }
76 }