ccc.commands
Class Command<T>

java.lang.Object
  extended by ccc.commands.Command<T>
Type Parameters:
T - The result type of the command.
Direct Known Subclasses:
ApplyWorkingCopyCommand, CreateCommentCommand, DeleteCommentCommand, DeleteResourceCommand, RenameResourceCommand, UpdateAliasCommand, UpdateCachingCommand, UpdateCommentCommand, UpdateCurrentUserCommand, UpdateFileCommand, UpdateFolderCommand, UpdatePageCommand, UpdateResourceAclCommand, UpdateTemplateCommand, UpdateUserCommand

public abstract class Command<T>
extends java.lang.Object

Provides the basic contract for command execution.

Author:
Civic Computing Ltd.

Constructor Summary
Command(IRepositoryFactory repoFactory)
          Constructor.
Command(ResourceRepository repository, LogEntryRepository audit, UserRepository userRepo, DataRepository data)
          Constructor.
 
Method Summary
protected  void afterExecute(UserEntity actor, java.util.Date happenedOn, T result)
          Event handler that executes after the command has executed successfully.
protected  void authorize(UserEntity actor)
          Confirm that the actor may execute this command.
protected  void beforeExecute(UserEntity actor, java.util.Date happenedOn)
          Event handler that executes before the command has executed.
protected abstract  T doExecute(UserEntity actor, java.util.Date happenedOn)
          Execute the command.
 T execute(UserEntity actor, java.util.Date happenedOn)
          Execute the command.
protected  LogEntryRepository getAudit()
          Accessor.
protected  CommentRepository getComments()
          Accessor.
 DataRepository getData()
          Accessor.
protected  GroupRepository getGroups()
          Accessor.
protected  ResourceRepository getRepository()
          Accessor.
protected abstract  CommandType getType()
          Get the type of this command.
 UserRepository getUsers()
          Accessor.
protected  void validate()
          Validate the command's inputs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

public Command(ResourceRepository repository,
               LogEntryRepository audit,
               UserRepository userRepo,
               DataRepository data)
Constructor.

Parameters:
repository - The ResourceDao used for CRUD operations, etc.
audit - The audit logger, for logging business actions.
userRepo - The repository for users.
data - The data repository for storing binary data.

Command

public Command(IRepositoryFactory repoFactory)
Constructor.

Parameters:
repoFactory - The repository factory for this command.
Method Detail

execute

public final T execute(UserEntity actor,
                       java.util.Date happenedOn)
Execute the command.

Parameters:
actor - The user who performed the command.
happenedOn - When the command was performed.
Returns:
The result of the command, of type T.

validate

protected void validate()
Validate the command's inputs.


authorize

protected void authorize(UserEntity actor)
Confirm that the actor may execute this command.

The default implementation allows any actor to execute the command.

Parameters:
actor - The actor performing the command.

afterExecute

protected void afterExecute(UserEntity actor,
                            java.util.Date happenedOn,
                            T result)
Event handler that executes after the command has executed successfully.

Parameters:
actor - The user who performed the command.
happenedOn - When the command was performed.
result - The result of command execution.

beforeExecute

protected void beforeExecute(UserEntity actor,
                             java.util.Date happenedOn)
Event handler that executes before the command has executed.

Parameters:
actor - The user who performed the command.
happenedOn - When the command was performed.

getRepository

protected ResourceRepository getRepository()
Accessor.

Returns:
Returns the resource repository.

getAudit

protected LogEntryRepository getAudit()
Accessor.

Returns:
Returns the audit log.

getUsers

public UserRepository getUsers()
Accessor.

Returns:
Returns the user repository.

getData

public DataRepository getData()
Accessor.

Returns:
Returns the data repository.

getGroups

protected GroupRepository getGroups()
Accessor.

Returns:
Returns the groups repository.

getComments

protected CommentRepository getComments()
Accessor.

Returns:
Return the comments repository.

doExecute

protected abstract T doExecute(UserEntity actor,
                               java.util.Date happenedOn)
Execute the command.

Parameters:
actor - The user who performed the command.
happenedOn - When the command was performed.
Returns:
The result of the command, of type T.

getType

protected abstract CommandType getType()
Get the type of this command.

Returns:
The type as an enum.


Copyright © 2010. All Rights Reserved.