KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: CustomNotification.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
15 /**
16  * <code>CustomNotification</code> Custom notifications can be used by components
17  * and other objects such as routers, transformers, agents, etc to communicate a
18  * change of state to each other. The Action value for the event is abitary. However
19  * care should be taken not to set the action code to an existing action code. To
20  * ensure this doesn't happen always set the action code greater than the
21  * CUSTOM_ACTION_START_RANGE.
22  *
23  * @see CustomNotificationListener
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27 public class CustomNotification extends UMOServerNotification
28 {
29     /**
30      * Serial version
31      */

32     private static final long serialVersionUID = 762448139858484536L;
33
34     /**
35      * Creates a custom action event
36      *
37      * @param message the message to associate with the event
38      * @param action the action code for the event
39      * @throws IllegalArgumentException if the action value is less than
40      * CUSTOM_ACTION_START_RANGE
41      */

42     public CustomNotification(Object JavaDoc message, int action)
43     {
44         super(message, action);
45         if (action < CUSTOM_EVENT_ACTION_START_RANGE && action > 0)
46         {
47             throw new IllegalArgumentException JavaDoc(
48                 "Action range must be greater than CUSTOM_ACTION_START_RANGE ("
49                                 + CUSTOM_EVENT_ACTION_START_RANGE + ")");
50         }
51     }
52
53     public CustomNotification(Object JavaDoc message, int action, String JavaDoc resourceId)
54     {
55         super(message, action, resourceId);
56         if (action < CUSTOM_EVENT_ACTION_START_RANGE && action > 0)
57         {
58             throw new IllegalArgumentException JavaDoc(
59                 "Action range must be greater than CUSTOM_ACTION_START_RANGE ("
60                                 + CUSTOM_EVENT_ACTION_START_RANGE + ")");
61         }
62     }
63
64     protected String JavaDoc getActionName(int action)
65     {
66         int i = action - CUSTOM_EVENT_ACTION_START_RANGE;
67         if (i - 1 >= getActionNames().length || i < 0)
68         {
69             return String.valueOf(action);
70         }
71         return getActionNames()[i - 1];
72     }
73
74     protected String JavaDoc[] getActionNames()
75     {
76         return new String JavaDoc[]{};
77     }
78 }
79
Popular Tags