org.eclipse.viatra.dse.util

## Class EMFHelper

- java.lang.Object
- - org.eclipse.viatra.dse.util.EMFHelper

-     public final class EMFHelper
      extends java.lang.Object

  This class contains static helper methods.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `EMFHelper.EmfHelperException`
    `static class` | `EMFHelper.ENamedElementComparator`
    `static class` | `EMFHelper.MetaModelElements` This class is used to store `EClass`es, `EAttribute`s, `EReference`s, EAttributes by EClasses, EReferences by EClasses for a given set of `EPackage`s.

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static org.eclipse.emf.common.notify.Notifier` | `clone(org.eclipse.emf.common.notify.Notifier notifier)` Clones the given model.
    `static org.eclipse.emf.edit.domain.EditingDomain` | `createEditingDomain(org.eclipse.emf.common.notify.Notifier notifier)` Creates (or gets if already exists) an `EditingDomain` over the given `Notifier`, either an `EObject`, `Resource` or `ResourceSet`.
    `static EMFHelper.MetaModelElements` | `getAllMetaModelElements(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)` Traverses the full metamodel on the given `EPackage`s and returns all the classes, attributes and references it contains.
    `static EMFHelper.MetaModelElements` | `getAttrbiutes(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)` Return a `EMFHelper.MetaModelElements` instance populated with its `EMFHelper.MetaModelElements.attributes` and `EMFHelper.MetaModelElements.attributesOfClass`.
    `static EMFHelper.MetaModelElements` | `getClasses(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)` Return a `EMFHelper.MetaModelElements` instance populated with its `EMFHelper.MetaModelElements.classes`.
    `static java.util.List<org.eclipse.emf.ecore.EModelElement>` | `getClassesAndReferences(java.util.Collection<org.eclipse.emf.ecore.EPackage> metaModelPackages)` Deprecated. Use `getAllMetaModelElements(Set)` instead.
    `static org.eclipse.emf.edit.domain.EditingDomain` | `getEditingDomain(org.eclipse.emf.common.notify.Notifier notifier)` Gets the `EditingDomain` of either an `EObject`, `Resource` or `ResourceSet`.
    `static EMFHelper.MetaModelElements` | `getReferences(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)` Return a `EMFHelper.MetaModelElements` instance populated with its `EMFHelper.MetaModelElements.references` and `EMFHelper.MetaModelElements.referencesOfClass`.
    `static org.eclipse.emf.ecore.EObject` | `getRootEObject(org.eclipse.emf.common.notify.Notifier notifier)` Retrieves the root EObject from a Resource or ResourceSet.
    `static org.eclipse.emf.ecore.resource.Resource` | `loadModel(java.lang.String fileName)` Loads a model as a `Resource`.
    `static void` | `registerExtensionForXmiSerializer(java.lang.String ext)` Registers an `XMIResourceFactoryImpl` for the given extension.
    `static void` | `saveModel(org.eclipse.emf.common.notify.Notifier model, java.lang.String fileName)` Saves the EMF model (EObject or Resource) into the given file.
    `static void` | `serializeModel(org.eclipse.emf.ecore.EObject root, java.lang.String name, java.lang.String ext)` Deprecated. Use `saveModel(Notifier, String)` instead.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getEditingDomain

          public static org.eclipse.emf.edit.domain.EditingDomain getEditingDomain(org.eclipse.emf.common.notify.Notifier notifier)

      Gets the `EditingDomain` of either an `EObject`, `Resource` or `ResourceSet`.
      Parameters:
        `notifier` - The `Notifier`.
      Returns:
        The EditingDomain.

    - #### createEditingDomain

          public static org.eclipse.emf.edit.domain.EditingDomain createEditingDomain(org.eclipse.emf.common.notify.Notifier notifier)

      Creates (or gets if already exists) an `EditingDomain` over the given `Notifier`, either an `EObject`, `Resource` or `ResourceSet`.
      Parameters:
        `notifier` - The `Notifier`.
      Returns:
        The EditingDomain.

    - #### serializeModel

          @Deprecated
          public static void serializeModel(org.eclipse.emf.ecore.EObject root,
                                                        java.lang.String name,
                                                        java.lang.String ext)

      Deprecated. Use `saveModel(Notifier, String)` instead.
      Saves the EMF model into the given file. An `XMIResourceFactoryImpl` will be registered if not already.
      Parameters:
        `root` - The root of model.
        `name` - The name or path of the file.
        `ext` - The extension of the file.

    - #### saveModel

          public static void saveModel(org.eclipse.emf.common.notify.Notifier model,
                                       java.lang.String fileName)

      Saves the EMF model (EObject or Resource) into the given file. An `XMIResourceFactoryImpl` will be registered if not already. Doesn't throw exception but logs an error if the save was unsuccessful.
      Parameters:
        `model` - Can be an `EObject` or a `Resource`.
        `fileName` -

    - #### loadModel

          public static org.eclipse.emf.ecore.resource.Resource loadModel(java.lang.String fileName)
                                                                   throws java.io.IOException

      Loads a model as a `Resource`. In headless mode, don't forget to call XYZPackage.eINSTANCE.
      Throws:
        `java.io.IOException`

    - #### getRootEObject

          public static org.eclipse.emf.ecore.EObject getRootEObject(org.eclipse.emf.common.notify.Notifier notifier)

      Retrieves the root EObject from a Resource or ResourceSet.
      - Returns null if there is no content.
      - Returns the notifier itself if it is an EObject.
      - Logs a warn if there are multiple roots.
      Parameters:
        `notifier` -
      Returns:
        The root EObject or null.

    - #### registerExtensionForXmiSerializer

          public static void registerExtensionForXmiSerializer(java.lang.String ext)

      Registers an `XMIResourceFactoryImpl` for the given extension.
      Parameters:
        `ext` - The extension as a String.

    - #### clone

          public static org.eclipse.emf.common.notify.Notifier clone(org.eclipse.emf.common.notify.Notifier notifier)

      Clones the given model. Either an `EObject`, `Resource` or `ResourceSet`.
      Parameters:
        `notifier` - The root container of the model.
      Returns:
        The cloned model.

    - #### getClassesAndReferences

          public static java.util.List<org.eclipse.emf.ecore.EModelElement> getClassesAndReferences(java.util.Collection<org.eclipse.emf.ecore.EPackage> metaModelPackages)

      Deprecated. Use `getAllMetaModelElements(Set)` instead.
      Collects all the classes and references from the given `EPackage`s.

    - #### getAllMetaModelElements

          public static EMFHelper.MetaModelElements getAllMetaModelElements(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)

      Traverses the full metamodel on the given `EPackage`s and returns all the classes, attributes and references it contains.
      Parameters:
        `metaModelPackages` - The set of `EPackage`s.
      Returns:
        A `EMFHelper.MetaModelElements` instance containing the metamodel elements.

    - #### getClasses

          public static EMFHelper.MetaModelElements getClasses(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)

      Return a `EMFHelper.MetaModelElements` instance populated with its `EMFHelper.MetaModelElements.classes`.
      Parameters:
        `metaModelPackages` - The set of `EPackage`s.
      Returns:
        AA `EMFHelper.MetaModelElements` instance.

    - #### getReferences

          public static EMFHelper.MetaModelElements getReferences(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)

      Return a `EMFHelper.MetaModelElements` instance populated with its `EMFHelper.MetaModelElements.references` and `EMFHelper.MetaModelElements.referencesOfClass`.
      Parameters:
        `metaModelPackages` - The set of `EPackage`s.
      Returns:
        AA `EMFHelper.MetaModelElements` instance.

    - #### getAttrbiutes

          public static EMFHelper.MetaModelElements getAttrbiutes(java.util.Set<org.eclipse.emf.ecore.EPackage> metaModelPackages)

      Return a `EMFHelper.MetaModelElements` instance populated with its `EMFHelper.MetaModelElements.attributes` and `EMFHelper.MetaModelElements.attributesOfClass`.
      Parameters:
        `metaModelPackages` - The set of `EPackage`s.
      Returns:
        AA `EMFHelper.MetaModelElements` instance.