| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PicManCommonImpl |
|
| 1.3636363636363635;1.364 |
| 1 | /****************************************************************************** | |
| 2 | * PicManCommonImpl.java - Implement the Business Interface common to the PicMan apps. | |
| 3 | * | |
| 4 | * PicMan - The BuckoSoft Picture Manager in Java | |
| 5 | * Copyright(c) 2008 - Dick Balaska | |
| 6 | * | |
| 7 | */ | |
| 8 | package com.buckosoft.PicMan.business.common; | |
| 9 | ||
| 10 | import java.util.LinkedList; | |
| 11 | import java.util.List; | |
| 12 | import java.util.ListIterator; | |
| 13 | ||
| 14 | import org.apache.commons.logging.Log; | |
| 15 | import org.apache.commons.logging.LogFactory; | |
| 16 | ||
| 17 | import com.buckosoft.PicMan.business.SetChangedListener; | |
| 18 | import com.buckosoft.PicMan.db.DatabaseFacade; | |
| 19 | import com.buckosoft.PicMan.domain.SetSize; | |
| 20 | import com.buckosoft.PicMan.domain.SyncLogEntry; | |
| 21 | ||
| 22 | /** Implement the Business Interface common to the PicMan apps. | |
| 23 | * @author Dick Balaska | |
| 24 | * @since 2008/11/22 | |
| 25 | * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicManService/src/com/buckosoft/PicMan/business/common/PicManCommonImpl.java">PicManCommonImpl.java</a> | |
| 26 | */ | |
| 27 | 0 | public class PicManCommonImpl implements PicManCommonFacade { |
| 28 | 0 | private final Log log = LogFactory.getLog(getClass()); |
| 29 | ||
| 30 | protected DatabaseFacade dbf; | |
| 31 | ||
| 32 | 0 | private LinkedList<Throwable> errorLog = new LinkedList<Throwable>(); |
| 33 | 0 | private LinkedList<SyncLogEntry> syncLog = new LinkedList<SyncLogEntry>(); |
| 34 | ||
| 35 | 0 | private LinkedList<SetChangedListener> setChangedListeners = new LinkedList<SetChangedListener>(); |
| 36 | ||
| 37 | ||
| 38 | /** AOP Injector to set the Database | |
| 39 | * @param pmdb A reference to the database | |
| 40 | */ | |
| 41 | public void setPicManDatabase(DatabaseFacade pmdb) { | |
| 42 | 0 | this.dbf = pmdb; |
| 43 | 0 | this.dbf.setPicManCommonFacade(this); |
| 44 | //this.dbf.setDEBUG(this.databaseDEBUG); | |
| 45 | 0 | } |
| 46 | ||
| 47 | /* (non-Javadoc) | |
| 48 | * @see com.buckosoft.PicMan.business.PicManFacade#addSyncToLog(com.buckosoft.PicMan.domain.SyncLogEntry) | |
| 49 | */ | |
| 50 | public void addSyncToLog(SyncLogEntry sle) { | |
| 51 | 0 | syncLog.addFirst(sle); |
| 52 | 0 | } |
| 53 | ||
| 54 | /* (non-Javadoc) | |
| 55 | * @see com.buckosoft.PicMan.business.PicManFacade#getSyncLog() | |
| 56 | */ | |
| 57 | public LinkedList<SyncLogEntry> getSyncLog() { | |
| 58 | 0 | return(syncLog); |
| 59 | } | |
| 60 | ||
| 61 | ||
| 62 | /* (non-Javadoc) | |
| 63 | * @see com.buckosoft.PicMan.business.common.PicManCommonFacade#getSyncLogMaxCount() | |
| 64 | */ | |
| 65 | public int getSyncLogMaxCount() { | |
| 66 | 0 | return(10); |
| 67 | } | |
| 68 | ||
| 69 | /* (non-Javadoc) | |
| 70 | * @see com.buckosoft.PicMan.business.PicManFacade#addError(java.lang.Exception) | |
| 71 | */ | |
| 72 | public void addError(Throwable t) { | |
| 73 | 0 | errorLog.add(t); |
| 74 | 0 | } |
| 75 | ||
| 76 | /* (non-Javadoc) | |
| 77 | * @see com.buckosoft.PicMan.business.PicManFacade#getErrorLog() | |
| 78 | */ | |
| 79 | public List<Throwable> getErrorLog() { | |
| 80 | 0 | return(errorLog); |
| 81 | } | |
| 82 | ||
| 83 | /* (non-Javadoc) | |
| 84 | * @see com.buckosoft.PicMan.business.PicManFacade#emptyErrorLog() | |
| 85 | */ | |
| 86 | public void emptyErrorLog() { | |
| 87 | 0 | errorLog.clear(); |
| 88 | 0 | } |
| 89 | ||
| 90 | /* (non-Javadoc) | |
| 91 | * @see com.buckosoft.PicMan.business.PicManFacade#getError(int) | |
| 92 | */ | |
| 93 | public Throwable getError(int index) { | |
| 94 | 0 | return(errorLog.get(index)); |
| 95 | } | |
| 96 | ||
| 97 | /* (non-Javadoc) | |
| 98 | * @see com.buckosoft.PicMan.business.PicManFacade#addSetChangedListener(com.buckosoft.PicMan.business.SetChangedListener) | |
| 99 | */ | |
| 100 | @Override | |
| 101 | public void addSetChangedListener(SetChangedListener setChangedListener) { | |
| 102 | 0 | this.setChangedListeners.add(setChangedListener); |
| 103 | 0 | } |
| 104 | ||
| 105 | /* (non-Javadoc) | |
| 106 | * @see com.buckosoft.PicMan.business.PicManFacade#removeSetChangedListener(com.buckosoft.PicMan.business.SetChangedListener) | |
| 107 | */ | |
| 108 | @Override | |
| 109 | public void removeSetChangedListener(SetChangedListener setChangedListener) { | |
| 110 | 0 | ListIterator<SetChangedListener> iter = this.setChangedListeners.listIterator(); |
| 111 | 0 | while (iter.hasNext()) { |
| 112 | 0 | SetChangedListener scl = iter.next(); |
| 113 | 0 | if (scl == setChangedListener) |
| 114 | 0 | iter.remove(); |
| 115 | 0 | } |
| 116 | 0 | } |
| 117 | ||
| 118 | /* (non-Javadoc) | |
| 119 | * @see com.buckosoft.PicMan.business.PicManFacade#fireSetSizeChanged(com.buckosoft.PicMan.domain.SetSize) | |
| 120 | */ | |
| 121 | @Override | |
| 122 | public void fireSetSizeChanged(SetSize setSize) { | |
| 123 | 0 | log.info("fireSetSizeChanged: " + setSize.getSetSize()); |
| 124 | 0 | for (SetChangedListener scl : this.setChangedListeners) { |
| 125 | 0 | if (setSize.getSize() == 0) |
| 126 | 0 | this.dbf.updateSetTimestamp(setSize.getSetName()); |
| 127 | else | |
| 128 | 0 | this.dbf.updateSetTimestamp(setSize.getSetSize()); |
| 129 | 0 | scl.onSetChanged(setSize); |
| 130 | 0 | } |
| 131 | 0 | } |
| 132 | ||
| 133 | ||
| 134 | } |