KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > event > NavEventFactoryImpl


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/NavEventFactoryImpl.java,v 1.17 2004/08/18 12:25:58 hkollmann Exp $
3  * $Revision: 1.17 $
4  * $Date: 2004/08/18 12:25:58 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 JavaDoc;
36
37
38
39 /**
40  * Implementation of a Navigation Event Factory.
41  *
42  * @author Luca Fossato
43  *
44  */

45 public class NavEventFactoryImpl extends NavEventFactory {
46    /** an handle to the unique NavigationEventFactory instance */
47    private static NavEventFactory 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 NavEventFactory 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 WebEvent createEvent(String JavaDoc action,
80                                HttpServletRequest JavaDoc request,
81                                DbFormsConfig config) {
82       Object JavaDoc[] constructorArgs = new Object JavaDoc[] {
83                                     action,
84                                     request,
85                                     config
86                                  };
87       String JavaDoc eventId = getEventIdFromDestinationTable(request, action);
88       EventInfo einfo = getEventInfo(eventId);
89
90       // debug
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 NavigationEvent createEvent(String JavaDoc action,
110                                       HttpServletRequest JavaDoc request,
111                                       DbFormsConfig config,
112                                       Table table) {
113       Object JavaDoc[] constructorArgs = new Object JavaDoc[] {
114                                     table,
115                                     request,
116                                     config
117                                  };
118       String JavaDoc eventId = getEventIdFromDestinationTable(table, action);
119       EventInfo einfo = getEventInfo(eventId);
120
121       // debug
122
logCat.info("::createEvent - got event [" + einfo + "] from action ["
123                   + action + "]");
124
125       return (NavigationEvent) 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 NavigationEvent createGotoEvent(Table table,
142                                           HttpServletRequest JavaDoc request,
143                                           DbFormsConfig config,
144                                           String JavaDoc positionString) {
145       String JavaDoc eventId = table.getTableEvents()
146                                .getEventId(EventType.EVENT_NAVIGATION_GOTO);
147       EventInfo einfo = getEventInfo(eventId);
148       Object JavaDoc[] constructorArgs = new Object JavaDoc[] {
149                                      table,
150                                      request,
151                                      config,
152                                      positionString
153                                   };
154
155       return (NavigationEvent) 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 NavigationEvent createGotoEvent(Table table,
173                                           HttpServletRequest JavaDoc request,
174                                           DbFormsConfig config,
175                                           String JavaDoc whereClause,
176                                           String JavaDoc tableList) {
177       String JavaDoc eventId = table.getTableEvents()
178                                .getEventId(EventType.EVENT_NAVIGATION_GOTO);
179       EventInfo einfo = getEventInfo(eventId);
180       Object JavaDoc[] constructorArgs = new Object JavaDoc[] {
181                                      table,
182                                      request,
183                                      config,
184                                      whereClause,
185                                      tableList
186                                   };
187
188       return (NavigationEvent) 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 JavaDoc {
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 }
218
Popular Tags