KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > main > CmsEvent


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/main/CmsEvent.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.main;
33
34 import java.util.Map JavaDoc;
35
36 /**
37  * Event class for OpenCms for system wide events that are thrown by various
38  * operations (e.g. publishing) and can be catched and processed by
39  * classes that implement the {@link I_CmsEventListener} interface.<p>
40  *
41  * @author Alexander Kandzior
42  *
43  * @version $Revision: 1.12 $
44  *
45  * @since 6.0.0
46  *
47  * @see I_CmsEventListener
48  */

49 public class CmsEvent {
50
51     /** The event data associated with this event. */
52     private Map JavaDoc m_data;
53
54     /** The event type this instance represents. */
55     private Integer JavaDoc m_type;
56
57     /**
58      * Construct a new CmsEvent with the specified parameters.<p>
59      *
60      * The event data <code>Map</code> provides a facility to
61      * pass objects with the event that contain information about
62      * the event environment. For example, if the event is of type
63      * {@link I_CmsEventListener#EVENT_LOGIN_USER} the Map contains
64      * a single object with the key <code>"data"</code> and a value
65      * that is the OpenCms user object that represents the user that just logged in.<p>
66      *
67      * @param type event type
68      * @param data event data
69      *
70      * @see I_CmsEventListener
71      */

72     public CmsEvent(int type, Map JavaDoc data) {
73
74         m_type = new Integer JavaDoc(type);
75         m_data = data;
76     }
77
78     /**
79      * @see java.lang.Object#equals(java.lang.Object)
80      */

81     public boolean equals(Object JavaDoc obj) {
82
83         if (obj == this) {
84             return true;
85         }
86         if (obj instanceof CmsEvent) {
87             return m_type.equals(((CmsEvent)obj).getTypeInteger());
88         }
89         return false;
90     }
91
92     /**
93      * Provides access to the event data that was passed with this event.<p>
94      *
95      * @return the event data of this event
96      */

97     public Map JavaDoc getData() {
98
99         return m_data;
100     }
101
102     /**
103      * Provides access to the event type that was passed with this event.<p>
104      *
105      * Event types of the core OpenCms classes are defined in {@link I_CmsEventListener}.
106      * For your extensions, you should define them in a central class
107      * or interface as public member variables. Make sure the integer values
108      * do not confict with the values from the core classes.<p>
109      *
110      * @return the event type of this event
111      *
112      * @see I_CmsEventListener
113      */

114     public int getType() {
115
116         return m_type.intValue();
117     }
118
119     /**
120      * Provides access to the event type as Integer.<p>
121      *
122      * @return the event type of this event as Integer
123      */

124     public Integer JavaDoc getTypeInteger() {
125
126         return m_type;
127     }
128
129     /**
130      * @see java.lang.Object#hashCode()
131      */

132     public int hashCode() {
133
134         return m_type.hashCode();
135     }
136
137     /**
138      * Return a String representation of this CmsEvent.<p>
139      *
140      * @return a String representation of this event
141      */

142     public String JavaDoc toString() {
143
144         return "CmsEvent['" + m_type + "']";
145     }
146 }
Popular Tags