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 a choice of allowed instances in a Metachema.
015 */
016public interface IChoiceInstance extends IModelInstanceAbsolute, IContainerModelAbsolute {
017
018  /**
019   * Provides the Metaschema model type of "CHOICE".
020   *
021   * @return the model type
022   */
023  @Override
024  default ModelType getModelType() {
025    return ModelType.CHOICE;
026  }
027
028  @Override
029  default IAssemblyDefinition getOwningDefinition() {
030    return getParentContainer().getOwningDefinition();
031  }
032
033  @Override
034  default int getMinOccurs() {
035    return 1;
036  }
037
038  @Override
039  default int getMaxOccurs() {
040    return 1;
041  }
042
043  @Override
044  default IEnhancedQName getEffectiveXmlGroupAsQName() {
045    // never grouped
046    return null;
047  }
048
049  @Override
050  default boolean isEffectiveValueWrappedInXml() {
051    throw new UnsupportedOperationException("not applicable");
052  }
053
054  @SuppressWarnings("null")
055  @Override
056  default String toCoordinates() {
057    return String.format("%s-instance:%s:%s@%d",
058        getModelType().toString().toLowerCase(Locale.ROOT),
059        getContainingDefinition().getContainingModule().getShortName(),
060        getContainingDefinition().getName(),
061        hashCode());
062  }
063
064  /**
065   * A visitor callback.
066   *
067   * @param <CONTEXT>
068   *          the type of the context parameter
069   * @param <RESULT>
070   *          the type of the visitor result
071   * @param visitor
072   *          the calling visitor
073   * @param context
074   *          a parameter used to pass contextual information between visitors
075   * @return the visitor result
076   */
077  @Override
078  default <CONTEXT, RESULT> RESULT accept(@NonNull IModelElementVisitor<CONTEXT, RESULT> visitor, CONTEXT context) {
079    return visitor.visitChoiceInstance(this, context);
080  }
081}