Search in sources :

Example 16 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project xtext-core by eclipse.

the class TerminalRulesTestLanguageStandaloneSetupGenerated method createInjectorAndDoEMFRegistration.

@Override
public Injector createInjectorAndDoEMFRegistration() {
    // register default ePackages
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin"))
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtextbin", new BinaryGrammarResourceFactoryImpl());
    if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI))
        EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE);
    Injector injector = createInjector();
    register(injector);
    return injector;
}
Also used : EcoreResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl) Injector(com.google.inject.Injector) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) BinaryGrammarResourceFactoryImpl(org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl)

Example 17 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project xtext-core by eclipse.

the class EcoreUtil2Test method testClone.

@Test
public void testClone() throws Exception {
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    EPackage.Registry.INSTANCE.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE);
    ResourceSetImpl rs = new ResourceSetImpl();
    Resource r1 = rs.createResource(URI.createURI("foo.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
    Resource r2 = rs.createResource(URI.createURI("bar.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
    EClass a = EcoreFactory.eINSTANCE.createEClass();
    a.setName("a");
    EClass b = EcoreFactory.eINSTANCE.createEClass();
    r1.getContents().add(a);
    b.setName("b");
    b.getESuperTypes().add(a);
    r2.getContents().add(b);
    ResourceSetImpl clone = EcoreUtil2.clone(new ResourceSetImpl(), rs);
    EList<Resource> list = clone.getResources();
    Resource resA = list.get(0);
    assertEquals(URI.createURI("foo.xmi"), resA.getURI());
    assertNotSame(resA, r1);
    Resource resB = list.get(1);
    assertEquals(URI.createURI("bar.xmi"), resB.getURI());
    assertNotSame(resB, r2);
    EClass a1 = (EClass) resA.getContents().get(0);
    EClass b1 = (EClass) resB.getContents().get(0);
    assertEquals("a", a1.getName());
    assertNotSame(a, a1);
    assertEquals("b", b1.getName());
    assertNotSame(b, b1);
    assertSame(b1.getESuperTypes().get(0), a1);
    assertSame(b.getESuperTypes().get(0), a);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) Test(org.junit.Test)

Example 18 with XMIResourceFactoryImpl

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

the class LWM2MMappingParseTest method createMappingModel.

private MappingModel createMappingModel(String mappingFileName) throws IOException {
    ResourceSet rset = new ResourceSetImpl();
    rset.getPackageRegistry().put(MappingPackage.eNS_URI, MappingPackage.eINSTANCE);
    rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    Resource resource = rset.getResource(URI.createFileURI(EXAMPLES_DIRECTORY + mappingFileName), true);
    resource.load(null);
    MappingModel mappingModel = (MappingModel) resource.getContents().get(0);
    return mappingModel;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 19 with XMIResourceFactoryImpl

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

the class MappingModelSyntaxTest method createMappingModel.

private MappingModel createMappingModel(String mappingFileName) throws IOException {
    ResourceSet rset = new ResourceSetImpl();
    rset.getPackageRegistry().put(MappingPackage.eNS_URI, MappingPackage.eINSTANCE);
    rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    String exampleSmarthomeMappingFile = EXAMPLES_DIRECTORY + mappingFileName;
    Resource resource = rset.getResource(URI.createFileURI(exampleSmarthomeMappingFile), true);
    resource.load(null);
    MappingModel mappingModel = (MappingModel) resource.getContents().get(0);
    return mappingModel;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 20 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project iobserve-analysis by research-iobserve.

the class AbstractModelHandler method save.

/**
 * Save the internal model. This will override the existing.
 *
 * @param writeModelURI
 *            URI refering where to store the model
 * @param model
 *            is the model to be stored
 */
public final void save(final URI writeModelURI, final T model) {
    final Resource.Factory.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);
    final Resource resource = resourceSet.createResource(writeModelURI);
    resource.getContents().add(model);
    try {
        resource.save(null);
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) LoggerFactory(org.slf4j.LoggerFactory) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException)

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