KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > execution > Event


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.webflow.execution;
17
18 import java.util.EventObject JavaDoc;
19
20 import org.springframework.util.Assert;
21 import org.springframework.webflow.core.collection.AttributeMap;
22 import org.springframework.webflow.core.collection.CollectionUtils;
23
24 /**
25  * Signals the occurrence of something an active flow execution should respond
26  * to. Each event has a string id that provides a key for identifying what
27  * happened: e.g "coinInserted", or "pinDropped". Events may have attributes
28  * that provide arbitrary payload data, e.g. "coin.amount=25", or
29  * "pinDropSpeed=25ms".
30  * <p>
31  * As an example, a "submit" event might signal that a Submit button was pressed
32  * in a web browser. A "success" event might signal an action executed
33  * successfully. A "finish" event might signal a subflow ended normally.
34  * <p>
35  * Why is this not an interface? A specific design choice. An event is not a
36  * strategy that defines a generic type or role--it is essentially an immutable
37  * value object. It is expected that specializations of this base class be
38  * "Events" and not part of some other inheritence hierarchy.
39  *
40  * @author Keith Donald
41  * @author Erwin Vervaet
42  * @author Colin Sampaleanu
43  */

44 public final class Event extends EventObject JavaDoc {
45
46     /**
47      * The event identifier.
48      */

49     private final String JavaDoc id;
50
51     /**
52      * The time the event occured.
53      */

54     private final long timestamp = System.currentTimeMillis();
55
56     /**
57      * Additional event attributes that form this event's payload.
58      */

59     private final AttributeMap attributes;
60
61     /**
62      * Create a new event with the specified <code>id</code> and no payload.
63      * @param source the source of the event (required)
64      * @param id the event identifier (required)
65      */

66     public Event(Object JavaDoc source, String JavaDoc id) {
67         this(source, id, null);
68     }
69
70     /**
71      * Create a new event with the specified <code>id</code> and payload
72      * attributes.
73      * @param source the source of the event (required)
74      * @param id the event identifier (required)
75      * @param attributes additional event attributes
76      */

77     public Event(Object JavaDoc source, String JavaDoc id, AttributeMap attributes) {
78         super(source);
79         Assert.hasText(id, "The event id is required: please set this event's id to a non-blank string identifier");
80         this.id = id;
81         this.attributes = (attributes != null ? attributes : CollectionUtils.EMPTY_ATTRIBUTE_MAP);
82     }
83
84     /**
85      * Returns the event identifier.
86      * @return the event id
87      */

88     public String JavaDoc getId() {
89         return id;
90     }
91
92     /**
93      * Returns the time at which the event occured, represented as the number of
94      * milliseconds since January 1, 1970, 00:00:00 GMT.
95      * @return the timestamp
96      */

97     public long getTimestamp() {
98         return timestamp;
99     }
100
101     /**
102      * Returns an unmodifiable map storing the attributes of this event. Never
103      * returns <code>null</code>.
104      * @return the event attributes (payload)
105      */

106     public AttributeMap getAttributes() {
107         return attributes;
108     }
109
110     public String JavaDoc toString() {
111         return getId();
112     }
113 }
Popular Tags