org.eclipse.emf.henshin.model.resource
Class HenshinResourceSet

java.lang.Object
  extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
      extended by org.eclipse.emf.common.notify.impl.NotifierImpl
          extended by org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
              extended by org.eclipse.emf.henshin.model.resource.HenshinResourceSet
All Implemented Interfaces:
Notifier, ResourceSet
Direct Known Subclasses:
StateSpaceResourceSet

public class HenshinResourceSet
extends ResourceSetImpl

Resource set implementation for Henshin. Provides some convenience methods for easy use and supports automatic resolving of relative file URIs using a base directory.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
ResourceSetImpl.MappedResourceLocator, ResourceSetImpl.ResourceLocator, ResourceSetImpl.ResourcesEList<E extends Object & Resource>
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
BasicNotifierImpl.EAdapterList<E extends Object & Adapter>, BasicNotifierImpl.EObservableAdapterList
 
Field Summary
 
Fields inherited from class org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
adapterFactories, loadOptions, packageRegistry, resourceFactoryRegistry, resourceLocator, resources, uriConverter, uriResourceMap
 
Fields inherited from class org.eclipse.emf.common.notify.impl.NotifierImpl
eAdapters, EDELIVER, eFlags, ELAST_NOTIFIER_FLAG
 
Fields inherited from interface org.eclipse.emf.ecore.resource.ResourceSet
RESOURCE_SET__RESOURCES
 
Constructor Summary
HenshinResourceSet()
          Constructor without base directory.
HenshinResourceSet(String baseDir)
          Constructor which sets the base directory for this resource set.
 
Method Summary
 Resource createResource(String path)
          Create a resource for a given path.
 URI getBaseDir()
          Get the base directory for this resource set as a file URI.
 EObject getEObject(String path)
          Load a resource for the given file name and get the first EObject contained in it.
 Module getModule(String path)
          Load a Module from a Henshin file given as a path and file name.
 Module getModule(String path, boolean fixImports)
          Load a Module from a Henshin file given as a path and file name.
 Module getModule(URI uri, boolean fixImports)
           Load a Module from a Henshin file given by a URI.
 Resource getResource(String path)
          Load a resource for the given (relative) path and file name.
 boolean initPackageImplementation(String packageClassName)
          Try to initialize a generated package implementation.
 List<EPackage> registerDynamicEPackages(String ecorePath)
          Load EPackages from an Ecore file and register them in the local package registry.
 void registerXMIResourceFactories(String... fileExtensions)
          Register XMIResourceFactoryImpls for the given file extensions.
 void saveEObject(EObject object, String path)
          Save an EObject at a given path.
 void saveEObject(EObject object, URI uri)
          Save an EObject at a given URI.
 
Methods inherited from class org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
createResource, createResource, delegatedGetResource, demandCreateResource, demandLoad, demandLoadHelper, getAdapterFactories, getAllContents, getEObject, getLoadOptions, getPackageRegistry, getResource, getResourceFactoryRegistry, getResources, getURIConverter, getURIResourceMap, handleDemandLoadException, setPackageRegistry, setResourceFactoryRegistry, setURIConverter, setURIResourceMap, toString
 
Methods inherited from class org.eclipse.emf.common.notify.impl.NotifierImpl
eAdapters, eBasicAdapters, eDeliver, eSetDeliver
 
Methods inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
eBasicAdapterArray, eBasicHasAdapters, eNotificationRequired, eNotify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.common.notify.Notifier
eAdapters, eDeliver, eNotify, eSetDeliver
 

Constructor Detail

HenshinResourceSet

public HenshinResourceSet(String baseDir)
Constructor which sets the base directory for this resource set.

Parameters:
baseDir - Base directory (can be also null).

HenshinResourceSet

public HenshinResourceSet()
Constructor without base directory.

Method Detail

getBaseDir

public URI getBaseDir()
Get the base directory for this resource set as a file URI.

Returns:
The base directory as a file URI or null.

registerXMIResourceFactories

public void registerXMIResourceFactories(String... fileExtensions)
Register XMIResourceFactoryImpls for the given file extensions. The factories are registered in the scope of this resource set. The resource factories are registered only if no other resource factory is already registered for the file extension.

Parameters:
fileExtension - File extensions.

registerDynamicEPackages

public List<EPackage> registerDynamicEPackages(String ecorePath)
Load EPackages from an Ecore file and register them in the local package registry.

Parameters:
ecorePath - The relative path to an Ecore file.
Returns:
List of loaded and registered EPackages.

initPackageImplementation

public boolean initPackageImplementation(String packageClassName)
Try to initialize a generated package implementation. Note that this has a global effect (not limited to this resource set).

Parameters:
packageClassName - Class name of the (interface) of a package implementation.
Returns:
true if the package was successfully initialized.

getResource

public Resource getResource(String path)
Load a resource for the given (relative) path and file name. If the path is relative, it will be resolved using the base directory of this resource set.

Parameters:
path - Possible relative model path.
Returns:
The loaded resource.

createResource

public Resource createResource(String path)
Create a resource for a given path.

Parameters:
path - Possible relative model path.
Returns:
The created resource.
See Also:
getResource(String), ResourceSetImpl.createResource(URI)

getEObject

public EObject getEObject(String path)
Load a resource for the given file name and get the first EObject contained in it. If the path is relative, it will be resolved using the base directory of this resource set.

Parameters:
path - Possible relative path and file name.
Returns:
The first contained object.

getModule

public Module getModule(String path,
                        boolean fixImports)
Load a Module from a Henshin file given as a path and file name. If the path is relative, it will be resolved using the base directory of this resource set. The behavior is as in getModule(URI, boolean).

Parameters:
path - Possibly relative path to a Henshin file.
fixImports - If true, tries to fix the imports of the loaded module (default is false).
Returns:
The contained Module.
See Also:
getModule(URI, boolean)

getModule

public Module getModule(URI uri,
                        boolean fixImports)

Load a Module from a Henshin file given by a URI.

If fixImports is set to true, the method will try to fix broken imports of the module. Specifically, it will check for every imported package of the module, if a another package with the same namespace URI is registered in the local package registry of this resource. If yes, all references to elements of this package in the module will be replaced by the found package.

If you want to fix the imports, you should first load the instance models to be transformed, and then call this method.

Parameters:
path - Possible relative path and file name of a Henshin resource.
fixImports - If true, tries to fix the imports of the loaded module (default is false).
Returns:
The contained Module.

getModule

public Module getModule(String path)
Load a Module from a Henshin file given as a path and file name. If the path is relative, it will be resolved using the base directory of this resource set. This does not fix imports.

Parameters:
path - Possibly relative path to a Henshin file.
Returns:
The contained Module.
See Also:
getModule(String, boolean)

saveEObject

public void saveEObject(EObject object,
                        String path)
Save an EObject at a given path. This creates a new resource under the given path, adds the object to the resource and saves it. This delegates to saveEObject(EObject, URI).

Parameters:
object - EObject to be saved.
path - Possibly relative file path.

saveEObject

public void saveEObject(EObject object,
                        URI uri)
Save an EObject at a given URI. This creates a new resource under the given path, adds the object to the resource and saves it.

Parameters:
object - EObject to be saved.
uri - URI pointing to the file where the object should be saved.