KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > internal > notifications > ConnectionNotification


1 /*
2  * $Id: ConnectionNotification.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl.internal.notifications;
12
13 import org.mule.umo.manager.UMOServerNotification;
14 import org.mule.umo.provider.UMOConnectable;
15
16 /**
17  * Is fired by a connector when a connection is made, or disconnected of the
18  * connection fails.
19  *
20  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
21  * @version $Revision: 3798 $
22  */

23 public class ConnectionNotification extends UMOServerNotification
24 {
25     /**
26      * Serial version
27      */

28     private static final long serialVersionUID = -6455441938378523145L;
29     public static final int CONNECTION_CONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 1;
30     public static final int CONNECTION_FAILED = CONNECTION_EVENT_ACTION_START_RANGE + 2;
31     public static final int CONNECTION_DISCONNECTED = CONNECTION_EVENT_ACTION_START_RANGE + 3;
32
33     private static final transient String JavaDoc[] ACTIONS = new String JavaDoc[]{"connected", "connect failed",
34         "disconnected"};
35
36     public ConnectionNotification(UMOConnectable resource, String JavaDoc identifier, int action)
37     {
38         super(resource, action);
39         resourceIdentifier = identifier;
40     }
41
42     protected String JavaDoc getPayloadToString()
43     {
44         if (source instanceof UMOConnectable)
45         {
46             return ((UMOConnectable)source).getConnectionDescription();
47         }
48         return source.toString();
49     }
50
51     protected String JavaDoc getActionName(int action)
52     {
53         int i = action - CONNECTION_EVENT_ACTION_START_RANGE;
54         if (i - 1 > ACTIONS.length)
55         {
56             return String.valueOf(action);
57         }
58         return ACTIONS[i - 1];
59     }
60
61     public String JavaDoc getType()
62     {
63         if (action == CONNECTION_DISCONNECTED)
64         {
65             return TYPE_WARNING;
66         }
67         if (action == CONNECTION_FAILED)
68         {
69             return TYPE_ERROR;
70         }
71         return TYPE_INFO;
72     }
73
74 }
75
Popular Tags