audiojury.action
Class ProjectManager

java.lang.Object
  |
  +--java.util.Observable
        |
        +--audiojury.action.ProjectManager
All Implemented Interfaces:
ProjectProcessing

public class ProjectManager
extends java.util.Observable
implements ProjectProcessing

Manages a collection of Projects.
The class implements the Singleton design pattern, which means there is only one instance of this class. This is necessary to make concurrent access to Projects impossible.


Method Summary
 void activateProject(java.lang.String name, java.lang.String activeName)
          Adds a snapshot tag to the Project name and then activates the Project.
 void closeProject(java.lang.String name)
          Moves a Project from active to closed state.
 Scale[] createStandardScales()
          Generates the standard Scales ACR, CCR and DCR.
 void deleteProject(java.lang.String name, int state)
          Deletes a Project permanently.
 void duplicateProject(java.lang.String name, java.lang.String newname)
          Duplicates a Project in dynamic state.
protected  ProjectBuilder getProjectBuilder()
          Gets the ProjectBuilder currently being used.
static ProjectManager getUniqueInstance()
          Enforces the Singleton design pattern by always returning the same instance of ProjectManager.
 boolean isUniqueProjectName(java.lang.String name, int state)
          Checks it a project name is unique within a specific project state domain.
 java.util.Hashtable listActiveProjects()
          Used by the client to discover available Projects.
 java.util.Hashtable listProjects(int state)
          Lists Projects.
 java.util.Hashtable listProjectsAndTests(int state)
          Lists Projects and Tests.
 Project newProject(java.lang.String name)
          Creates a new Project.
 Project openProject(java.lang.String name)
          Opens a Project that is in dynamic state.
 Project openProjectPassive(java.lang.String name)
          Open the Project in read-only mode.
 Scale[] openScales()
          Opens a Scale from a scale.conf file.
 void reactivateProject(java.lang.String name)
          Moves a Project from closed state back to active state.
 void registerObserver(java.util.Observer observer)
          Registers an observer so it can be notified when the state of the ProjectManager changes.
 void renameProject(java.lang.String name, java.lang.String newname)
          Renames a Project in dynamic state.
 void saveProject(Project proj)
          Saves a Project object to disk.
 void saveScales(Scale[] scales)
          Saves Scale objects in a stream file named scale.conf
 void setProjectStoragePlugin(ProjectStoragePlugin plugin)
          Sets sets the storage plugin to use.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setProjectStoragePlugin

public void setProjectStoragePlugin(ProjectStoragePlugin plugin)
Sets sets the storage plugin to use.

Parameters:
plugin - The desired storage plugin.

registerObserver

public void registerObserver(java.util.Observer observer)
Registers an observer so it can be notified when the state of the ProjectManager changes.

Parameters:
observer - The observer to register.

createStandardScales

public Scale[] createStandardScales()
Generates the standard Scales ACR, CCR and DCR.

Specified by:
createStandardScales in interface ProjectProcessing
Returns:
An array of standard Scales.

openScales

public Scale[] openScales()
                   throws ProjectOperationException
Opens a Scale from a scale.conf file. The Scale is located in the project base directory.

Specified by:
openScales in interface ProjectProcessing
Returns:
An array of Scales loaded from file.
Throws:
ProjectOperationException - if an unhandled error occurs.

saveScales

public void saveScales(Scale[] scales)
                throws ProjectOperationException
Saves Scale objects in a stream file named scale.conf

Specified by:
saveScales in interface ProjectProcessing
Parameters:
scales - An array of Scales.
Throws:
ProjectOperationException - if an unhandled exception occurs.

listProjectsAndTests

public java.util.Hashtable listProjectsAndTests(int state)
                                         throws ProjectOperationException
Lists Projects and Tests.

Specified by:
listProjectsAndTests in interface ProjectProcessing
Parameters:
state - List projects in this state. State identifiers are defined in Project.
Returns:
A Hashtable with project names as keys. Each entry consists of another Hashtable, listing the tests in the respective projects. The keys of this hashtable are test names and the entries are paths to tests.
Throws:
ProjectOperationException - if an unhandled exception occurs.
See Also:
audiojury.domain.Project#

listProjects

public java.util.Hashtable listProjects(int state)
                                 throws ProjectOperationException
Lists Projects.

Specified by:
listProjects in interface ProjectProcessing
Parameters:
state - List projects in this state. State identifiers are defined in Project.
Returns:
A Hashtable with project names as keys. Each entry is the path to the respective project.
Throws:
ProjectOperationException - if an unhandled exception occurs.
See Also:
audiojury.domain.Project#

listActiveProjects

public java.util.Hashtable listActiveProjects()
                                       throws ProjectOperationException
Used by the client to discover available Projects. The keys in the table are strings of project names.

Specified by:
listActiveProjects in interface ProjectProcessing
Returns:
Hashtable where the keys are project name Strings.
Throws:
ProjectOperationException - if an unhandled exception occurs.

duplicateProject

public void duplicateProject(java.lang.String name,
                             java.lang.String newname)
                      throws ProjectOperationException,
                             NotUniqueNameException
Duplicates a Project in dynamic state.

Specified by:
duplicateProject in interface ProjectProcessing
Parameters:
name - The name of the project to duplicate.
newname - The name of the copy that will be created.
Throws:
ProjectOperationException - if an unhandled exception occurs.
NotUniqueNameException - if the proposed name is not unique.

renameProject

public void renameProject(java.lang.String name,
                          java.lang.String newname)
                   throws ProjectOperationException,
                          NotUniqueNameException
Renames a Project in dynamic state.

Specified by:
renameProject in interface ProjectProcessing
Parameters:
name - The current name of the project.
newname - The new desired name of the project.
Throws:
ProjectOperationException - if an unhandled exception occurs.
NotUniqueNameException - if the proposed name is not unique.

closeProject

public void closeProject(java.lang.String name)
                  throws ProjectOperationException
Moves a Project from active to closed state.

Specified by:
closeProject in interface ProjectProcessing
Parameters:
name - The name of the project to close. The project must be in active state for the closure to be possible.
Throws:
ProjectOperationException - if an unhandled exception occurs.

reactivateProject

public void reactivateProject(java.lang.String name)
                       throws ProjectOperationException
Moves a Project from closed state back to active state.

Specified by:
reactivateProject in interface ProjectProcessing
Parameters:
name - The name of the project to reactivate.
Throws:
ProjectOperationException - if an unhandled exception occurs.

activateProject

public void activateProject(java.lang.String name,
                            java.lang.String activeName)
                     throws ProjectOperationException
Adds a snapshot tag to the Project name and then activates the Project.

Specified by:
activateProject in interface ProjectProcessing
Parameters:
name - The name of the project to activate
activeName - Not used. It exsist because this class implements the ProjectProcessing interface. Safe to set to null or "".
Throws:
ProjectOperationException - if an unhandled exception occurs.

deleteProject

public void deleteProject(java.lang.String name,
                          int state)
                   throws ProjectOperationException
Deletes a Project permanently.

Specified by:
deleteProject in interface ProjectProcessing
Parameters:
name - Name of the Project to rename.
state - In which state to look for the project.
Throws:
ProjectOperationException - if an unhandled exception occurs.

saveProject

public void saveProject(Project proj)
                 throws ProjectOperationException
Saves a Project object to disk.

Specified by:
saveProject in interface ProjectProcessing
Parameters:
proj - A Project object to save.
Throws:
ProjectOperationException - if an unhandled exception occurs.

openProject

public Project openProject(java.lang.String name)
                    throws ProjectOperationException,
                           NoProjectFoundException
Opens a Project that is in dynamic state.

Specified by:
openProject in interface ProjectProcessing
Parameters:
name - The name of the project.
Returns:
The opened Project.
Throws:
ProjectOperationException - if an unhandled exception occurs.
NoProjectFoundException - if no project could be found with the specified name.

openProjectPassive

public Project openProjectPassive(java.lang.String name)
                           throws ProjectOperationException,
                                  NoProjectFoundException
Open the Project in read-only mode. Used by the client.

Parameters:
name - The name of the project.
Returns:
The opened Project.
Throws:
ProjectOperationException - if an unhandled exception occurs.
NoProjectFoundException - if no project could be found with the specified name.

newProject

public Project newProject(java.lang.String name)
                   throws ProjectOperationException,
                          NotUniqueNameException
Creates a new Project.

Specified by:
newProject in interface ProjectProcessing
Parameters:
name - The desired name of the new Project.
Returns:
A new Project object.
Throws:
ProjectOperationException - if an unhandled exception occurs.
NotUniqueNameException - if the proposed name is not unique.

isUniqueProjectName

public boolean isUniqueProjectName(java.lang.String name,
                                   int state)
                            throws ProjectOperationException
Checks it a project name is unique within a specific project state domain.

Specified by:
isUniqueProjectName in interface ProjectProcessing
Parameters:
name - A name candidate.
state - The project state domain to check against. Project states are defined in audiojury.domain.Project
Returns:
True if the project name has not been used, and therefore is unique. False otherwise.
Throws:
ProjectOperationException - if an unhandled exception occurs.

getUniqueInstance

public static ProjectManager getUniqueInstance()
Enforces the Singleton design pattern by always returning the same instance of ProjectManager. This should be used instead of a constructor.

Returns:
A unique single ProjectManager insatance.

getProjectBuilder

protected ProjectBuilder getProjectBuilder()
Gets the ProjectBuilder currently being used.

Returns:
The current ProjectBuilder.