1 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 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 51 public TableEvents() { 52 eventMap = new HashMap (); 53 54 try { 55 addEventInfo(EventType.EVENT_DATABASE_DELETE); 57 addEventInfo(EventType.EVENT_DATABASE_INSERT); 58 addEventInfo(EventType.EVENT_DATABASE_UPDATE); 59 60 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 doLog = true; 76 } 77 78 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 103 public void setTable(Table table) { 104 this.table = table; 105 } 106 107 108 113 public Table getTable() { 114 return table; 115 } 116 117 118 123 public void addEventInfo(EventInfo einfo) { 124 String eventType = einfo.getType(); 125 126 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 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 164 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 } 179 | Popular Tags |