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.event;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.DbFormsConfig;
30 import org.dbforms.config.EventInfo;
31 import org.dbforms.config.Table;
32
33 import org.dbforms.event.eventtype.EventType;
34
35 import javax.servlet.http.HttpServletRequest;
36
37
38
39 /***
40 * Implementation of a Navigation Event Factory.
41 *
42 * @author Luca Fossato
43 *
44 */
45 public class NavEventFactoryImpl extends AbstractNavEventFactory {
46 /*** an handle to the unique NavigationEventFactory instance */
47 private static AbstractNavEventFactory instance = null;
48 private static Log logCat = LogFactory.getLog(NavEventFactoryImpl.class);
49
50 /***
51 * Default constructor.
52 */
53 public NavEventFactoryImpl() {
54 }
55
56 /***
57 * Get the instance of the NavEventFactoryImpl class.
58 *
59 * @return the instance of NavEventFactoryImpl class.
60 */
61 public static synchronized AbstractNavEventFactory instance() {
62 if (instance == null) {
63 instance = new NavEventFactoryImpl();
64 }
65
66 return instance;
67 }
68
69
70 /***
71 * create and return a new navigation event
72 *
73 * @param action the action string that identifies the web event
74 * @param request the HttpServletRequest object
75 * @param config the DbForms config object
76 *
77 * @return a new navigation event
78 */
79 public AbstractWebEvent createEvent(String action,
80 HttpServletRequest request,
81 DbFormsConfig config) {
82 Object[] constructorArgs = new Object[] {
83 action,
84 request,
85 config
86 };
87 String eventId = getEventIdFromDestinationTable(request, action);
88 EventInfo einfo = getEventInfo(eventId);
89
90
91 logCat.info("::createEvent - got event [" + einfo + "] from action ["
92 + action + "]");
93
94 return getEvent(einfo, constructorArgsTypes, constructorArgs);
95 }
96
97
98 /***
99 * create and return a new navigation event. Called from local web event in
100 * DbForms!
101 *
102 * @param action the action string that identifies the web event
103 * @param request DOCUMENT ME!
104 * @param config the DbForms config object
105 * @param table the Table object
106 *
107 * @return a new navigation event
108 */
109 public AbstractNavigationEvent createEvent(String action,
110 HttpServletRequest request,
111 DbFormsConfig config,
112 Table table) {
113 Object[] constructorArgs = new Object[] {
114 table,
115 request,
116 config
117 };
118 String eventId = getEventIdFromDestinationTable(table, action);
119 EventInfo einfo = getEventInfo(eventId);
120
121
122 logCat.info("::createEvent - got event [" + einfo + "] from action ["
123 + action + "]");
124
125 return (AbstractNavigationEvent) getEvent(einfo, actionConstructorArgsTypes,
126 constructorArgs);
127 }
128
129
130 /***
131 * Create and return a new navGoto event. Used by the view (DbFormTag) to
132 * create a gotoEvent
133 *
134 * @param table the Table object
135 * @param request DOCUMENT ME!
136 * @param config DOCUMENT ME!
137 * @param positionString the position string object
138 *
139 * @return a new navGoto event
140 */
141 public AbstractNavigationEvent createGotoEvent(Table table,
142 HttpServletRequest request,
143 DbFormsConfig config,
144 String positionString) {
145 String eventId = table.getTableEvents()
146 .getEventId(EventType.EVENT_NAVIGATION_GOTO);
147 EventInfo einfo = getEventInfo(eventId);
148 Object[] constructorArgs = new Object[] {
149 table,
150 request,
151 config,
152 positionString
153 };
154
155 return (AbstractNavigationEvent) getEvent(einfo, goToConstructorArgsTypes,
156 constructorArgs);
157 }
158
159
160 /***
161 * Create and return a new navGoto event. Used by the view (DbFormTag) to
162 * create a gotoEvent for free form select
163 *
164 * @param table the Table object
165 * @param request the position string object
166 * @param config DOCUMENT ME!
167 * @param whereClause DOCUMENT ME!
168 * @param tableList DOCUMENT ME!
169 *
170 * @return a new navGoto event
171 */
172 public AbstractNavigationEvent createGotoEvent(Table table,
173 HttpServletRequest request,
174 DbFormsConfig config,
175 String whereClause,
176 String tableList) {
177 String eventId = table.getTableEvents()
178 .getEventId(EventType.EVENT_NAVIGATION_GOTO);
179 EventInfo einfo = getEventInfo(eventId);
180 Object[] constructorArgs = new Object[] {
181 table,
182 request,
183 config,
184 whereClause,
185 tableList
186 };
187
188 return (AbstractNavigationEvent) getEvent(einfo, goToConstructorArgsTypes2,
189 constructorArgs);
190 }
191
192
193 /***
194 * Initialize the default events.
195 *
196 * @exception Exception if any error occurs
197 */
198 protected void initializeEvents() throws Exception {
199 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_NEW,
200 "org.dbforms.event.NavNewEvent"));
201 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_COPY,
202 "org.dbforms.event.NavCopyEvent"));
203 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_GOTO,
204 "org.dbforms.event.datalist.GotoEvent"));
205 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_FIRST,
206 "org.dbforms.event.datalist.NavFirstEvent"));
207 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_LAST,
208 "org.dbforms.event.datalist.NavLastEvent"));
209 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_NEXT,
210 "org.dbforms.event.datalist.NavNextEvent"));
211 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_PREV,
212 "org.dbforms.event.datalist.NavPrevEvent"));
213
214 addEventInfo(new EventInfo(EventType.EVENT_NAVIGATION_RELOAD,
215 "org.dbforms.event.datalist.ReloadEvent"));
216 }
217 }