Search in sources :

Example 1 with Registry

use of org.eclipse.emf.ecore.resource.Resource.Factory.Registry in project iobserve-analysis by research-iobserve.

the class ModelSnapshotWriter method execute.

@Override
protected void execute(final PCMDeployedEvent element) throws Exception {
    final File revisionOutputDirectory = new File(String.format("%s%s%08d", this.modelDumpDirectory.toPath().toAbsolutePath().toString(), File.separator, this.modelIndex));
    revisionOutputDirectory.mkdir();
    this.modelIndex++;
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.setResourceFactoryRegistry(resourceRegistry);
    /**
     * load all models into resource set.
     */
    final Resource correspondenceEMFResource = this.loadModel(resourceSet, this.correspondenceResource, CorrespondenceModel.class, CorrespondencePackage.Literals.CORRESPONDENCE_MODEL, CorrespondencePackage.eINSTANCE, revisionOutputDirectory);
    final Resource repositoryModelEMFResource = this.loadModel(resourceSet, this.repositoryResource, Repository.class, RepositoryPackage.Literals.REPOSITORY, RepositoryPackage.eINSTANCE, revisionOutputDirectory);
    final Resource resourceEnvironmentModelEMFResource = this.loadModel(resourceSet, this.resourceEnvironmentResource, ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT, ResourceenvironmentPackage.eINSTANCE, revisionOutputDirectory);
    final Resource assemblyModelEMFResource = this.loadModel(resourceSet, this.assemblyResource, System.class, SystemPackage.Literals.SYSTEM, SystemPackage.eINSTANCE, revisionOutputDirectory);
    final Resource allocationModelEMFResource = this.loadModel(resourceSet, this.allocationResource, Allocation.class, AllocationPackage.Literals.ALLOCATION, AllocationPackage.eINSTANCE, revisionOutputDirectory);
    final Resource privacyModelEMFResource = this.loadModel(resourceSet, this.dataProtectionModelResource, DataProtectionModel.class, PrivacyPackage.Literals.DATA_PROTECTION_MODEL, PrivacyPackage.eINSTANCE, revisionOutputDirectory);
    /**
     * Resolve models.
     */
    ModelNeo4JUtil.resolveAll(resourceSet, this.correspondenceResource, this.repositoryResource, this.resourceEnvironmentResource, this.assemblyResource, this.allocationResource, this.dataProtectionModelResource);
    /**
     * store.
     */
    repositoryModelEMFResource.save(null);
    resourceEnvironmentModelEMFResource.save(null);
    assemblyModelEMFResource.save(null);
    allocationModelEMFResource.save(null);
    privacyModelEMFResource.save(null);
    correspondenceEMFResource.save(null);
    this.outputPort.send(element);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) IModelResource(org.iobserve.model.persistence.IModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) File(java.io.File)

Example 2 with Registry

use of org.eclipse.emf.ecore.resource.Resource.Factory.Registry in project iobserve-analysis by research-iobserve.

the class EvalProxyDBTest method test.

@Test
public void test() throws IOException, DBException {
    new File(EvalProxyDBTest.MODEL_ONE).delete();
    // create model
    final Root modelOne = TestModelData.createModelOne();
    final Two modelTwo = TestModelData.createModelTwo();
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.setResourceFactoryRegistry(resourceRegistry);
    // put in resources
    final Resource resourceOne = resourceSet.createResource(URI.createFileURI(EvalProxyDBTest.MODEL_ONE));
    resourceOne.getContents().add(modelOne);
    final Resource resourceTwo = resourceSet.createResource(URI.createFileURI(EvalProxyDBTest.MODEL_TWO));
    resourceTwo.getContents().add(modelTwo);
    // save models
    resourceOne.save(null);
    resourceTwo.save(null);
    // store in DB
    final Neo4JModelResource<Root> dbResourceOne = ModelProviderTestUtils.prepareResource("testStoreGraphCreate1", this.prefix, TwoPackage.eINSTANCE);
    dbResourceOne.storeModelPartition(modelOne);
    final Neo4JModelResource<Two> dbResourceTwo = ModelProviderTestUtils.prepareResource("testStoreGraphCreate2", this.prefix, TwoPackage.eINSTANCE);
    dbResourceTwo.storeModelPartition(modelTwo);
    // retrieve model two
    final Two retrievedModelTwo = dbResourceTwo.getModelRootNode(Two.class, TwoPackage.Literals.TWO);
    this.checkProxies("A", retrievedModelTwo);
    ModelNeo4JUtil.printModel(retrievedModelTwo);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Root(org.iobserve.model.test.storage.one.Root) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Two(org.iobserve.model.test.storage.two.Two) File(java.io.File) Test(org.junit.Test)

Example 3 with Registry

use of org.eclipse.emf.ecore.resource.Resource.Factory.Registry in project iobserve-analysis by research-iobserve.

the class EvalProxyTest method test.

@Test
public void test() throws IOException {
    new File(EvalProxyTest.MODEL_ONE).delete();
    new File(EvalProxyTest.MODEL_X_ONE).delete();
    // create model
    final Root modelOne = TestModelData.createModelOne();
    final Two modelTwo = TestModelData.createModelTwo();
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.setResourceFactoryRegistry(resourceRegistry);
    // put in resources
    final Resource resourceOne = resourceSet.createResource(URI.createFileURI(EvalProxyTest.MODEL_ONE));
    resourceOne.getContents().add(modelOne);
    final Resource resourceTwo = resourceSet.createResource(URI.createFileURI(EvalProxyTest.MODEL_TWO));
    resourceTwo.getContents().add(modelTwo);
    // save models
    resourceOne.save(null);
    resourceTwo.save(null);
    this.rename(EvalProxyTest.MODEL_ONE, EvalProxyTest.MODEL_X_ONE);
    TwoPackage.eINSTANCE.eClass();
    OnePackage.eINSTANCE.eClass();
    // read model two
    final Registry resourceRegistry2 = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map2 = resourceRegistry2.getExtensionToFactoryMap();
    map2.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet2 = new ResourceSetImpl();
    resourceSet2.setResourceFactoryRegistry(resourceRegistry2);
    final Resource resourceTwo2 = resourceSet2.getResource(URI.createFileURI(EvalProxyTest.MODEL_TWO), true);
    resourceTwo2.load(resourceSet2.getLoadOptions());
    // check proxies
    this.checkProxies("A", resourceTwo2);
    // read model one
    this.rename(EvalProxyTest.MODEL_X_ONE, EvalProxyTest.MODEL_ONE);
    final Resource resourceOne2 = resourceSet2.getResource(URI.createFileURI(EvalProxyTest.MODEL_ONE), true);
    resourceTwo2.load(resourceSet2.getLoadOptions());
    resourceOne2.load(resourceSet2.getLoadOptions());
    // check proxies
    this.checkProxies("B", resourceTwo2);
    // resolve proxies
    for (final Resource a : resourceSet2.getResources()) {
        System.out.println("resource " + a.getURI());
    }
    EcoreUtil.resolveAll(resourceTwo2);
    // check proxies
    this.checkProxies("C", resourceTwo2);
    // do it again
    final Registry resourceRegistry3 = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map3 = resourceRegistry2.getExtensionToFactoryMap();
    map3.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet3 = new ResourceSetImpl();
    resourceSet3.setResourceFactoryRegistry(resourceRegistry3);
    final Resource resourceTwo3 = resourceSet3.getResource(URI.createFileURI(EvalProxyTest.MODEL_TWO), true);
    resourceTwo3.load(resourceSet3.getLoadOptions());
    // check proxies
    this.checkProxies("D", resourceTwo3);
    final Resource resourceOne3 = resourceSet3.getResource(URI.createFileURI(EvalProxyTest.MODEL_ONE), true);
    resourceOne3.load(resourceSet3.getLoadOptions());
    // check proxies
    this.checkProxies("E", resourceTwo3);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Root(org.iobserve.model.test.storage.one.Root) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) File(java.io.File) Two(org.iobserve.model.test.storage.two.Two) Test(org.junit.Test)

Example 4 with Registry

use of org.eclipse.emf.ecore.resource.Resource.Factory.Registry in project iobserve-analysis by research-iobserve.

the class ECoreNeo4JTest method setUp.

/**
 * Setup test.
 *
 * @throws Exception
 *             on error
 */
@Before
public void setUp() {
    this.prefix = this.getClass().getCanonicalName();
    this.modelOne = TestModelData.createModelOne();
    this.modelTwo = TestModelData.createModelTwo();
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    try {
        final ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.setResourceFactoryRegistry(resourceRegistry);
        final Resource resource = resourceSet.createResource(URI.createFileURI("storage-example.storage"));
        resource.getContents().add(this.modelOne);
        resource.save(null);
    } catch (final IOException e) {
        Assert.fail(e.getLocalizedMessage());
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) Before(org.junit.Before)

Example 5 with Registry

use of org.eclipse.emf.ecore.resource.Resource.Factory.Registry in project metalib by softlang.

the class StandaloneTurnstile method main.

public static void main(String[] args) {
    // Register package as a side-effect.
    FsmlPackage.eINSTANCE.eClass();
    // The ResourceSet that this standalone application is using.
    ResourceSet resourceSet = new ResourceSetImpl();
    // Get the registry for ResourceFactories.
    Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
    // Register the XMIResourceFactory for files with fsml extension.
    XMIResourceFactoryImpl xmiResourceFactory = new XMIResourceFactoryImpl();
    resourceFactoryRegistry.getExtensionToFactoryMap().put("fsml", xmiResourceFactory);
    // Deserialize XMI File.
    Resource fsmlResource = resourceSet.getResource(URI.createURI("Turnstile.fsml"), true);
    // Read the Turnstile model.
    FSM fsmTurnstileEObject = (FSM) fsmlResource.getContents().get(0);
    EList<FSMState> fsmTurnstileStateEObjects = fsmTurnstileEObject.getStates();
}
Also used : FSM(org.softlang.metalib.emf.fsml.fsml.FSM) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) FSMState(org.softlang.metalib.emf.fsml.fsml.FSMState) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)5 Registry (org.eclipse.emf.ecore.resource.Resource.Factory.Registry)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)5 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)5 File (java.io.File)3 EObject (org.eclipse.emf.ecore.EObject)2 Neo4JModelResource (org.iobserve.model.persistence.neo4j.Neo4JModelResource)2 Root (org.iobserve.model.test.storage.one.Root)2 Two (org.iobserve.model.test.storage.two.Two)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 IModelResource (org.iobserve.model.persistence.IModelResource)1 Before (org.junit.Before)1 FSM (org.softlang.metalib.emf.fsml.fsml.FSM)1 FSMState (org.softlang.metalib.emf.fsml.fsml.FSMState)1