TPTP 4.3.0 Testing Tools Project
Public API Specification

org.eclipse.hyades.test.core.util
Class EMFUtil

java.lang.Object
  extended byorg.eclipse.hyades.test.core.util.EMFUtil

public class EMFUtil
extends java.lang.Object

Contains generic utility methods to work with EMF objects.

Since:
0.2.0

Field Summary
static java.util.Map RESOURCE_OPTIONS
           
 
Constructor Summary
EMFUtil()
           
 
Method Summary
static void addAdapter(java.util.Iterator objectIterator, org.eclipse.emf.common.notify.Adapter adapter)
          Adds the specified adapter to the notifiers in the given iterator.
static org.eclipse.emf.ecore.EObject getEObject(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.emf.ecore.EObject eObject, boolean load)
          Returns an EObject from the resource set that has the same URI fragment or id of the specifie eObject.
static org.eclipse.emf.ecore.EObject getEObject(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.emf.common.util.URI uri, boolean loadOnDemand)
          Returns the object resolved by the URI.
static org.eclipse.emf.ecore.EObject getEObjectInResourceSet(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.resource.ResourceSet rs)
           
static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.core.resources.IFile file)
          Returns the EObjects in the specified file from the Resource Set without loading it.
static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.core.resources.IFile file, boolean loadOnDemand)
          Returns the EObjects in the specified file from the Resource Set.
static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs, java.lang.String fullPath)
          Returns the EObjects in the specified file paht from the Resource Set without loading it.
static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs, java.lang.String fullPath, boolean loadOnDemand)
          Returns the EObjects in the specified file paht from the Resource Set.
static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.common.util.URI fileURI, boolean load)
          Returns the EObjects in the resource specified by the fileUIR.
static java.lang.String getFilePath(org.eclipse.emf.ecore.EObject eObject)
          Returns file path for EObject or empty string if not found
static java.lang.String getFilePath(org.eclipse.emf.ecore.resource.Resource resource)
          Returns file path for resource or empty string if not found
static org.eclipse.emf.common.util.URI getObjectURI(java.lang.Object object)
          Returns the complete EMF URI which includes the resource information.
static org.eclipse.core.resources.IContainer getParent(org.eclipse.emf.ecore.resource.Resource resource)
           
static org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.emf.ecore.EObject object)
          Returns the resource which contains (at the first level) the given object.
static org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.core.resources.IFile file)
          Returns a resource without loading it.
static org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.emf.common.util.URI uri, boolean load)
           
static org.eclipse.emf.ecore.resource.Resource.Factory getResourceFactory(java.lang.String fileExtension)
          Returns the resource factory associated with a given file extension.
static org.eclipse.emf.ecore.resource.ResourceSet getResourceSet()
           
static org.eclipse.core.resources.IFile getWorkspaceFile(org.eclipse.emf.ecore.EObject eObject)
          Returns the workspace file that is storing a given eObject or null if the object is not persisted.
static org.eclipse.core.resources.IFile getWorkspaceFile(org.eclipse.emf.ecore.resource.Resource resource)
          Returns the workspace file that corresponds to a given resource or null if the resource is not available in the workspace.
static org.eclipse.core.resources.IFile getWorkspaceFile(org.eclipse.emf.common.util.URI uri)
           
static java.lang.String getWorkspaceFilePath(org.eclipse.emf.ecore.resource.Resource resource)
           
static org.eclipse.emf.ecore.EObject[] load(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.core.resources.IFile file)
          Loads the specified file returning all the root EObjects.
static org.eclipse.emf.ecore.EObject[] load(org.eclipse.emf.ecore.resource.ResourceSet rs, java.lang.String fullPath)
          Loads the specified file returning all the root EObjects.
static org.eclipse.emf.ecore.EObject[] load(org.eclipse.emf.ecore.resource.ResourceSet rs, org.eclipse.emf.common.util.URI uri)
          Loads the specified file returning all the root EObjects.
static org.eclipse.emf.ecore.EObject reload(org.eclipse.emf.ecore.EObject eObject)
          Reloads a given eObject returning a new instance from the same resource.
static org.eclipse.emf.ecore.resource.Resource[] remove(org.eclipse.emf.ecore.EObject eObject)
          Removes the specified eObject from its container and breaks all the references to this object within the context of its resource set.
static org.eclipse.emf.ecore.resource.Resource[] remove(org.eclipse.emf.ecore.resource.Resource resource)
          Removes the specified resource from its resource set and breaks all the references to objects inside this resource within the context of the resource set.
static void removeAdapter(java.util.Iterator objectIterator, org.eclipse.emf.common.notify.Adapter adapter)
          Removes the specified adapter from the notifiers in the given iterator.
static void removeAdapters(java.util.Iterator objectIterator)
          Removes all adapters from the notifiers in the given iterator.
static void removeAdapters(java.util.Iterator objectIterator, org.eclipse.emf.common.notify.Adapter adapter)
          Removes a specific adapter from the notifiers in the given iterator.
static void save(org.eclipse.emf.ecore.resource.Resource resource)
          Saves a resource.
static void unloadIfNeeded(org.eclipse.emf.common.util.URI uri)
          Unload a resource using its URI from the test navigator resource set if this resource is not one we are currently saving This method is used in the updateContent of the resource change updater of the test navigator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_OPTIONS

public static final java.util.Map RESOURCE_OPTIONS
Constructor Detail

EMFUtil

public EMFUtil()
Method Detail

save

public static void save(org.eclipse.emf.ecore.resource.Resource resource)
                 throws java.lang.Exception
Saves a resource.

Parameters:
resource -
Throws:
java.lang.IllegalArgumentException - if the resource is null
java.lang.Exception - if an exception happens during the saving attempt.

unloadIfNeeded

public static void unloadIfNeeded(org.eclipse.emf.common.util.URI uri)
Unload a resource using its URI from the test navigator resource set if this resource is not one we are currently saving This method is used in the updateContent of the resource change updater of the test navigator

Parameters:
uri - the URI of the resource to unload

getEObject

public static org.eclipse.emf.ecore.EObject getEObject(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                       org.eclipse.emf.ecore.EObject eObject,
                                                       boolean load)
Returns an EObject from the resource set that has the same URI fragment or id of the specifie eObject. If the eObject is not in the resource set or can't be loaded, this method returns null. If the resource set is null the default (internal) one is used.

Parameters:
eObject -
load -
Returns:
EObject

getEObjects

public static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                          org.eclipse.core.resources.IFile file)
Returns the EObjects in the specified file from the Resource Set without loading it.

If the file is null or if the file is not loaded into it, this method returns an empty array.

Parameters:
file -
Returns:
EObject[]

getEObjects

public static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                          org.eclipse.core.resources.IFile file,
                                                          boolean loadOnDemand)
Returns the EObjects in the specified file from the Resource Set.

If the file is null or if the file is not loaded and loadOnDemand is false, this method returns an empty array.

Parameters:
file -
loadOnDemand -
Returns:
EObject[]

getEObjects

public static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                          java.lang.String fullPath)
Returns the EObjects in the specified file paht from the Resource Set without loading it.

If the resource set is null or if the file is not loaded into it, this method returns an empty array.

Returns:
EObject[]

getEObjects

public static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                          java.lang.String fullPath,
                                                          boolean loadOnDemand)
Returns the EObjects in the specified file paht from the Resource Set.

If the resource set is null or if the file is not loaded into it and loadOnDemand is false, this method returns an empty array.

Returns:
EObject[]

getEObjects

public static org.eclipse.emf.ecore.EObject[] getEObjects(org.eclipse.emf.common.util.URI fileURI,
                                                          boolean load)
Returns the EObjects in the resource specified by the fileUIR.

Parameters:
fileURI -
load -
Returns:

load

public static org.eclipse.emf.ecore.EObject[] load(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                   org.eclipse.core.resources.IFile file)
Loads the specified file returning all the root EObjects. If the resource set argument is null the default one is used.

If the load attempt fails this method adds an entry to the log and returns an empty array.

Parameters:
file -
Returns:
EObject[]

load

public static org.eclipse.emf.ecore.EObject[] load(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                   java.lang.String fullPath)
Loads the specified file returning all the root EObjects. If the resource set argument is null the default one is used.

If the load attempt fails this method adds an entry to the log and returns an empty array.

Parameters:
fullPath -
Returns:
EObject[]

load

public static org.eclipse.emf.ecore.EObject[] load(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                   org.eclipse.emf.common.util.URI uri)
Loads the specified file returning all the root EObjects. If the resource set argument is null the default one is used.

If the load attempt fails this method adds an entry to the log and returns an empty array.

Returns:
EObject[]

getResourceFactory

public static org.eclipse.emf.ecore.resource.Resource.Factory getResourceFactory(java.lang.String fileExtension)
Returns the resource factory associated with a given file extension. If the file extension is null or if there isn't a specifc factory for the file extension, the this method returns the generic factory.

Parameters:
fileExtension -
Returns:
the Resource.Factory or null if none.

getWorkspaceFile

public static org.eclipse.core.resources.IFile getWorkspaceFile(org.eclipse.emf.ecore.EObject eObject)
Returns the workspace file that is storing a given eObject or null if the object is not persisted.

Parameters:
eObject -
Returns:
IFile

getWorkspaceFile

public static org.eclipse.core.resources.IFile getWorkspaceFile(org.eclipse.emf.common.util.URI uri)

getWorkspaceFile

public static org.eclipse.core.resources.IFile getWorkspaceFile(org.eclipse.emf.ecore.resource.Resource resource)
Returns the workspace file that corresponds to a given resource or null if the resource is not available in the workspace.

Parameters:
resource -
Returns:
IFile

getParent

public static org.eclipse.core.resources.IContainer getParent(org.eclipse.emf.ecore.resource.Resource resource)

getFilePath

public static java.lang.String getFilePath(org.eclipse.emf.ecore.resource.Resource resource)
Returns file path for resource or empty string if not found

Returns:
String file path

getFilePath

public static java.lang.String getFilePath(org.eclipse.emf.ecore.EObject eObject)
Returns file path for EObject or empty string if not found

Parameters:
eObject -
Returns:
String file path

getWorkspaceFilePath

public static java.lang.String getWorkspaceFilePath(org.eclipse.emf.ecore.resource.Resource resource)

getResource

public static org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                                  org.eclipse.core.resources.IFile file)
Returns a resource without loading it. If the resource is null, a new resource is created if a resource factory is available for the file extension.

Parameters:
file -
Returns:
Resource

getResource

public static org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                                  org.eclipse.emf.common.util.URI uri,
                                                                  boolean load)

reload

public static org.eclipse.emf.ecore.EObject reload(org.eclipse.emf.ecore.EObject eObject)
Reloads a given eObject returning a new instance from the same resource.

This method unloads and reloads the entire eObject's resource and tries to find the object in the new resource content.

Important: after reloading the resource all the objects in that resource are reinstantiated. This has a big impact if an object is being cached somewhere.

Parameters:
eObject -
Returns:
the reloaded eObject

remove

public static org.eclipse.emf.ecore.resource.Resource[] remove(org.eclipse.emf.ecore.EObject eObject)
Removes the specified eObject from its container and breaks all the references to this object within the context of its resource set.

Parameters:
eObject -
Returns:
the changed resources including the eObject's resource.

remove

public static org.eclipse.emf.ecore.resource.Resource[] remove(org.eclipse.emf.ecore.resource.Resource resource)
Removes the specified resource from its resource set and breaks all the references to objects inside this resource within the context of the resource set.

Parameters:
resource -
Returns:
the changed resources excluding the specified resource.

addAdapter

public static void addAdapter(java.util.Iterator objectIterator,
                              org.eclipse.emf.common.notify.Adapter adapter)
Adds the specified adapter to the notifiers in the given iterator.

Parameters:
objectIterator -
adapter -

removeAdapter

public static void removeAdapter(java.util.Iterator objectIterator,
                                 org.eclipse.emf.common.notify.Adapter adapter)
Removes the specified adapter from the notifiers in the given iterator.

Parameters:
objectIterator -
adapter -

removeAdapters

public static void removeAdapters(java.util.Iterator objectIterator)
Removes all adapters from the notifiers in the given iterator.

Parameters:
objectIterator -

removeAdapters

public static void removeAdapters(java.util.Iterator objectIterator,
                                  org.eclipse.emf.common.notify.Adapter adapter)
Removes a specific adapter from the notifiers in the given iterator.

Parameters:
objectIterator -

getResourceSet

public static org.eclipse.emf.ecore.resource.ResourceSet getResourceSet()
Returns:
the resource set cached in this class

getResource

public static org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                                  org.eclipse.emf.ecore.EObject object)
Returns the resource which contains (at the first level) the given object.

Parameters:
rs - resource set used to search in or null if cached one has to be used.
object - the EMF element we are loking for its resource
Returns:
the resource which contains the looked for object

getEObjectInResourceSet

public static org.eclipse.emf.ecore.EObject getEObjectInResourceSet(org.eclipse.emf.ecore.EObject object,
                                                                    org.eclipse.emf.ecore.resource.ResourceSet rs)

getEObject

public static org.eclipse.emf.ecore.EObject getEObject(org.eclipse.emf.ecore.resource.ResourceSet rs,
                                                       org.eclipse.emf.common.util.URI uri,
                                                       boolean loadOnDemand)
Returns the object resolved by the URI.

Parameters:
rs - resource set used to search in or null if cached one has to be used.
uri - the URI to resolve.
loadOnDemand - whether to create and load the resource, if it doesn't already exists.
Returns:
the object resolved by the URI.
See Also:
ResourceSet.getEObject(org.eclipse.emf.common.util.URI, boolean)

getObjectURI

public static org.eclipse.emf.common.util.URI getObjectURI(java.lang.Object object)
Returns the complete EMF URI which includes the resource information.

Parameters:
object -
Returns:
the uri of the given object

TPTP 4.3.0 Testing Tools Project
Public API Specification