Show AsynchronousLocalPersister.java syntax highlighted
package persister.local;
import java.sql.Timestamp;
import java.util.List;
import javax.swing.event.EventListenerList;
import persister.AsynchronousPersister;
import persister.Backlog;
import persister.ConnectionFailedException;
import persister.CouldNotLoadProjectException;
import persister.ForbiddenOperationException;
import persister.IndexCardNotFoundException;
import persister.Iteration;
import persister.NotConnectedException;
import persister.PlannerDataChangeListener;
import persister.Project;
import persister.StoryCard;
public class AsynchronousLocalPersister implements AsynchronousPersister {
private EventListenerList plannerDataChangeListeners;
private PersisterToXML synPer;
public AsynchronousLocalPersister(String localProjectDirPath, String defaultFilename) throws ConnectionFailedException, CouldNotLoadProjectException {
this.plannerDataChangeListeners = new EventListenerList();
synPer = new PersisterToXML(localProjectDirPath, defaultFilename);
}
public synchronized void load(String projectName) throws CouldNotLoadProjectException {
this.fireCreatedProjectEvent(synPer.load(projectName));
}
public synchronized void load(String projectName, Timestamp start,
Timestamp end) throws CouldNotLoadProjectException {
this.fireCreatedProjectEvent(synPer.load(projectName, start, end));
}
public synchronized void getProjectNames() {
this.fireGotProjectNamesEvent(synPer.getProjectNames());
}
/***************************************************************************
* CREATE *
**************************************************************************/
public synchronized void createBacklog(int width, int height,
int locationX, int locationY) throws ForbiddenOperationException {
this.fireCreatedBacklogEvent(synPer.createBacklog(width, height,
locationX, locationY));
}
public synchronized void createIteration(String name, String description,
int width, int height, int locationX, int locationY,
float availableEffort, Timestamp startDate, Timestamp endDate) {
this.fireCreatedIterationEvent(synPer.createIteration(name,
description, width, height, locationX, locationY,
availableEffort, startDate, endDate));
}
public synchronized void createProject(String name)
throws ForbiddenOperationException {
this.fireCreatedProjectEvent(synPer.createProject(name));
}
public synchronized void createStoryCard(String name, String description,
int width, int height, int locationX, int locationY, long parentid,
float bestCaseEstimate, float mostlikelyEstimate,
float worstCaseEstimate, float actualEffort, String str)
throws IndexCardNotFoundException {
this.fireCreatedStoryCardEvent(synPer.createStoryCard(name,
description, width, height, locationX, locationY, parentid,
bestCaseEstimate, mostlikelyEstimate, worstCaseEstimate,
actualEffort, str));
}
/***************************************************************************
* DELETE *
**************************************************************************/
public synchronized void deleteBacklog(long id)
throws ForbiddenOperationException {
throw new ForbiddenOperationException(
"You cannot delete the Backlog without deleting the Project!");
}
public synchronized void deleteIteration(long id)
throws IndexCardNotFoundException {
Iteration i = null;
try {
i = (Iteration)synPer.deleteCard(id);
this.fireDeletedIterationEvent(i);
} catch (ForbiddenOperationException e) {
throw new IndexCardNotFoundException("Card with id="+id+" is not an Iteration");
}
}
public synchronized void deleteStoryCard(long id) throws IndexCardNotFoundException
{
StoryCard sc;
try {
sc = (StoryCard) synPer.deleteCard(id);
this.fireDeletedStoryCardEvent(sc);
} catch (ForbiddenOperationException e) {
throw new IndexCardNotFoundException("Card with id="+id+" is not a StoryCard");
}
}
/***************************************************************************
* UPDATE BACKLOG *
**************************************************************************/
public synchronized void updateBacklog(Backlog backlog)
throws IndexCardNotFoundException {
//Backlog backlog = this.ffin
this.fireUpdatedBacklogEvent((Backlog)synPer.updateCard(backlog));
}
/***************************************************************************
* UPDATE ITERATION *
**************************************************************************/
public synchronized void updateIteration(Iteration iteration) throws IndexCardNotFoundException {
this.fireUpdatedIterationEvent((Iteration)synPer.updateCard(iteration));
}
/***************************************************************************
* UPDATE STORYCARD *
**************************************************************************/
public synchronized void updateStoryCard(StoryCard sc) throws IndexCardNotFoundException {
this.fireUpdatedStoryCardEvent((StoryCard)synPer.updateCard(sc));
}
/***************************************************************************
* MOVE STORYCARD BETWEEN PARENTS *
**************************************************************************/
public synchronized void moveStoryCardToNewParent(StoryCard sc, long newparentid, int locationX, int locationY)
throws IndexCardNotFoundException {
this.fireMovedStoryCardToNewParentEvent(synPer
.moveStoryCardToNewParent(sc.getId(), sc.getParent(), newparentid,
locationX, locationY));
}
/***************************************************************************
* UPDATE PROJECT *
**************************************************************************/
// public synchronized void updateProjectName(long id, String name)
// throws IndexCardNotFoundException {
//
// }
/***************************************************************************
* LISTENER *
**************************************************************************/
public synchronized void addPlannerDataChangeListener(
PlannerDataChangeListener listener) {
this.plannerDataChangeListeners.add(PlannerDataChangeListener.class,
listener);
}
public synchronized void removePlannerDataChangeListener(
PlannerDataChangeListener listener) {
this.plannerDataChangeListeners.remove(PlannerDataChangeListener.class,
listener);
}
private void fireCreatedBacklogEvent(Backlog backlog) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.createdBacklog(backlog);
}
}
}
private void fireCreatedIterationEvent(Iteration iteration) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.createdIteration(iteration);
}
}
}
private void fireCreatedProjectEvent(Project project) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.createdProject(project);
}
}
}
private void fireCreatedStoryCardEvent(StoryCard storycard) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.createdStoryCard(storycard);
}
}
}
private void fireDeletedIterationEvent(Iteration iteration) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.deletedIteration(iteration.getId());
}
}
}
// private void fireDeletedProjectEvent(Project project) {
// Object[] listeners = plannerDataChangeListeners.getListenerList();
// // loop through each listener and pass on the event if needed
// int numListeners = listeners.length;
// for (int i = 0; i < numListeners; i += 2) {
// if (listeners[i] == PlannerDataChangeListener.class) {
// // pass the event to the listeners event dispatch method
// ((PlannerDataChangeListener) listeners[i + 1])
// .deletedProject(project);
// }
// }
// }
private void fireDeletedStoryCardEvent(StoryCard storycard) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.deletedStoryCard(storycard.getId());
}
}
}
private void fireMovedStoryCardToNewParentEvent(StoryCard storycard) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.movedStoryCardToNewParent(storycard);
}
}
}
private void fireUndeletedIterationEvent(Iteration iteration) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.undeletedIteration(iteration);
}
}
}
// private void fireUndeletedProjectEvent(Project project) {
// Object[] listeners = plannerDataChangeListeners.getListenerList();
// // loop through each listener and pass on the event if needed
// int numListeners = listeners.length;
// for (int i = 0; i < numListeners; i += 2) {
// if (listeners[i] == PlannerDataChangeListener.class) {
// // pass the event to the listeners event dispatch method
// ((PlannerDataChangeListener) listeners[i + 1])
// .undeletedProject(project);
// }
// }
// }
private void fireUndeletedStorycCardEvent(StoryCard storycard) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.undeletedStoryCard(storycard);
}
}
}
private void fireUpdatedBacklogEvent(Backlog backlog) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.updatedBacklog(backlog);
}
}
}
private void fireUpdatedIterationEvent(Iteration iteration) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.updatedIteration(iteration);
}
}
}
private void fireUpdatedStoryCardEvent(StoryCard storycard) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.updatedStoryCard(storycard);
}
}
}
private void fireGotProjectNamesEvent(List<String> projects) {
Object[] listeners = plannerDataChangeListeners.getListenerList();
// loop through each listener and pass on the event if needed
int numListeners = listeners.length;
for (int i = 0; i < numListeners; i += 2) {
if (listeners[i] == PlannerDataChangeListener.class) {
// pass the event to the listeners event dispatch method
((PlannerDataChangeListener) listeners[i + 1])
.gotProjectNames(projects);
}
}
}
public void getProjectAsXML() throws NotConnectedException {
// TODO Auto-generated method stub
}
public void undeleteBacklog(Backlog backlog) throws NotConnectedException,
ForbiddenOperationException {
// TODO Auto-generated method stub
}
public void undeleteIteration(Iteration iteration) {
try {
this.fireUndeletedIterationEvent((Iteration)synPer.undeleteCard(iteration));
} catch (ForbiddenOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void undeleteProject(Project project) throws NotConnectedException,
ForbiddenOperationException {
// TODO Auto-generated method stub
}
public void undeleteStoryCard(StoryCard sc) throws NotConnectedException,
IndexCardNotFoundException, ForbiddenOperationException {
this.fireUndeletedStorycCardEvent((StoryCard)synPer.undeleteCard(sc));
}
public void connect() {
//reload the current project to ensure that all clients are informed about it
Project p = synPer.getProject();
fireCreatedProjectEvent(p);
}
public boolean connected() {
// TODO Auto-generated method stub
return false;
}
public PersisterToXML getSynPer() {
return synPer;
}
public void setSynPer(PersisterToXML synPer) {
this.synPer = synPer;
}
}
See more files for this project here