Search in sources :

Example 1 with YTDataType

use of org.eclipse.winery.model.tosca.yaml.YTDataType in project winery by eclipse.

the class SchemaVisitor method visit.

@Override
public Result visit(YTServiceTemplate node, Parameter parameter) {
    Map<String, YTDataType> tmpDataTypes = this.data_types;
    this.data_types = node.getDataTypes();
    for (YTMapImportDefinition map : node.getImports()) {
        for (Map.Entry<String, YTImportDefinition> entry : map.entrySet()) {
            addImport(entry.getValue().getNamespaceUri(), new AbstractMap.SimpleEntry<>(entry));
        }
    }
    // init localDataTypesList
    node.getDataTypes().forEach((key, value) -> this.localDatatypeNames.add(key));
    // Default: parameter.datatype is not set -> visit all datatype nodes
    QName type = parameter.getDatatype();
    if (type == null) {
        for (Map.Entry<String, YTDataType> entry : node.getDataTypes().entrySet()) {
            if (entry.getValue() != null) {
                entry.getValue().accept(this, parameter.copy().addContext("datatypes", entry.getKey()));
            }
        }
        visitChildren(node, parameter);
    } else // Optimized: parameter.datatype is set and defined in this service template
    if (type.getNamespaceURI().equals(parameter.getNamespace()) && this.localDatatypeNames.contains(type.getLocalPart())) {
        node.getDataTypes().get(parameter.getDatatype().getLocalPart()).accept(this, parameter.copy().addContext("datatypes", parameter.getDatatype().getLocalPart()));
    }
    if (parameter.getBuildSchema()) {
        for (Map.Entry<String, SchemaBuilder> entry : schemaBuilders.entrySet()) {
            Document document = entry.getValue().build();
            WriterUtils.saveType(document, parameter.getPath(), parameter.getNamespace(), entry.getValue().getNamespace());
        }
    }
    this.data_types = tmpDataTypes;
    return null;
}
Also used : YTDataType(org.eclipse.winery.model.tosca.yaml.YTDataType) QName(javax.xml.namespace.QName) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) Document(org.w3c.dom.Document) AbstractMap(java.util.AbstractMap) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 2 with YTDataType

use of org.eclipse.winery.model.tosca.yaml.YTDataType in project winery by eclipse.

the class SchemaVisitor method visit.

@Override
public Result visit(YTEntityType node, Parameter parameter) {
    if (node instanceof YTDataType || node.getProperties().isEmpty()) {
        return null;
    }
    // BuildPlan for assignments
    Map<String, QName> plan = new LinkedHashMap<>();
    String name = parameter.getKey() + "_Properties";
    SchemaBuilder builder = new SchemaBuilder(parameter.getNamespace());
    Map<String, String> imports = new LinkedHashMap<>();
    for (Map.Entry<String, YTPropertyDefinition> entry : node.getProperties().entrySet()) {
        builder.addElements(entry.getKey(), entry.getValue());
        QName type = entry.getValue().getType();
        if (type.getNamespaceURI() != null && !type.getNamespaceURI().equals(Namespaces.YAML_NS)) {
            imports.put(type.getNamespaceURI(), type.getLocalPart());
        }
        plan.put(entry.getKey(), entry.getValue().getType());
    }
    imports.forEach((key, value) -> builder.addImports(key, getRelativeFileName(key)));
    Document document = builder.buildComplexType(name, true).build();
    WriterUtils.saveType(document, parameter.getPath(), parameter.getNamespace(), name);
    // FIXME this needs access to a repository
    WriterUtils.storeTypes(null, parameter.getPath(), name, parameter.getNamespace(), name);
    this.propertyDefinition.put(new QName(parameter.getNamespace(), name), plan);
    return null;
}
Also used : YTPropertyDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyDefinition) YTDataType(org.eclipse.winery.model.tosca.yaml.YTDataType) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with YTDataType

use of org.eclipse.winery.model.tosca.yaml.YTDataType in project winery by eclipse.

the class ToCanonical method convert.

public TDataType convert(YTDataType node, String id) {
    String name = fixNamespaceDuplication(id, node.getMetadata().get("targetNamespace"));
    TDataType.Builder builder = new TDataType.Builder(name).addConstraints(convertList(node.getConstraints(), this::convert));
    fillEntityTypeProperties(node, builder);
    TDataType result = builder.build();
    // FIXME need to actually transform the node.getProperties() to an xml schema
    // to be able to import it and add a PropertiesDefinition reference to that schema
    String namespace = this.namespace;
    if (namespace == null) {
        // attempt to patch namespace with the definitions' targetNamespace
        namespace = result.getTargetNamespace();
    }
    if (namespace == null) {
        LOGGER.warn("Could not determine namespace for DataType {}. Imports may be incorrect!", id);
        return result;
    }
    TImport importDefinition = new TImport.Builder(Namespaces.XML_NS).setLocation(EncodingUtil.URLencode(namespace) + ".xsd").setNamespace(namespace).build();
    if (!this.imports.contains(importDefinition)) {
        this.imports.add(importDefinition);
    }
    return result;
}
Also used : TImport(org.eclipse.winery.model.tosca.TImport) TDataType(org.eclipse.winery.model.tosca.TDataType) YTDataType(org.eclipse.winery.model.tosca.yaml.YTDataType)

Aggregations

YTDataType (org.eclipse.winery.model.tosca.yaml.YTDataType)3 AbstractMap (java.util.AbstractMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 Document (org.w3c.dom.Document)2 TDataType (org.eclipse.winery.model.tosca.TDataType)1 TImport (org.eclipse.winery.model.tosca.TImport)1 YTImportDefinition (org.eclipse.winery.model.tosca.yaml.YTImportDefinition)1 YTPropertyDefinition (org.eclipse.winery.model.tosca.yaml.YTPropertyDefinition)1 YTMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition)1