KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > audit > SessionEvent


1 /**
2  * $RCSfile: SessionEvent.java,v $
3  * $Revision: 1.2 $
4  * $Date: 2004/10/21 06:30:10 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.audit;
13
14 import org.jivesoftware.messenger.Session;
15 import java.util.Date JavaDoc;
16
17 /**
18  * Events that occur during the session life cycle are repreented
19  * by SessionEvents.
20  *
21  * @author Iain Shigeoka
22  */

23 public class SessionEvent extends AuditEvent {
24
25     /**
26      * Session events use the code 1
27      */

28     public static final int SESSION_CODE = 1;
29
30     // Session reasons
31
public static final int SESSION_CONNECT = 1;
32     public static final int SESSION_STREAM = 2;
33     public static final int SESSION_AUTH_FAILURE = 3;
34     public static final int SESSION_AUTH_SUCCESS = 4;
35     public static final int SESSION_DISCONNECT = 10;
36
37     /**
38      * Session events can only be created using static factory methods.
39      *
40      * @param eventSession the session that this event is recording.
41      * @param eventReason the reason the event is called.
42      * @param data the data to associate with the event.
43      */

44     private SessionEvent(Session eventSession, int eventReason, String JavaDoc data) {
45         super(eventSession, new Date JavaDoc(), SESSION_CODE, eventReason, data);
46     }
47
48     /**
49      * Create an event associated with the initial connection
50      * of a session before the stream is created.
51      *
52      * @param session the session that was connected.
53      * @return an event representing the connection event.
54      */

55     public static SessionEvent createConnectEvent(Session session) {
56         return new SessionEvent(session, SESSION_CONNECT, null);
57     }
58
59     /**
60      * Create an event associated with the establishment of an XMPP session.
61      * A connect event that is not followed by a stream event indicates
62      * the connection was rejected.
63      *
64      * @param session the session that began streaming.
65      * @return an event representing the connection event.
66      */

67     public static SessionEvent createStreamEvent(Session session) {
68         return new SessionEvent(session, SESSION_STREAM, null);
69     }
70
71     /**
72      * Create an event associated with the failure of a session to authenticate.
73      *
74      * @param session the session that made the attempt
75      * @return an event representing the connection event
76      */

77     public static SessionEvent createAuthFailureEvent(Session session, String JavaDoc user,
78             String JavaDoc resource)
79     {
80         return new SessionEvent(session, SESSION_AUTH_FAILURE,
81                 "User: " + user + " Resource: " + resource);
82     }
83
84     /**
85      * Create an event associated with a successful authentication.
86      *
87      * @param session the session that authenticated.
88      * @return an event representing the connection event.
89      */

90     public static SessionEvent createAuthSuccessEvent(Session session) {
91         return new SessionEvent(session, SESSION_AUTH_SUCCESS, null);
92     }
93
94     /**
95      * Create an event associated with the closing of a session.
96      *
97      * @param session the session that was disconnected.
98      * @return an event representing the connection event.
99      */

100     public static SessionEvent createDisconnectEvent(Session session) {
101         return new SessionEvent(session, SESSION_DISCONNECT, null);
102     }
103     
104 }
Popular Tags