Class ResourceUtils


  • public final class ResourceUtils
    extends Object
    Helper methods to load and save EMF resources.
    Version:
    $Rev$
    Author:
    herrmama, $Author$
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean exists​(org.eclipse.emf.common.util.URI uri)
      Check whether a file exists for a certain URI.
      static <E extends org.eclipse.emf.ecore.EObject>
      List<E>
      getRootElements​(org.eclipse.emf.ecore.resource.Resource resource, Class<E> type)
      Get the root model elements.
      static <E extends org.eclipse.emf.ecore.EObject>
      List<E>
      getRootElements​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet, Class<E> type)
      Get the root model elements.
      static boolean isPathmap​(org.eclipse.emf.common.util.URI uri)
      Determines whether this URI is a path map URI.
      static boolean isPlatformResource​(org.eclipse.emf.ecore.resource.Resource resource)
      Decide whether a resource is a platform resource.
      static <V extends org.eclipse.emf.ecore.EObject>
      V
      loadElement​(org.eclipse.emf.common.util.URI uri)
      Load a resource based on a URI and return its root element.
      static org.eclipse.emf.ecore.resource.Resource loadResource​(org.eclipse.emf.common.util.URI uri)
      Load a resource based on a URI.
      static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(String fileName)
      Load EMF model based on file name (use the packages already added to the registry).
      static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(String fileName, List<org.eclipse.emf.ecore.EPackage> ePackages)
      Load EMF model based on file name and root packages.
      static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(List<org.eclipse.emf.common.util.URI> modelURIs, List<org.eclipse.emf.ecore.EPackage> ePackages)
      Load EMF model based on a set of URI and root packages.
      static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(List<org.eclipse.emf.common.util.URI> modelURIs, List<org.eclipse.emf.ecore.EPackage> ePackages, IResourceSetFactory resourceSetFactory)
      Load EMF model based on a set of URI and root packages.
      static void loadResourceSet​(List<org.eclipse.emf.common.util.URI> modelURIs, org.eclipse.emf.ecore.resource.ResourceSet resourceSet)  
      static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(org.eclipse.emf.common.util.URI modelURI)
      Load EMF model based on URI.
      static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(org.eclipse.emf.common.util.URI modelURI, List<org.eclipse.emf.ecore.EPackage> ePackages)
      Load EMF model based on URI and root packages.
      static Map<String,​org.eclipse.emf.ecore.EPackage> register​(List<org.eclipse.emf.ecore.EPackage> ePackages, org.eclipse.emf.ecore.EPackage.Registry registry)
      Recursively register packages to a registry.
      static void resolveAll​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
      Resolve all referenced resources within a ResourceSet.
      static org.eclipse.emf.ecore.resource.Resource saveElement​(org.eclipse.emf.common.util.URI uri, org.eclipse.emf.ecore.EObject element)
      Save an element to a URI and return the resource.
      static void saveResourceSet​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet, Map<String,​Object> options)
      Save model based on ResourceSet.
    • Method Detail

      • loadResourceSet

        public static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(org.eclipse.emf.common.util.URI modelURI,
                                                                                 List<org.eclipse.emf.ecore.EPackage> ePackages)
                                                                          throws IOException
        Load EMF model based on URI and root packages.
        Throws:
        IOException
      • loadResourceSet

        public static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(List<org.eclipse.emf.common.util.URI> modelURIs,
                                                                                 List<org.eclipse.emf.ecore.EPackage> ePackages)
                                                                          throws IOException
        Load EMF model based on a set of URI and root packages.
        Throws:
        IOException
      • loadResourceSet

        public static void loadResourceSet​(List<org.eclipse.emf.common.util.URI> modelURIs,
                                           org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
                                    throws IOException
        Throws:
        IOException
      • loadResourceSet

        public static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(List<org.eclipse.emf.common.util.URI> modelURIs,
                                                                                 List<org.eclipse.emf.ecore.EPackage> ePackages,
                                                                                 IResourceSetFactory resourceSetFactory)
                                                                          throws IOException
        Load EMF model based on a set of URI and root packages.
        Throws:
        IOException
      • loadResourceSet

        public static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(org.eclipse.emf.common.util.URI modelURI)
                                                                          throws IOException
        Load EMF model based on URI.
        Throws:
        IOException
      • register

        public static Map<String,​org.eclipse.emf.ecore.EPackage> register​(List<org.eclipse.emf.ecore.EPackage> ePackages,
                                                                                org.eclipse.emf.ecore.EPackage.Registry registry)
        Recursively register packages to a registry.
      • loadResourceSet

        public static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(String fileName,
                                                                                 List<org.eclipse.emf.ecore.EPackage> ePackages)
                                                                          throws IOException
        Load EMF model based on file name and root packages.
        Throws:
        IOException
      • loadResourceSet

        public static org.eclipse.emf.ecore.resource.ResourceSet loadResourceSet​(String fileName)
                                                                          throws IOException
        Load EMF model based on file name (use the packages already added to the registry).
        Throws:
        IOException
      • saveResourceSet

        public static void saveResourceSet​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
                                           Map<String,​Object> options)
                                    throws IOException
        Save model based on ResourceSet.
        Throws:
        IOException
      • isPathmap

        public static boolean isPathmap​(org.eclipse.emf.common.util.URI uri)
        Determines whether this URI is a path map URI.
      • loadResource

        public static org.eclipse.emf.ecore.resource.Resource loadResource​(org.eclipse.emf.common.util.URI uri)
                                                                    throws IOException
        Load a resource based on a URI.
        Throws:
        IOException
      • loadElement

        public static <V extends org.eclipse.emf.ecore.EObject> V loadElement​(org.eclipse.emf.common.util.URI uri)
                                                                       throws IOException
        Load a resource based on a URI and return its root element.
        Throws:
        IOException
      • saveElement

        public static org.eclipse.emf.ecore.resource.Resource saveElement​(org.eclipse.emf.common.util.URI uri,
                                                                          org.eclipse.emf.ecore.EObject element)
                                                                   throws IOException
        Save an element to a URI and return the resource.
        Throws:
        IOException
      • exists

        public static boolean exists​(org.eclipse.emf.common.util.URI uri)
                              throws IOException
        Check whether a file exists for a certain URI.
        Throws:
        IOException
      • getRootElements

        public static <E extends org.eclipse.emf.ecore.EObject> List<E> getRootElements​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
                                                                                        Class<E> type)
        Get the root model elements.
      • getRootElements

        public static <E extends org.eclipse.emf.ecore.EObject> List<E> getRootElements​(org.eclipse.emf.ecore.resource.Resource resource,
                                                                                        Class<E> type)
        Get the root model elements.
      • isPlatformResource

        public static boolean isPlatformResource​(org.eclipse.emf.ecore.resource.Resource resource)
        Decide whether a resource is a platform resource.
      • resolveAll

        public static void resolveAll​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
        Resolve all referenced resources within a ResourceSet.