Search in sources :

Example 1 with TMapImportDefinition

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

the class SchemaVisitor method visit.

public Map<QName, Map<String, QName>> visit(TServiceTemplate node, Path path, Path outpath, String namespace) {
    for (TMapImportDefinition map : node.getImports()) {
        for (Map.Entry<String, TImportDefinition> entry : map.entrySet()) {
            Reader reader = Reader.getReader();
            try {
                TServiceTemplate serviceTemplate = reader.parse(entry.getValue(), path, entry.getValue().getNamespaceUri());
                visit(serviceTemplate, new Parameter(outpath, entry.getValue().getNamespaceUri()).setBuildSchema(false));
            } catch (MultiException e) {
                setException(e);
            }
        }
    }
    this.visit(node, new Parameter(outpath, namespace));
    return propertyDefinition;
}
Also used : TMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.TMapImportDefinition) Reader(org.eclipse.winery.yaml.common.reader.yaml.Reader) Parameter(org.eclipse.winery.yaml.converter.yaml.visitors.support.Parameter) MultiException(org.eclipse.winery.yaml.common.exception.MultiException)

Example 2 with TMapImportDefinition

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

the class SchemaVisitor method visit.

@Override
public Result visit(TServiceTemplate node, Parameter parameter) {
    Map<String, TDataType> tmpDataTypes = this.data_types;
    this.data_types = node.getDataTypes();
    for (TMapImportDefinition map : node.getImports()) {
        for (Map.Entry<String, TImportDefinition> 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, TDataType> entry : node.getDataTypes().entrySet()) {
            if (entry.getValue() != null) {
                entry.getValue().accept(this, parameter.copy().addContext("datatypes", entry.getKey()));
            }
        }
        visitChildes(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 : TMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.TMapImportDefinition) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) SchemaBuilder(org.eclipse.winery.yaml.converter.yaml.support.SchemaBuilder)

Aggregations

TMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.TMapImportDefinition)2 QName (javax.xml.namespace.QName)1 MultiException (org.eclipse.winery.yaml.common.exception.MultiException)1 Reader (org.eclipse.winery.yaml.common.reader.yaml.Reader)1 SchemaBuilder (org.eclipse.winery.yaml.converter.yaml.support.SchemaBuilder)1 Parameter (org.eclipse.winery.yaml.converter.yaml.visitors.support.Parameter)1 Document (org.w3c.dom.Document)1