1
2
3
4
5
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
23
24
25
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
39
40
41 public void setPicManDatabase(DatabaseFacade pmdb) {
42 this.dbf = pmdb;
43 this.dbf.setPicManCommonFacade(this);
44
45 }
46
47
48
49
50 public void addSyncToLog(SyncLogEntry sle) {
51 syncLog.addFirst(sle);
52 }
53
54
55
56
57 public LinkedList<SyncLogEntry> getSyncLog() {
58 return(syncLog);
59 }
60
61
62
63
64
65 public int getSyncLogMaxCount() {
66 return(10);
67 }
68
69
70
71
72 public void addError(Throwable t) {
73 errorLog.add(t);
74 }
75
76
77
78
79 public List<Throwable> getErrorLog() {
80 return(errorLog);
81 }
82
83
84
85
86 public void emptyErrorLog() {
87 errorLog.clear();
88 }
89
90
91
92
93 public Throwable getError(int index) {
94 return(errorLog.get(index));
95 }
96
97
98
99
100 @Override
101 public void addSetChangedListener(SetChangedListener setChangedListener) {
102 this.setChangedListeners.add(setChangedListener);
103 }
104
105
106
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
119
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 }