InstanceModelGroupedFieldReference.java
/*
* SPDX-FileCopyrightText: none
* SPDX-License-Identifier: CC0-1.0
*/
package gov.nist.secauto.metaschema.databind.model.metaschema.impl;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem;
import gov.nist.secauto.metaschema.core.model.AbstractFieldInstance;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
import gov.nist.secauto.metaschema.core.model.IFieldDefinition;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceGrouped;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.model.IBoundInstanceModelGroupedAssembly;
import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingDefinitionModelAssembly;
import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingInstance;
import gov.nist.secauto.metaschema.databind.model.metaschema.IBindingMetaschemaModule;
import gov.nist.secauto.metaschema.databind.model.metaschema.binding.AssemblyModel;
import java.util.Map;
import java.util.Set;
import edu.umd.cs.findbugs.annotations.NonNull;
import nl.talsmasoftware.lazy4j.Lazy;
public class InstanceModelGroupedFieldReference
extends AbstractFieldInstance<
IChoiceGroupInstance,
IFieldDefinition,
IFieldInstanceGrouped,
IBindingDefinitionModelAssembly>
implements IFieldInstanceGrouped, IBindingInstance {
@NonNull
private final AssemblyModel.ChoiceGroup.Field binding;
@NonNull
private final IFieldDefinition definition;
@NonNull
private final Map<IAttributable.Key, Set<String>> properties;
@NonNull
private final Lazy<IAssemblyNodeItem> boundNodeItem;
protected InstanceModelGroupedFieldReference(
@NonNull AssemblyModel.ChoiceGroup.Field binding,
@NonNull IBoundInstanceModelGroupedAssembly bindingInstance,
int position,
@NonNull IFieldDefinition definition,
@NonNull IChoiceGroupInstance parent) {
super(parent);
this.binding = binding;
this.definition = definition;
this.properties = ModelSupport.parseProperties(ObjectUtils.requireNonNull(binding.getProps()));
this.boundNodeItem = ObjectUtils.notNull(
Lazy.lazy(() -> (IAssemblyNodeItem) ObjectUtils.notNull(getContainingDefinition().getSourceNodeItem())
.getModelItemsByName(bindingInstance.getXmlQName())
.get(position)));
}
@Override
public IFieldDefinition getDefinition() {
return definition;
}
@NonNull
private AssemblyModel.ChoiceGroup.Field getBinding() {
return binding;
}
@Override
public IBindingMetaschemaModule getContainingModule() {
return getContainingDefinition().getContainingModule();
}
@Override
public Map<IAttributable.Key, Set<String>> getProperties() {
return properties;
}
@Override
public IAssemblyNodeItem getSourceNodeItem() {
return ObjectUtils.notNull(boundNodeItem.get());
}
@Override
public String getName() {
return getDefinition().getName();
}
// ---------------------------------------
// - Start binding driven code - CPD-OFF -
// ---------------------------------------
@Override
public String getUseName() {
return ModelSupport.useName(getBinding().getUseName());
}
@Override
public Integer getUseIndex() {
return ModelSupport.useIndex(getBinding().getUseName());
}
@Override
public String getFormalName() {
return getBinding().getFormalName();
}
@Override
public MarkupLine getDescription() {
return getBinding().getDescription();
}
@Override
public MarkupMultiline getRemarks() {
return ModelSupport.remarks(getBinding().getRemarks());
}
@Override
public String getDiscriminatorValue() {
return getBinding().getDiscriminatorValue();
}
}