org.entityfs.ostrat
Interface OverwriteStrategy

All Known Implementing Classes:
AbstractOverwriteStrategy, DontOverwrite, DontOverwriteAndLogWarning, DontOverwriteAndThrowException, DoOverwrite, DoOverwriteAndLogWarning

public interface OverwriteStrategy

This interface is implemented by different strategy objects that are used for overwriting existing entities when a new entity should be created at the same location as the old.

Since:
1.1
Author:
Karl Gustafsson

Method Summary
 OverwriteResult overwrite(Directory dir, String name, EntityType typeOfNewEntity)
          If there is an existing entity in the directory with the specified name, deal with it according to the overwrite strategy.
 OverwriteResult overwrite(File dir, String name, EntityType typeOfNewEntity, LogAdapter la)
          This method does the same as the overwrite(Directory, String, EntityType) method, but it uses a File variable for the target directory.
 

Method Detail

overwrite

OverwriteResult overwrite(Directory dir,
                          String name,
                          EntityType typeOfNewEntity)
                          throws EntityFoundException,
                                 DirectoryNotEmptyException
If there is an existing entity in the directory with the specified name, deal with it according to the overwrite strategy.

If this method logs a warning, the directory's file system's log adapter should preferably be used.

Parameters:
dir - The directory. The directory must be locked for writing when this method is called.
name - The name of the entity.
typeOfNewEntity - The type of the new entity that will be created after an old entity, if there is one, is overwritten. This may be a factor in the decision to overwrite an entity, especially if both the old and the new entities are directories.
Returns:
One of three possible results:
  1. OverwriteResult.CAN_CREATE_NEW_ENTITY   a new entity can be created at the target location. This may mean that the overwrite strategy deleted an old entity
  2. OverwriteResult.CANNOT_CREATE_NEW_ENTITY   a new entity cannot be created at the target location. This means that the overwrite strategy found an entity that it was not allowed to delete.
  3. OverwriteResult.KEPT_OLD_DIRECTORY   the client wanted to create a new directory in the same place as an old directory. The overwrite strategy kept the old directory.
Throws:
EntityFoundException - If there is an entity in the target location and the strategy tells us to react by throwing an exception.
DirectoryNotEmptyException - If this method attempts to overwrite a non-empty directory.

overwrite

OverwriteResult overwrite(File dir,
                          String name,
                          EntityType typeOfNewEntity,
                          LogAdapter la)
                          throws EntityNotFoundException,
                                 NotADirectoryException,
                                 EntityFoundException,
                                 FileSystemException
This method does the same as the overwrite(Directory, String, EntityType) method, but it uses a File variable for the target directory.

Parameters:
dir - The target directory. This must exist and be a directory.
name - The name of the entity.
typeOfNewEntity - The type of the new entity that will be created after an old entity, if there is one, is overwritten. This may be a factor in the decision to overwrite an entity, especially if both the old and the new entities are directories.
la - An adapter to log to.
Returns:
One of three possible results:
  1. OverwriteResult.CAN_CREATE_NEW_ENTITY   a new entity can be created at the target location. This may mean that the overwrite strategy deleted an old entity
  2. OverwriteResult.CANNOT_CREATE_NEW_ENTITY   a new entity cannot be created at the target location. This means that the overwrite strategy found an entity that it was not allowed to delete.
  3. OverwriteResult.KEPT_OLD_DIRECTORY   the client wanted to create a new directory in the same place as an old directory. The overwrite strategy kept the old directory.
Throws:
EntityNotFoundException - If the target directory does not exist.
NotADirectoryException - If the target is not a directory.
EntityFoundException - If there is an entity in the target location and the strategy tells us to react by throwing an exception.
FileSystem - If an existing entity cannot be deleted.
FileSystemException