Eclipse Platform
Release 3.4

org.eclipse.team.core.mapping
Class DelegatingStorageMerger

java.lang.Object
  extended byorg.eclipse.team.core.mapping.DelegatingStorageMerger
All Implemented Interfaces:
IStorageMerger

public class DelegatingStorageMerger
extends Object
implements IStorageMerger

This storage merger delegates to the appropriate merger or returns a conflict if no merger is available or if a merge was not possible.

The target storage is used to look for an appropriate merger. If the target is an IFile, the content type of the file is used. Otherwise, the IContentTypeManager is used to find an appropriate content type. If an appropriate merger is not found, a status containing the CONFLICT is returned.

Clients may use this class directly or subclass it.

Since:
3.4

Field Summary
 
Fields inherited from interface org.eclipse.team.core.mapping.IStorageMerger
CONFLICT, INTERNAL_ERROR, OK, UNSUPPORTED_ENCODING
 
Constructor Summary
DelegatingStorageMerger()
          Default no-arg constructor.
 
Method Summary
 boolean canMergeWithoutAncestor()
          Return whether this merger can merge the two contributors without an ancestor.
protected  IStorageMerger createDelegateMerger(IStorage target)
          Create a merger for the given storage or return null if an appropriate merger could not be created.
static IStorageMerger createTextMerger()
          Return the storage merger associated with the IContentTypeManager.CT_TEXT content type.
static IContentType getContentType(IStorage target)
          A helper method that finds the content type for the given storage or returns null if a content type cannot be found.
static String getExtension(String name)
          Helper method for returning the extension of a file name
static IStorageMerger getInstance()
          Helper method that returns a singleton instance that can be used to merge two IStorage instances.
protected  int getType(IStorage target)
          Return the Team content type associated with the given target.
 IStatus merge(OutputStream output, String outputEncoding, IStorage ancestor, IStorage target, IStorage other, IProgressMonitor monitor)
          Performs a merge operation on the given storage instances and writes the merge result to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingStorageMerger

public DelegatingStorageMerger()
Default no-arg constructor.

Method Detail

createTextMerger

public static IStorageMerger createTextMerger()
Return the storage merger associated with the IContentTypeManager.CT_TEXT content type.

Returns:
the storage merger associated with the IContentTypeManager.CT_TEXT content type

getInstance

public static IStorageMerger getInstance()
Helper method that returns a singleton instance that can be used to merge two IStorage instances.

Returns:
a storage merger that delegates the merge based on the type of the target storage.

merge

public IStatus merge(OutputStream output,
                     String outputEncoding,
                     IStorage ancestor,
                     IStorage target,
                     IStorage other,
                     IProgressMonitor monitor)
              throws CoreException
Description copied from interface: IStorageMerger
Performs a merge operation on the given storage instances and writes the merge result to the output stream. On success a status IStatus.OK is returned, on error a status IStatus.ERROR. If the merge operation cannot deal with conflicts, the code of the error status has the value IStreamMerger.CONFLICT. For text oriented mergers the encoding for the input and output is honored if they implement IEncodedStorage. It is the responsibility of callers to close the output stream.

The provided ancestor may be null if this merger returns true from IStorageMerger.canMergeWithoutAncestor().

Specified by:
merge in interface IStorageMerger
Parameters:
output - the byte stream to which the merge result is written; the merger will not close the stream
outputEncoding - the encoding to use when writing to the output stream
ancestor - the storage from which the common ancestor is read
target - the storage containing the target of the merge
other - the storage containing the target of the merge
monitor - reports progress of the merge operation
Returns:
returns the completion status of the operation
Throws:
CoreException - if an error occurs

createDelegateMerger

protected IStorageMerger createDelegateMerger(IStorage target)
                                       throws CoreException
Create a merger for the given storage or return null if an appropriate merger could not be created. This method is called by merge(OutputStream, String, IStorage, IStorage, IStorage, IProgressMonitor) to create the merger to which the merge should be delegated.

Parameters:
target - the storage that contains the target contents of the merge.
Returns:
a merger for the given storage or null
Throws:
CoreException

getType

protected int getType(IStorage target)
Return the Team content type associated with the given target.

Parameters:
target - the storage that contains the target contents for the merge.
Returns:
the Team content type associated with the given target
See Also:
Team.getFileContentManager(), IFileContentManager.getType(IStorage)

getExtension

public static String getExtension(String name)
Helper method for returning the extension of a file name

Parameters:
name - the file name
Returns:
the extension of the file name or null if the file name does not have an extension

getContentType

public static IContentType getContentType(IStorage target)
                                   throws CoreException
A helper method that finds the content type for the given storage or returns null if a content type cannot be found. Any exceptions that occur when trying to determine the content type are propagated.

Parameters:
target - the storage that contains the target contents of the merge.
Returns:
the content type of the storage or null
Throws:
CoreException - if an exception occurs

canMergeWithoutAncestor

public boolean canMergeWithoutAncestor()
Description copied from interface: IStorageMerger
Return whether this merger can merge the two contributors without an ancestor. This is typically not possible but may be for some file types (for instances, files that contain a timestamp based list of events).

Specified by:
canMergeWithoutAncestor in interface IStorageMerger
Returns:
whether this merger can merge the two contributors without an ancestor

Eclipse Platform
Release 3.4

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.