Search in sources :

Example 41 with XMIResourceFactoryImpl

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

the class StandaloneFSMLScenario method main.

public static void main(String[] args) {
    ResourceSet rs = new ResourceSetImpl();
    rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("fsml", new XMIResourceFactoryImpl());
    URI uri = URI.createFileURI("path");
    Resource resource = rs.createResource(uri);
    FSM fsm = (FSM) resource.getContents().get(0);
}
Also used : FSM(org.softlang.metalib.emf.fsml.fsml.FSM) 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) URI(org.eclipse.emf.common.util.URI)

Example 42 with XMIResourceFactoryImpl

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

the class FsmlExample method main.

/**
 * <!-- begin-user-doc -->
 * Load all the argument file paths or URIs as instances of the model.
 * <!-- end-user-doc -->
 * @param args the file paths or URIs.
 * @generated
 */
public static void main(String[] args) {
    // Create a resource set to hold the resources.
    // 
    ResourceSet resourceSet = new ResourceSetImpl();
    // Register the appropriate resource factory to handle all file extensions.
    // 
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Register the package to ensure it is available during loading.
    // 
    resourceSet.getPackageRegistry().put(FsmlPackage.eNS_URI, FsmlPackage.eINSTANCE);
    // 
    if (args.length == 0) {
        System.out.println("Enter a list of file paths or URIs that have content like this:");
        try {
            Resource resource = resourceSet.createResource(URI.createURI("http:///My.fsml"));
            FSM root = FsmlFactory.eINSTANCE.createFSM();
            resource.getContents().add(root);
            resource.save(System.out, null);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    } else {
        // 
        for (int i = 0; i < args.length; ++i) {
            // Construct the URI for the instance file.
            // The argument is treated as a file path only if it denotes an existing file.
            // Otherwise, it's directly treated as a URL.
            // 
            File file = new File(args[i]);
            URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
            try {
                // Demand load resource for this file.
                // 
                Resource resource = resourceSet.getResource(uri, true);
                System.out.println("Loaded " + uri);
                // 
                for (EObject eObject : resource.getContents()) {
                    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
                    if (diagnostic.getSeverity() != Diagnostic.OK) {
                        printDiagnostic(diagnostic, "");
                    }
                }
            } catch (RuntimeException exception) {
                System.out.println("Problem loading " + uri);
                exception.printStackTrace();
            }
        }
    }
}
Also used : FSM(org.softlang.metalib.emf.fsml.fsml.FSM) 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) Diagnostic(org.eclipse.emf.common.util.Diagnostic) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) File(java.io.File) URI(org.eclipse.emf.common.util.URI)

Example 43 with XMIResourceFactoryImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl 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)

Example 44 with XMIResourceFactoryImpl

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

the class FSMLUtils method initialize.

public static void initialize() {
    FsmlPackage.eINSTANCE.eClass();
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fsml", new XMIResourceFactoryImpl());
}
Also used : XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)

Example 45 with XMIResourceFactoryImpl

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

the class SimulationEMFUtils method initialize.

public static void initialize() {
    FsmlPackage.eINSTANCE.eClass();
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fsml", new XMIResourceFactoryImpl());
}
Also used : XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)

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