org.entityfs.ostrat
Class DontOverwrite
java.lang.Object
org.entityfs.ostrat.AbstractOverwriteStrategy
org.entityfs.ostrat.DontOverwrite
- All Implemented Interfaces:
- OverwriteStrategy
public class DontOverwrite
- extends AbstractOverwriteStrategy
This overwrite strategy will not overwrite existing entity and does not log a
warning.
The singleton instance INSTANCE
may be used instead of instantiating
this class.
- Since:
- 1.1
- Author:
- Karl Gustafsson
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
INSTANCE
public static final DontOverwrite INSTANCE
DontOverwrite
public DontOverwrite()
overwrite
public OverwriteResult overwrite(Directory dir,
String name,
EntityType typeOfNewEntity)
throws EntityFoundException,
DirectoryNotEmptyException
- Description copied from interface:
OverwriteStrategy
- 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:
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 -
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. -
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
public OverwriteResult overwrite(File dir,
String name,
EntityType typeOfNewEntity,
LogAdapter la)
throws FileSystemException
- Description copied from interface:
OverwriteStrategy
- This method does the same as the
OverwriteStrategy.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:
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
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.
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.
FileSystemException