KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > event > ConnectionEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)ConnectionEvent.java 1.8 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.event;
29
30 import java.util.*;
31 import javax.mail.*;
32
33 /**
34  * This class models Connection events.
35  *
36  * @author John Mani
37  */

38
39 public class ConnectionEvent extends MailEvent JavaDoc {
40
41     /** A connection was opened. */
42     public static final int OPENED = 1;
43     /** A connection was disconnected (not currently used). */
44     public static final int DISCONNECTED = 2;
45     /** A connection was closed. */
46     public static final int CLOSED = 3;
47
48     /**
49      * The event type.
50      *
51      * @serial
52      */

53     protected int type;
54
55     private static final long serialVersionUID = -1855480171284792957L;
56
57     /**
58      * Constructor
59      * @param source The source object
60      */

61     public ConnectionEvent(Object JavaDoc source, int type) {
62     super(source);
63     this.type = type;
64     }
65
66     /**
67      * Return the type of this event
68      * @return type
69      */

70     public int getType() {
71     return type;
72     }
73
74     /**
75      * Invokes the appropriate ConnectionListener method
76      */

77     public void dispatch(Object JavaDoc listener) {
78     if (type == OPENED)
79         ((ConnectionListener JavaDoc)listener).opened(this);
80     else if (type == DISCONNECTED)
81         ((ConnectionListener JavaDoc)listener).disconnected(this);
82     else if (type == CLOSED)
83         ((ConnectionListener JavaDoc)listener).closed(this);
84     }
85 }
86
Popular Tags