## org.eclipse.emf.ecore.resource.impl
Class ResourceSetImpl

    java.lang.Object
      org.eclipse.emf.common.notify.impl.BasicNotifierImpl
          org.eclipse.emf.common.notify.impl.NotifierImpl
              org.eclipse.emf.ecore.resource.impl.ResourceSetImpl

All Implemented Interfaces:
  Notifier, ResourceSet

Direct Known Subclasses:
  AdapterFactoryEditingDomain.AdapterFactoryEditingDomainResourceSet

    public class ResourceSetImpl

extends NotifierImpl
implements ResourceSet

An extensible resource set implementation.

The following configuration and control mechanisms are provided:

- Resolve

- `delegatedGetResource(URI, boolean)`
- `getEObject(URI, boolean)`

- Demand

- `demandCreateResource(URI)`
- `demandLoad(Resource)`
- `demandLoadHelper(Resource)`

Nested Class Summary
`protected class` `ResourceSetImpl.ResourcesEList<E extends java.lang.Object & Resource>` A notifying list implementation for supporting `ResourceSet.getResources()`.

Nested classes/interfaces inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
`BasicNotifierImpl.EAdapterList<E extends java.lang.Object & Adapter>`

Field Summary
`protected EList<AdapterFactory>` `adapterFactories` The registered adapter factories.
`protected java.util.Map<java.lang.Object,java.lang.Object>` `loadOptions` The load options.
`protected EPackage.Registry` `packageRegistry` The local package registry.
`protected Resource.Factory.Registry` `resourceFactoryRegistry` The local resource factory registry.
`protected EList<Resource>` `resources` The contained resources.
`protected URIConverter` `uriConverter` The URI converter.
`protected java.util.Map<URI,Resource>` `uriResourceMap` A map to cache the resource associated with a specific URI.

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
`ResourceSetImpl()` Creates an empty instance.

Method Summary
`Resource` `createResource(URI uri)` Creates a new resource, of the appropriate type, and returns it.
`Resource` `createResource(URI uri, java.lang.String contentType)` Creates a new resource, of the appropriate type, and returns it.
`protected Resource` `delegatedGetResource(URI uri, boolean loadOnDemand)` Returns a resolved resource available outside of the resource set.
`protected Resource` `demandCreateResource(URI uri)` Creates a new resource appropriate for the URI.
`protected void` `demandLoad(Resource resource)` Loads the given resource.
`protected void` `demandLoadHelper(Resource resource)` Demand loads the given resource using `demandLoad(Resource)` and `wraps` any `IOException` as a runtime exception.
`EList<AdapterFactory>` `getAdapterFactories()` Returns the list of registered `AdapterFactory` instances.
`TreeIterator<Notifier>` `getAllContents()` Returns a tree iterator that iterates over all the `direct resources` and over the content `tree` of each.
`EObject` `getEObject(URI uri, boolean loadOnDemand)` Returns the object resolved by the URI.
`java.util.Map<java.lang.Object,java.lang.Object>` `getLoadOptions()` Returns the options used during demand load.
`EPackage.Registry` `getPackageRegistry()` Returns the registry used for looking up a package based namespace.
`Resource` `getResource(URI uri, boolean loadOnDemand)` Returns the resource resolved by the URI.
`Resource.Factory.Registry` `getResourceFactoryRegistry()` Returns the registry used for creating a resource of the appropriate type.
`EList<Resource>` `getResources()` Returns the direct `Resource`s being managed.
`URIConverter` `getURIConverter()` Returns the converter used to normalize URIs and to open streams.
`java.util.Map<URI,Resource>` `getURIResourceMap()` Returns the map used to cache the resource `associated` with a specific URI.
`protected void` `handleDemandLoadException(Resource resource, java.io.IOException exception)` Handles the exception thrown during demand load by recording it as an error diagnostic and throwing a wrapping runtime exception.
`void` `setPackageRegistry(EPackage.Registry packageRegistry)` Set the registry used for looking up a package based namespace.
`void` `setResourceFactoryRegistry(Resource.Factory.Registry resourceFactoryRegistry)` Sets the registry used for creating resource of the appropriate type.
`void` `setURIConverter(URIConverter uriConverter)` Sets the converter used to normalize URIs and to open streams.
`void` `setURIResourceMap(java.util.Map<URI,Resource> uriResourceMap)` Sets the map used to cache the resource associated with a specific URI.
`java.lang.String` `toString()` Returns a standard label with the list of resources.

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`

Field Detail

### resources

    protected EList<Resource> resources

  The contained resources.

  See Also:
    `getResources()`

### adapterFactories

    protected EList<AdapterFactory> adapterFactories

  The registered adapter factories.

  See Also:
    `getAdapterFactories()`

### loadOptions

    protected java.util.Map<java.lang.Object,java.lang.Object> loadOptions

  The load options.

  See Also:
    `getLoadOptions()`

### resourceFactoryRegistry

    protected Resource.Factory.Registry resourceFactoryRegistry

  The local resource factory registry.

  See Also:
    `getResourceFactoryRegistry()`

### uriConverter

    protected URIConverter uriConverter

  The URI converter.

  See Also:
    `getURIConverter()`

### packageRegistry

    protected EPackage.Registry packageRegistry

  The local package registry.

  See Also:
    `getPackageRegistry()`

### uriResourceMap

    protected java.util.Map<URI,Resource> uriResourceMap

  A map to cache the resource associated with a specific URI.

  See Also:
    `setURIResourceMap(Map)`

Constructor Detail

### ResourceSetImpl

    public ResourceSetImpl()

  Creates an empty instance.

Method Detail

### getURIResourceMap

    public java.util.Map<URI,Resource> getURIResourceMap()

  Returns the map used to cache the resource `associated` with a specific URI.

  Returns:
    the map used to cache the resource associated with a specific URI.
  See Also:
    `setURIResourceMap(java.util.Map<org.eclipse.emf.common.util.URI, org.eclipse.emf.ecore.resource.Resource>)`

### setURIResourceMap

    public void setURIResourceMap(java.util.Map<URI,Resource> uriResourceMap)

  Sets the map used to cache the resource associated with a specific URI. This cache is only activated if the map is not `null`. The map will be lazily loaded by the `getResource` method. It is up to the client to clear the cache when it becomes invalid, e.g., when the URI of a previously mapped resource is changed.

  Parameters:
    `uriResourceMap` - the new map or `null`.
  See Also:
    `getURIResourceMap()`

### getResources

    public EList<Resource> getResources()

  Description copied from interface: `ResourceSet`
  Returns the direct `Resource`s being managed.

  A resource added to this list will be `contained` by this resource set. If it was previously contained by a resource set, it will have been removed.

  Specified by:
    `getResources` in interface `ResourceSet`
  Returns:
    the resources.
  See Also:
    `Resource.getResourceSet()`

### getAllContents

    public TreeIterator<Notifier> getAllContents()

  Description copied from interface: `ResourceSet`
  Returns a tree iterator that iterates over all the `direct resources` and over the content `tree` of each.

  Specified by:
    `getAllContents` in interface `ResourceSet`
  Returns:
    a tree iterator that iterates over all contents.
  See Also:
    `EObject.eAllContents()`, `Resource.getAllContents()`, `EcoreUtil.getAllContents(ResourceSet, boolean)`

### getAdapterFactories

    public EList<AdapterFactory> getAdapterFactories()

  Description copied from interface: `ResourceSet`
  Returns the list of registered `AdapterFactory` instances.

  One style of adapter `lookup` supported by EMF is via registered adapter factories. Since these factories are accessible to any fully contained object via

        eObject.eResource().getResourceSet().getAdapterFactories()

  they can be used to create adapters on demand, without going to the factory first.

  Specified by:
    `getAdapterFactories` in interface `ResourceSet`
  Returns:
    the list of adapter factories.
  See Also:
    `EcoreUtil.getRegisteredAdapter(EObject, Object)`, `EcoreUtil.getRegisteredAdapter(Resource, Object)`, `AdapterFactory.adapt(Notifier, Object)`

### getLoadOptions

    public java.util.Map<java.lang.Object,java.lang.Object> getLoadOptions()

  Description copied from interface: `ResourceSet`
  Returns the options used during demand load.

  Options are handled generically as feature-to-setting entries. They are passed to the resource when it is `deserialized`. A resource will ignore options it doesn't recognize. The options could even include things like an Eclipse progress monitor...

  Specified by:
    `getLoadOptions` in interface `ResourceSet`
  Returns:
    the options used during demand load.
  See Also:
    `Resource.load(Map)`

### getEObject

    public EObject getEObject(URI uri,
                              boolean loadOnDemand)

  Description copied from interface: `ResourceSet`
  Returns the object resolved by the URI.

  Every object `contained` by a resource (or that is a `proxy`) has a `corresponding URI` that resolves to the object. So for any object contained by a resource, the following is `true`.

         eObject == eObject.eResource().getResourceSet().getEObject(EcoreUtil.getURI(eObject), false)

  The URI `without` the fragment, is used to `resolve` a resource. If the resource resolves, the `fragment` is used to `resolve` the object.

  Specified by:
    `getEObject` in interface `ResourceSet`
  Parameters:
    `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, or `null` if there isn't one.
  See Also:
    `Resource.getEObject(String)`, `ResourceSet.getResource(URI, boolean)`, `EcoreUtil.getURI(EObject)`

### demandCreateResource

    protected Resource demandCreateResource(URI uri)

  Creates a new resource appropriate for the URI. It is called by `getResource(URI, boolean)` when a URI that doesn't exist as a resource is demand loaded. This implementation simply calls `createResource(URI)`. Clients may extend this as appropriate.

  Parameters:
    `uri` - the URI of the resource to create.
  Returns:
    a new resource.
  See Also:
    `getResource(URI, boolean)`

### demandLoad

    protected void demandLoad(Resource resource)
                       throws java.io.IOException

  Loads the given resource. It is called by `demandLoadHelper(Resource)` to perform a demand load. This implementation simply calls `resource.``load`(`getLoadOptions`()). Clients may extend this as appropriate.

  Parameters:
    `resource` - a resource that isn't loaded.
  Throws:
    `java.io.IOException` - if there are serious problems loading the resource.
  See Also:
    `getResource(URI, boolean)`, `demandLoadHelper(Resource)`

### demandLoadHelper

    protected void demandLoadHelper(Resource resource)

  Demand loads the given resource using `demandLoad(Resource)` and `wraps` any `IOException` as a runtime exception. It is called by `getResource(URI, boolean)` to perform a demand load.

  Parameters:
    `resource` - a resource that isn't loaded.
  See Also:
    `demandLoad(Resource)`

### handleDemandLoadException

    protected void handleDemandLoadException(Resource resource,
                                             java.io.IOException exception)
                                      throws java.lang.RuntimeException

  Handles the exception thrown during demand load by recording it as an error diagnostic and throwing a wrapping runtime exception.

  Parameters:
    `resource` - the resource that threw an exception while loading.
    `exception` - the exception thrown from the resource while loading.
  Throws:
    `java.lang.RuntimeException`
  See Also:
    `demandLoadHelper(Resource)`

### delegatedGetResource

    protected Resource delegatedGetResource(URI uri,
                                            boolean loadOnDemand)

  Returns a resolved resource available outside of the resource set. It is called by `getResource(URI, boolean)` after it has determined that the URI cannot be resolved based on the existing contents of the resource set. This implementation looks up the URI in the {#getPackageRegistry() local} package registry. Clients may extend this as appropriate.

  Parameters:
    `uri` - the URI
    `loadOnDemand` - whether demand loading is required.

### getResource

    public Resource getResource(URI uri,
                                boolean loadOnDemand)

  Description copied from interface: `ResourceSet`
  Returns the resource resolved by the URI.

  A resource set is expected to implement the following strategy in order to resolve the given URI to a resource. First it uses it's `URI converter` to `normalize` the URI and then to compare it with the normalized URI of each resource; if it finds a match, that resource becomes the result. Failing that, it `delegates` to allow the URI to be resolved elsewhere. For example, the `package registry` is used to `resolve` the `namespace URI` of a package to the static instance of that package. So the important point is that an arbitrary implementation may resolve the URI to any resource, not necessarily to one contained by this particular resource set. If the delegation step fails to provide a result, and if `loadOnDemand` is `true`, a resource is `created` and that resource becomes the result. If `loadOnDemand` is `true` and the result resource is not `loaded`, it will be `loaded` before it is returned.

  Specified by:
    `getResource` in interface `ResourceSet`
  Parameters:
    `uri` - the URI to resolve.
    `loadOnDemand` - whether to create and load the resource, if it doesn't already exists.
  Returns:
    the resource resolved by the URI, or `null` if there isn't one and it's not being demand loaded.

### createResource

    public Resource createResource(URI uri)

  Description copied from interface: `ResourceSet`
  Creates a new resource, of the appropriate type, and returns it.

  It delegates to the resource factory `registry` to determine the `correct` factory, and then it uses that factory to `create` the resource and adds it to the `contents`. If there is no registered factory, `null` will be returned; when running within Eclipse, a default XMI factory will be registered, and this will never return `null`.

  Specified by:
    `createResource` in interface `ResourceSet`
  Parameters:
    `uri` - the URI of the resource to create.
  Returns:
    a new resource, or `null` if no factory is registered.

### createResource

    public Resource createResource(URI uri,
                                   java.lang.String contentType)

  Description copied from interface: `ResourceSet`
  Creates a new resource, of the appropriate type, and returns it.

  It delegates to the resource factory `registry` to determine the `correct` factory, and then it uses that factory to `create` the resource and adds it to the `contents`. If there is no registered factory, `null` will be returned; when running within Eclipse, a default XMI factory will be registered, and this will never return `null`.

  Specified by:
    `createResource` in interface `ResourceSet`
  Parameters:
    `uri` - the URI of the resource to create.
    `contentType` - the `content type identifier` of the URI, or `null` if no content type should be used during lookup.
  Returns:
    a new resource, or `null` if no factory is registered.

### getResourceFactoryRegistry

    public Resource.Factory.Registry getResourceFactoryRegistry()

  Description copied from interface: `ResourceSet`
  Returns the registry used for creating a resource of the appropriate type.

  An implementation will typically provide a registry that delegates to the `global` resource factory registry. As a result, registrations made in this registry are local to this resource set, i.e., they augment or override those of the global registry.

  Specified by:
    `getResourceFactoryRegistry` in interface `ResourceSet`
  Returns:
    the registry used for creating a resource of the appropriate type.

### setResourceFactoryRegistry

    public void setResourceFactoryRegistry(Resource.Factory.Registry resourceFactoryRegistry)

  Description copied from interface: `ResourceSet`
  Sets the registry used for creating resource of the appropriate type.

  Specified by:
    `setResourceFactoryRegistry` in interface `ResourceSet`
  Parameters:
    `resourceFactoryRegistry` - the new registry.

### getURIConverter

    public URIConverter getURIConverter()

  Description copied from interface: `ResourceSet`
  Returns the converter used to normalize URIs and to open streams.

  Specified by:
    `getURIConverter` in interface `ResourceSet`
  Returns:
    the URI converter.
  See Also:
    `URIConverter`, `URI`

### setURIConverter

    public void setURIConverter(URIConverter uriConverter)

  Description copied from interface: `ResourceSet`
  Sets the converter used to normalize URIs and to open streams.

  Specified by:
    `setURIConverter` in interface `ResourceSet`
  Parameters:
    `uriConverter` - the new converter.
  See Also:
    `URIConverter`, `URI`

### getPackageRegistry

    public EPackage.Registry getPackageRegistry()

  Description copied from interface: `ResourceSet`
  Returns the registry used for looking up a package based namespace.

  An implementation will typically provide a registry that delegates to the `global` package registry. As a result, registrations made in this registry are local to this resource set, i.e., they augment or override those of the global registry.

  Specified by:
    `getPackageRegistry` in interface `ResourceSet`
  Returns:
    the registry used for looking up a package based namespace.

### setPackageRegistry

    public void setPackageRegistry(EPackage.Registry packageRegistry)

  Description copied from interface: `ResourceSet`
  Set the registry used for looking up a package based namespace.

  Specified by:
    `setPackageRegistry` in interface `ResourceSet`
  Parameters:
    `packageRegistry` - the new registry.

### toString

    public java.lang.String toString()

  Returns a standard label with the list of resources.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    the string form.

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.