All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hu.blackbelt.epsilon.runtime.execution.model.plainxml.PlainXmlModelContext Maven / Gradle / Ivy

package hu.blackbelt.epsilon.runtime.execution.model.plainxml;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import hu.blackbelt.epsilon.runtime.execution.api.Log;
import hu.blackbelt.epsilon.runtime.execution.api.ModelContext;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.eclipse.epsilon.eol.models.IModel;
import org.eclipse.epsilon.eol.models.ModelReference;
import org.eclipse.epsilon.eol.models.ModelRepository;

import java.util.List;
import java.util.Map;

@Data
@Builder(builderMethodName = "plainXmlModelContextBuilder")
@EqualsAndHashCode
public class PlainXmlModelContext implements ModelContext {

    public static final String XML = "xml";
    @NonNull
    String name;

    @NonNull
    String xml;

    @Builder.Default
    List aliases = ImmutableList.of();

    @Builder.Default
    boolean readOnLoad = true;

    @Builder.Default
    boolean storeOnDisposal = false;

    @Builder.Default
    boolean cached = true;


    @Override
    public String toString() {
        return "PlainXmlModelContext{" +
                "artifacts='" + getArtifacts() + '\'' +
                ", name='" + name + '\'' +
                ", aliases=" + aliases +
                ", uriConverterMap='" + getUriConverterMap() + '\'' +
                ", readOnLoad=" + readOnLoad +
                ", storeOnDisposal=" + storeOnDisposal +
                ", cached=" + cached +
                '}';
    }

    @Override
    public void addAliases(ModelRepository repository, ModelReference ref) {
        ref.setName(this.getName());
        if (this.getAliases() != null) {
            for (String alias : this.getAliases()) {
                ref.getAliases().add(alias);
            }
        }
        repository.addModel(ref);
    }

    @Override
    public Map getArtifacts() {
        return ImmutableMap.of(XML, xml);
    }

    @Override
    public Map getUriConverterMap() {
        return ImmutableMap.of();
    }

    @Override
    public IModel load(Log log, ResourceSet resourceSet, ModelRepository repository, Map uriMap, Map uriConverterMap) throws EolModelLoadingException {
        return PlainXmlModelUtil.loadPlainXml(log, resourceSet, repository, this, uriMap.get(XML));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy