View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.context.notification;
8   
9   import org.mule.api.context.notification.CustomNotificationListener;
10  import org.mule.api.context.notification.ServerNotification;
11  
12  /**
13   * <code>CustomNotification</code> Custom notifications can be used by components
14   * and other objects such as routers, transformers, agents, etc to communicate a
15   * change of state to each other. The Action value for the event is abitary. However
16   * care should be taken not to set the action code to an existing action code. To
17   * ensure this doesn't happen always set the action code greater than the
18   * CUSTOM_ACTION_START_RANGE.
19   * 
20   * @see CustomNotificationListener
21   */
22  public class CustomNotification extends ServerNotification
23  {
24      /**
25       * Serial version
26       */
27      private static final long serialVersionUID = 762448139858484536L;
28  
29      /**
30       * Creates a custom action event
31       * 
32       * @param message the message to associate with the event
33       * @param action the action code for the event
34       * @throws IllegalArgumentException if the action value is less than
35       *             CUSTOM_ACTION_START_RANGE
36       */
37      public CustomNotification(Object message, int action)
38      {
39          super(message, action);
40          if (action < CUSTOM_EVENT_ACTION_START_RANGE && action > 0)
41          {
42              throw new IllegalArgumentException(
43                  "Action range must be greater than CUSTOM_ACTION_START_RANGE ("
44                                  + CUSTOM_EVENT_ACTION_START_RANGE + ")");
45          }
46      }
47  
48      public CustomNotification(Object message, int action, String resourceId)
49      {
50          super(message, action, resourceId);
51          if (action < CUSTOM_EVENT_ACTION_START_RANGE && action > 0)
52          {
53              throw new IllegalArgumentException(
54                  "Action range must be greater than CUSTOM_ACTION_START_RANGE ("
55                                  + CUSTOM_EVENT_ACTION_START_RANGE + ")");
56          }
57      }
58  
59      protected String[] getActionNames()
60      {
61          return new String[]{};
62      }
63  }