KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > config > TableEvents


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/config/TableEvents.java,v 1.11 2004/10/23 13:35:39 hkollmann Exp $
3  * $Revision: 1.11 $
4  * $Date: 2004/10/23 13:35:39 $
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.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 JavaDoc;
32 import java.util.HashMap JavaDoc;
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 JavaDoc{
43    private static Log logCat = LogFactory.getLog(TableEvents.class.getName());
44    private HashMap JavaDoc 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 JavaDoc();
53
54       try {
55          // set the default database events;
56
addEventInfo(EventType.EVENT_DATABASE_DELETE);
57          addEventInfo(EventType.EVENT_DATABASE_INSERT);
58          addEventInfo(EventType.EVENT_DATABASE_UPDATE);
59
60          // set the default navigation events;
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 JavaDoc e) {
70          logCat.error("::Table - cannot link a TableEvents object to this table",
71                       e);
72       }
73
74       // enable log for digester;
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 JavaDoc getEventId(String JavaDoc eventType) {
87       String JavaDoc 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 JavaDoc eventType = einfo.getType();
125
126       // store the event info object using its event type as the map key;
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 JavaDoc 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 JavaDoc eventType) throws Exception JavaDoc {
173       EventInfo einfo = new EventInfo();
174       einfo.setType(eventType);
175       einfo.setId(eventType);
176       addEventInfo(einfo);
177    }
178 }
179
Popular Tags