001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package dev.metaschema.databind.model;
007
008import java.lang.reflect.Field;
009
010import dev.metaschema.core.model.IAnyContent;
011import dev.metaschema.core.model.IAnyInstance;
012import dev.metaschema.databind.model.impl.InstanceModelAny;
013import edu.umd.cs.findbugs.annotations.NonNull;
014import edu.umd.cs.findbugs.annotations.Nullable;
015
016/**
017 * Represents an {@code any} instance bound to a Java field annotated with
018 * {@link dev.metaschema.databind.model.annotations.BoundAny @BoundAny}.
019 *
020 * <p>
021 * This interface bridges the core {@link IAnyInstance} with the databind
022 * binding layer, providing reflective access to the {@link IAnyContent} field
023 * on a bound object.
024 */
025public interface IBoundInstanceModelAny extends IAnyInstance, IFeatureJavaField {
026
027  /**
028   * Create a new bound {@code any} instance.
029   *
030   * @param field
031   *          the Java field annotated with {@code @BoundAny}
032   * @param containingDefinition
033   *          the assembly definition containing this instance
034   * @return the new bound {@code any} instance
035   */
036  @NonNull
037  static IBoundInstanceModelAny newInstance(
038      @NonNull Field field,
039      @NonNull IBoundDefinitionModelAssembly containingDefinition) {
040    return InstanceModelAny.newInstance(field, containingDefinition);
041  }
042
043  /**
044   * Get the containing assembly definition for this instance.
045   *
046   * @return the containing assembly definition
047   */
048  @Override
049  @NonNull
050  IBoundDefinitionModelAssembly getContainingDefinition();
051
052  /**
053   * Get the {@link IAnyContent} value from the parent bound object.
054   *
055   * @param parent
056   *          the parent object containing the bound field
057   * @return the captured unmodeled content, or {@code null} if no content has
058   *         been captured
059   */
060  @Nullable
061  default IAnyContent getAnyContent(@NonNull Object parent) {
062    return (IAnyContent) getValue(parent);
063  }
064
065  /**
066   * Set the {@link IAnyContent} value on the parent bound object.
067   *
068   * @param parent
069   *          the parent object containing the bound field
070   * @param value
071   *          the unmodeled content to set, or {@code null} to clear it
072   */
073  default void setAnyContent(@NonNull Object parent, @Nullable IAnyContent value) {
074    setValue(parent, value);
075  }
076}