XmlInlineAssemblyDefinition.java
/*
* SPDX-FileCopyrightText: none
* SPDX-License-Identifier: CC0-1.0
*/
package gov.nist.secauto.metaschema.core.model.xml.impl; // NOPMD - excessive public methods and coupling is unavoidable
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.core.model.AbstractInlineAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IAssemblyInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IAttributable;
import gov.nist.secauto.metaschema.core.model.IChoiceGroupInstance;
import gov.nist.secauto.metaschema.core.model.IChoiceInstance;
import gov.nist.secauto.metaschema.core.model.IContainerFlagSupport;
import gov.nist.secauto.metaschema.core.model.IContainerModel;
import gov.nist.secauto.metaschema.core.model.IContainerModelAssemblySupport;
import gov.nist.secauto.metaschema.core.model.IFieldInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.INamedModelInstanceAbsolute;
import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior;
import gov.nist.secauto.metaschema.core.model.constraint.AssemblyConstraintSet;
import gov.nist.secauto.metaschema.core.model.constraint.IModelConstrained;
import gov.nist.secauto.metaschema.core.model.xml.xmlbeans.InlineAssemblyDefinitionType;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import java.util.Map;
import java.util.Set;
import edu.umd.cs.findbugs.annotations.NonNull;
import nl.talsmasoftware.lazy4j.Lazy;
/**
* Represents a Metaschema assembly definition declared locally as an instance.
*/
class XmlInlineAssemblyDefinition
extends AbstractInlineAssemblyDefinition<
IContainerModel,
IAssemblyDefinition,
IAssemblyInstanceAbsolute,
IAssemblyDefinition,
IFlagInstance,
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
IAssemblyInstanceAbsolute,
IChoiceInstance,
IChoiceGroupInstance>
implements IAssemblyInstanceAbsolute {
// ----------------------------------------
// - Start XmlBeans driven code - CPD-OFF -
// ----------------------------------------
@NonNull
private final InlineAssemblyDefinitionType xmlObject;
@NonNull
private final Lazy<IContainerFlagSupport<IFlagInstance>> flagContainer;
@NonNull
private final Lazy<IContainerModelAssemblySupport<
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
IAssemblyInstanceAbsolute,
IChoiceInstance,
IChoiceGroupInstance>> modelContainer;
@NonNull
private final Lazy<IModelConstrained> constraints;
/**
* Constructs a new Metaschema assembly definition from an XML representation
* bound to Java objects.
*
* @param xmlObject
* the XML representation bound to Java objects
* @param parent
* the parent container, either a choice or assembly
*/
public XmlInlineAssemblyDefinition(
@NonNull InlineAssemblyDefinitionType xmlObject,
@NonNull IContainerModel parent) {
super(parent);
this.xmlObject = xmlObject;
this.flagContainer = ObjectUtils.notNull(Lazy.lazy(() -> XmlFlagContainerSupport.newInstance(xmlObject, this)));
this.modelContainer
= ObjectUtils.notNull(Lazy.lazy(() -> XmlAssemblyModelContainerSupport.of(xmlObject.getModel(), this)));
this.constraints = ObjectUtils.notNull(Lazy.lazy(() -> {
IModelConstrained retval = new AssemblyConstraintSet();
if (getXmlObject().isSetConstraint()) {
ConstraintXmlSupport.parse(
retval,
ObjectUtils.notNull(getXmlObject().getConstraint()),
getContainingModule().getSource());
}
return retval;
}));
}
@SuppressWarnings("null")
@Override
public IContainerFlagSupport<IFlagInstance> getFlagContainer() {
return flagContainer.get();
}
@SuppressWarnings("null")
@Override
public IContainerModelAssemblySupport<
IModelInstanceAbsolute,
INamedModelInstanceAbsolute,
IFieldInstanceAbsolute,
IAssemblyInstanceAbsolute,
IChoiceInstance,
IChoiceGroupInstance> getModelContainer() {
return modelContainer.get();
}
@SuppressWarnings("null")
@Override
public IModelConstrained getConstraintSupport() {
return constraints.get();
}
/**
* Get the underlying XML model.
*
* @return the XML model
*/
protected InlineAssemblyDefinitionType getXmlObject() {
return xmlObject;
}
@Override
public String getFormalName() {
return getXmlObject().isSetFormalName() ? getXmlObject().getFormalName() : null;
}
@SuppressWarnings("null")
@Override
public MarkupLine getDescription() {
return getXmlObject().isSetDescription()
? MarkupStringConverter.toMarkupString(getXmlObject().getDescription())
: null;
}
@Override
public Map<IAttributable.Key, Set<String>> getProperties() {
return ModelFactory.toProperties(CollectionUtil.listOrEmpty(getXmlObject().getPropList()));
}
@SuppressWarnings("null")
@Override
public String getName() {
return getXmlObject().getName();
}
@Override
public Integer getIndex() {
return getXmlObject().isSetIndex() ? getXmlObject().getIndex().intValue() : null;
}
@Override
public String getGroupAsName() {
return getXmlObject().isSetGroupAs() ? getXmlObject().getGroupAs().getName() : null;
}
@Override
public int getMinOccurs() {
return XmlModelParser.getMinOccurs(getXmlObject().getMinOccurs());
}
@Override
public int getMaxOccurs() {
return XmlModelParser.getMaxOccurs(getXmlObject().getMaxOccurs());
}
@Override
public JsonGroupAsBehavior getJsonGroupAsBehavior() {
return XmlModelParser.getJsonGroupAsBehavior(getXmlObject().getGroupAs());
}
@Override
public XmlGroupAsBehavior getXmlGroupAsBehavior() {
return XmlModelParser.getXmlGroupAsBehavior(getXmlObject().getGroupAs());
}
@SuppressWarnings("null")
@Override
public MarkupMultiline getRemarks() {
return getXmlObject().isSetRemarks() ? MarkupStringConverter.toMarkupString(getXmlObject().getRemarks()) : null;
}
// -------------------------------------
// - End XmlBeans driven code - CPD-ON -
// -------------------------------------
}