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);
}
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);
}
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);
}
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());
}
}
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();
}
Aggregations