use of org.eclipse.winery.model.tosca.xml.XTEntityType in project winery by eclipse.
the class ToCanonical method fillEntityTypeProperties.
private <Builder extends TEntityType.Builder<Builder>, Value extends XTEntityType> void fillEntityTypeProperties(Builder builder, Value xml) {
if (xml.getTags() != null) {
builder.addTags(xml.getTags().stream().map(this::convert).collect(Collectors.toList()));
}
if (xml.getDerivedFrom() != null) {
TEntityType.DerivedFrom derived = new TEntityType.DerivedFrom();
derived.setTypeRef(xml.getDerivedFrom().getTypeRef());
builder.setDerivedFrom(derived);
}
if (xml.getPropertiesDefinition() != null) {
if (xml.getPropertiesDefinition().getElement() != null) {
builder.setProperties(new TEntityType.XmlElementDefinition(xml.getPropertiesDefinition().getElement()));
} else if (xml.getPropertiesDefinition().getType() != null) {
builder.setProperties(new TEntityType.XmlTypeDefinition(xml.getPropertiesDefinition().getType()));
} else {
throw new IllegalStateException("If a PropertiesDefinition is given, either Element or Type must be specified!");
}
}
if (xml.getAny().stream().anyMatch(anyElement -> anyElement instanceof WinerysPropertiesDefinition)) {
WinerysPropertiesDefinition def = xml.getAny().stream().filter(el -> el instanceof WinerysPropertiesDefinition).map(WinerysPropertiesDefinition.class::cast).findFirst().orElse(null);
builder.setProperties(def);
// remove the element we've recognized as a property to avoid duplicating it in the canonical model
xml.getAny().remove(def);
}
builder.setAbstract(xml.getAbstract() == XTBoolean.YES);
builder.setFinal(xml.getFinal() == XTBoolean.YES);
builder.setTargetNamespace(xml.getTargetNamespace());
fillExtensibleElementsProperties(builder, xml);
}
Aggregations