1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.event.eventtype.EventType;
30
31 import java.io.Serializable;
32 import java.util.HashMap;
33
34
35
36 /***
37 * Handles the events related to the linked table object.
38 *
39 * @author Luca Fossato
40 *
41 */
42 public class TableEvents implements Serializable{
43 private static Log logCat = LogFactory.getLog(TableEvents.class.getName());
44 private HashMap eventMap = null;
45 private Table table = null;
46 private boolean doLog = false;
47
48 /***
49 * Default constructor.
50 */
51 public TableEvents() {
52 eventMap = new HashMap();
53
54 try {
55
56 addEventInfo(EventType.EVENT_DATABASE_DELETE);
57 addEventInfo(EventType.EVENT_DATABASE_INSERT);
58 addEventInfo(EventType.EVENT_DATABASE_UPDATE);
59
60
61 addEventInfo(EventType.EVENT_NAVIGATION_FIRST);
62 addEventInfo(EventType.EVENT_NAVIGATION_GOTO);
63 addEventInfo(EventType.EVENT_NAVIGATION_LAST);
64 addEventInfo(EventType.EVENT_NAVIGATION_NEW);
65 addEventInfo(EventType.EVENT_NAVIGATION_COPY);
66 addEventInfo(EventType.EVENT_NAVIGATION_NEXT);
67 addEventInfo(EventType.EVENT_NAVIGATION_PREV);
68 addEventInfo(EventType.EVENT_NAVIGATION_RELOAD);
69 } catch (Exception e) {
70 logCat.error("::Table - cannot link a TableEvents object to this table",
71 e);
72 }
73
74
75 doLog = true;
76 }
77
78 /***
79 * Get the event id related to the input event type.
80 *
81 * @param eventType the event type
82 *
83 * @return the event id related to the input event type, or null if the
84 * object does not exist
85 */
86 public String getEventId(String eventType) {
87 String id = null;
88 EventInfo einfo = getEventInfo(eventType);
89
90 if (einfo != null) {
91 id = einfo.getId();
92 }
93
94 return id;
95 }
96
97
98 /***
99 * Sets the table attribute of the TableEvent object
100 *
101 * @param table The new table value
102 */
103 public void setTable(Table table) {
104 this.table = table;
105 }
106
107
108 /***
109 * Gets the table attribute of the TableEvent object
110 *
111 * @return The table value
112 */
113 public Table getTable() {
114 return table;
115 }
116
117
118 /***
119 * Set a new event for the linked Table.
120 *
121 * @param einfo the event info
122 */
123 public void addEventInfo(EventInfo einfo) {
124 String eventType = einfo.getType();
125
126
127 if (eventMap.containsKey(eventType)) {
128 eventMap.remove(eventType);
129 }
130
131 eventMap.put(eventType, einfo);
132
133 if (doLog) {
134 logCat.info("::addEventInfo - set a new eventInfo with type, id ["
135 + eventType + ", " + einfo.getId() + "]");
136 }
137 }
138
139
140 /***
141 * Get the eventInfo object related to the input event type.
142 *
143 * @param eventType the event type string
144 *
145 * @return the eventInfo object related to the input event type, or null if
146 * the object does not exist
147 */
148 private EventInfo getEventInfo(String eventType) {
149 EventInfo einfo = null;
150
151 if (eventMap.containsKey(eventType)) {
152 einfo = (EventInfo) eventMap.get(eventType);
153 }
154
155 return einfo;
156 }
157
158
159 /***
160 * PRIVATE methods here
161 *
162 * @param eventType DOCUMENT ME!
163 */
164 /***
165 * Set a new event for the linked Table
166 *
167 * @param eventType the event type string
168 *
169 * @throws Exception if the system try to register two events with the same
170 * type
171 */
172 private void addEventInfo(String eventType) throws Exception {
173 EventInfo einfo = new EventInfo();
174 einfo.setType(eventType);
175 einfo.setId(eventType);
176 addEventInfo(einfo);
177 }
178 }