001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package dev.metaschema.core.model;
007
008import java.util.Locale;
009
010import dev.metaschema.core.qname.IEnhancedQName;
011import edu.umd.cs.findbugs.annotations.NonNull;
012
013/**
014 * A marker interface for an {@code any} instance in a Metaschema model.
015 * <p>
016 * An {@code any} instance represents unmodeled content that may appear within
017 * an assembly's model. Unlike other model instances, an {@code any} instance
018 * does not have a definition or name; it acts as a wildcard that captures
019 * content not explicitly declared by the model.
020 * <p>
021 * An {@code any} instance is always optional ({@link #getMinOccurs()} returns
022 * {@code 0}) and unbounded ({@link #getMaxOccurs()} returns {@code -1}).
023 */
024public interface IAnyInstance extends IModelInstanceAbsolute {
025
026  /**
027   * Provides the Metaschema model type of "ANY".
028   *
029   * @return the model type
030   */
031  @Override
032  default ModelType getModelType() {
033    return ModelType.ANY;
034  }
035
036  @Override
037  default IAssemblyDefinition getContainingDefinition() {
038    return getParentContainer().getOwningDefinition();
039  }
040
041  @Override
042  default int getMinOccurs() {
043    return 0;
044  }
045
046  @Override
047  default int getMaxOccurs() {
048    return -1;
049  }
050
051  @Override
052  default IEnhancedQName getEffectiveXmlGroupAsQName() {
053    // never grouped
054    return null;
055  }
056
057  @Override
058  default boolean isEffectiveValueWrappedInXml() {
059    // any content is never wrapped
060    return false;
061  }
062
063  @SuppressWarnings("null")
064  @Override
065  default String toCoordinates() {
066    return String.format("%s-instance:%s:%s@%d",
067        getModelType().toString().toLowerCase(Locale.ROOT),
068        getContainingDefinition().getContainingModule().getShortName(),
069        getContainingDefinition().getName(),
070        hashCode());
071  }
072
073  /**
074   * A visitor callback.
075   *
076   * @param <CONTEXT>
077   *          the type of the context parameter
078   * @param <RESULT>
079   *          the type of the visitor result
080   * @param visitor
081   *          the calling visitor
082   * @param context
083   *          a parameter used to pass contextual information between visitors
084   * @return the visitor result
085   */
086  @Override
087  default <CONTEXT, RESULT> RESULT accept(@NonNull IModelElementVisitor<CONTEXT, RESULT> visitor, CONTEXT context) {
088    return visitor.visitAny(this, context);
089  }
090}