View Javadoc
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  public class PicManCommonImpl implements PicManCommonFacade {
28  	private final Log log = LogFactory.getLog(getClass());
29  
30  	protected	DatabaseFacade	dbf;
31  	
32  	private	LinkedList<Throwable>		errorLog = new LinkedList<Throwable>();
33  	private	LinkedList<SyncLogEntry>	syncLog = new LinkedList<SyncLogEntry>();
34  
35  	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  		this.dbf = pmdb;
43  		this.dbf.setPicManCommonFacade(this);
44  		//this.dbf.setDEBUG(this.databaseDEBUG);
45  	}
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  		syncLog.addFirst(sle);
52  	}
53  
54  	/* (non-Javadoc)
55  	 * @see com.buckosoft.PicMan.business.PicManFacade#getSyncLog()
56  	 */
57  	public LinkedList<SyncLogEntry> getSyncLog() {
58  		return(syncLog);
59  	}
60  
61  	
62  	/* (non-Javadoc)
63  	 * @see com.buckosoft.PicMan.business.common.PicManCommonFacade#getSyncLogMaxCount()
64  	 */
65  	public int getSyncLogMaxCount() {
66  		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  		errorLog.add(t);
74  	}
75  
76  	/* (non-Javadoc)
77  	 * @see com.buckosoft.PicMan.business.PicManFacade#getErrorLog()
78  	 */
79  	public	List<Throwable>	getErrorLog() {
80  		return(errorLog);
81  	}
82  
83  	/* (non-Javadoc)
84  	 * @see com.buckosoft.PicMan.business.PicManFacade#emptyErrorLog()
85  	 */
86  	public void	emptyErrorLog() {
87  		errorLog.clear();
88  	}
89  
90  	/* (non-Javadoc)
91  	 * @see com.buckosoft.PicMan.business.PicManFacade#getError(int)
92  	 */
93  	public Throwable getError(int index) {
94  		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 		this.setChangedListeners.add(setChangedListener);
103 	}
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 		ListIterator<SetChangedListener> iter = this.setChangedListeners.listIterator();
111 		while (iter.hasNext()) {
112 			SetChangedListener scl = iter.next();
113 			if (scl == setChangedListener)
114 				iter.remove();
115 		}
116 	}
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 		log.info("fireSetSizeChanged: " + setSize.getSetSize());
124 		for (SetChangedListener scl : this.setChangedListeners) {
125 			if (setSize.getSize() == 0)
126 				this.dbf.updateSetTimestamp(setSize.getSetName());
127 			else
128 				this.dbf.updateSetTimestamp(setSize.getSetSize());
129 			scl.onSetChanged(setSize);
130 		}
131 	}
132 
133 	
134 }