View Javadoc

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