Search in sources :

Example 6 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersons method saveModels.

/**
	 * Allows to save the current state of the source and target models
	 * 
	 * @param name : Filename 
	 */
public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 7 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project benchmarx by eMoflon.

the class EMFUtil method loadExpectedResource.

public static Resource loadExpectedResource(String path, ResourceSet resourceSet) {
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    Resource resource = resourceSet.createResource(URI.createFileURI("resources/" + path + ".xmi"));
    try {
        resource.load(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return resource;
}
Also used : XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException)

Example 8 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project benchmarx by eMoflon.

the class UbtXtendFamiliesToPersons method saveModels.

/**
	 * Allows to save the current state of the source and target models
	 * 
	 * @param name : Filename 
	 */
@Override
public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 9 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project benchmarx by eMoflon.

the class UbtXtendFamiliesToPersons method initiateSynchronisationDialogue.

/**
	 * Initiates a synchronization between a source and a target model. The BXtend Transformation is
	 * initialized and empty source, target and correspondence models are created.
	 * Finally a FamilyRegister is added to the source model and an initial forward transformation is issued
	 * to create a corresponding PersonRegister.
	 */
@Override
public void initiateSynchronisationDialogue() {
    // Fix default preferences (which can be overwritten)
    setConfigurator(new Configurator<Decisions>().makeDecision(Decisions.PREFER_CREATING_PARENT_TO_CHILD, true).makeDecision(Decisions.PREFER_EXISTING_FAMILY_TO_NEW, true));
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put("family", new XMIResourceFactoryImpl());
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put("person", new XMIResourceFactoryImpl());
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put("corr", new XMIResourceFactoryImpl());
    source = set.createResource(URI.createURI("sourceModel.family"));
    target = set.createResource(URI.createURI("targetModel.person"));
    corr = set.createResource(URI.createURI("corrModel.corr"));
    FamilyRegister familiesRoot = FamiliesFactory.eINSTANCE.createFamilyRegister();
    source.getContents().add(familiesRoot);
    f2pt = new Family2PersonTransformation(source, target, corr);
    // Fix default preferences (which can be overwritten)
    setConfigurator(new Configurator<Decisions>().makeDecision(Decisions.PREFER_CREATING_PARENT_TO_CHILD, true).makeDecision(Decisions.PREFER_EXISTING_FAMILY_TO_NEW, true));
    // perform batch to establish consistent starting state
    f2pt.Family2Person();
}
Also used : Family2PersonTransformation(bitrafo.eval.familyperson.rules.Family2PersonTransformation) FamilyRegister(Families.FamilyRegister) Decisions(org.benchmarx.examples.familiestopersons.testsuite.Decisions) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)

Example 10 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersonsConfig method initiateSynchronisationDialogue.

/**
	 * Initiates a synchronization between a source and a target model. The medini QVT engine is initialized,
	 * the required metamodels are registered and empty source, target and configuration models are created.
	 * Finally a FamilyRegister is added to the source model and an initial forward transformation is issued
	 * to create a corresponding PersonRegister.
	 */
@Override
public void initiateSynchronisationDialogue() {
    // delete content of traces folder
    File tracesFolder = new File("./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/traces");
    final File[] files = tracesFolder.listFiles();
    if (files != null) {
        for (File f : files) {
            if (f != null)
                f.delete();
        }
    }
    // in case, no configuration is set, switch to default
    checkConfiguration();
    // Initialise resource set of models
    this.resourceSet = new ResourceSetImpl();
    this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Collect all necessary packages from the metamodel(s)
    Collection<EPackage> metaPackages = new ArrayList<EPackage>();
    this.collectMetaModels(metaPackages);
    // Make these packages known to the QVT engine
    init(metaPackages);
    // Create resources for models
    source = resourceSet.createResource(URI.createURI(RESULTPATH + "/source.xmi"));
    config = resourceSet.createResource(URI.createURI(RESULTPATH + "/config.xmi"));
    target = resourceSet.createResource(URI.createURI(RESULTPATH + "/target.xmi"));
    // Collect the models, which should participate in the transformation.
    // You can provide a list of models for each direction.
    // The models must be added in the same order as defined in your transformation!
    Collection<Collection<Resource>> modelResources = new ArrayList<Collection<Resource>>();
    Collection<Resource> firstSetOfModels = new ArrayList<Resource>();
    Collection<Resource> secondSetOfModels = new ArrayList<Resource>();
    Collection<Resource> thirdSetOfModels = new ArrayList<Resource>();
    modelResources.add(firstSetOfModels);
    modelResources.add(secondSetOfModels);
    modelResources.add(thirdSetOfModels);
    firstSetOfModels.add(source);
    secondSetOfModels.add(config);
    thirdSetOfModels.add(target);
    URI directory = URI.createFileURI(basePath + "traces");
    this.preExecution(modelResources, directory);
    // Call setConfigurator, which will initialize the configurator with default decisions
    setConfigurator(new Configurator<Decisions>());
    source.getContents().add(FamiliesFactory.eINSTANCE.createFamilyRegister());
    config.getContents().add(ConfigFactory.eINSTANCE.createConfiguration());
    launchFWD();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Decisions(org.benchmarx.examples.familiestopersons.testsuite.Decisions) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) Collection(java.util.Collection) File(java.io.File)

Aggregations

XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)50 Injector (com.google.inject.Injector)20 EcoreResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl)20 BinaryGrammarResourceFactoryImpl (org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl)20 Resource (org.eclipse.emf.ecore.resource.Resource)19 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)18 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)15 IOException (java.io.IOException)12 EObject (org.eclipse.emf.ecore.EObject)11 URI (org.eclipse.emf.common.util.URI)10 File (java.io.File)4 FSM (org.softlang.metalib.emf.fsml.fsml.FSM)3 MelangeResourceFactoryImpl (fr.inria.diverse.melange.resource.MelangeResourceFactoryImpl)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Decisions (org.benchmarx.examples.familiestopersons.testsuite.Decisions)2 Diagnostic (org.eclipse.emf.common.util.Diagnostic)2 EPackage (org.eclipse.emf.ecore.EPackage)2 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)2 LoggerFactory (org.slf4j.LoggerFactory)2