## org.eclipse.emf.workspace.util
Class WorkspaceSynchronizer

    java.lang.Object
      org.eclipse.emf.workspace.util.WorkspaceSynchronizer

    public final class WorkspaceSynchronizer

extends Object

A utility object that listens to workspace resource changes to synchronize the state of an EMF resource set with the workspace.

The default behaviour on workspace resource deletions is to unload the corresponding EMF resource. The default behaviour on resource changes is to unload and reload the corresponding EMF resource, unless the resource path has changed (by move or rename), in which case it is simply unloaded.

To customize the behaviour of the synchronizer, initialize it with a `delegate` that provides the required behaviour. For example, it might be more user-friendly to prompt the user before taking drastic measures.

Whether implemented by a delegate or not, the synchronization algorithm is invoked asynchronously (as a job) and in a read-only transaction on the synchronizer's editing domain. This ensures timely completion of the workspace's event dispatching and exclusive access to the resource set according to the transaction protocol. Also, the job is scheduled on the workspace rule, so that the delegate call-backs are free to read or modify any resources that they may need.

Nested Class Summary
`static interface` `WorkspaceSynchronizer.Delegate` Call-back interface for an object to which a `WorkspaceSynchronizer` delegates the algorithms for handling different kinds of resource changes.

Constructor Summary
`WorkspaceSynchronizer(TransactionalEditingDomain domain)` Initializes me with the editing domain for which I synchronize resources, using the default change-handling behaviour.
`WorkspaceSynchronizer(TransactionalEditingDomain domain, WorkspaceSynchronizer.Delegate delegate)` Initializes me with the editing domain for which I synchronize resources, using the specified delegate to handle resource changes.

Method Summary
`void` `dispose()` Disposes me, in particular disconnecting me from the workspace so that I no longer respond to resource change events.
`TransactionalEditingDomain` `getEditingDomain()` Queries the editing domain whose resources I synchronize with the workspace.
`static IFile` `getFile(Resource resource)` Obtains the workspace file corresponding to the specified resource, if it has a platform-resource URI.
`static IFile` `getUnderlyingFile(Resource resource)` Obtains the workspace file underlying the specified resource.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### WorkspaceSynchronizer

    public WorkspaceSynchronizer(TransactionalEditingDomain domain)

  Initializes me with the editing domain for which I synchronize resources, using the default change-handling behaviour.

  I immediately start listening for workspace resource changes.

  Parameters:
    `domain` - my domain (must not be `null`)

### WorkspaceSynchronizer

    public WorkspaceSynchronizer(TransactionalEditingDomain domain,
                                 WorkspaceSynchronizer.Delegate delegate)

  Initializes me with the editing domain for which I synchronize resources, using the specified delegate to handle resource changes.

  I immediately start listening for workspace resource changes.

  Parameters:
    `domain` - my domain (must not be `null`)
    `delegate` - the delegate that handles my resource changes, or `null` to get the default behaviour

Method Detail

### getEditingDomain

    public TransactionalEditingDomain getEditingDomain()

  Queries the editing domain whose resources I synchronize with the workspace.

  Returns:
    my editing domain

### dispose

    public void dispose()

  Disposes me, in particular disconnecting me from the workspace so that I no longer respond to resource change events.

### getFile

    public static IFile getFile(Resource resource)

  Obtains the workspace file corresponding to the specified resource, if it has a platform-resource URI. Note that the resulting file, if not `null`, may nonetheless not actually exist (as the file is just a handle).

  Note that, if the `resource` is in an archive (such as a ZIP file) then it does not map to a workspace file. In this case, however, the workspace file (if any) corresponding to the containing archive can be obtained via the `getUnderlyingFile(Resource)` method.

  Parameters:
    `resource` - an EMF resource
  Returns:
    the corresponding workspace file, or `null` if the resource's URI is not a platform-resource URI
  See Also:
    `getUnderlyingFile(Resource)`

### getUnderlyingFile

    public static IFile getUnderlyingFile(Resource resource)

  Obtains the workspace file underlying the specified resource. If the resource has an `archive` scheme, the authority is considered instead. If the URI has a file scheme, it's looked up in the workspace, just as in the `getFile(Resource)` method. Otherwise, a platform scheme is assumed.

  Note that the resulting file, if not `null`, may nonetheless not actually exist (as the file is just a handle).

  Parameters:
    `resource` - an EMF resource
  Returns:
    the underlying workspace file, or `null` if the resource's URI is not a platform-resource URI
  Since:
    1.2
  See Also:
    `getFile(Resource)`

Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved.