SubscriptionEvent.java

  1. /**
  2.  *
  3.  * Copyright the original author or authors
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.pubsub;

  18. import java.util.Collections;
  19. import java.util.List;

  20. /**
  21.  * Base class to represents events that are associated to subscriptions.
  22.  *
  23.  * @author Robin Collier
  24.  */
  25. abstract public class SubscriptionEvent extends NodeEvent
  26. {
  27.     private List<String> subIds = Collections.emptyList();

  28.     /**
  29.      * Construct an event with no subscription id's.  This can
  30.      * occur when there is only one subscription to a node.  The
  31.      * event may or may not report the subscription id along
  32.      * with the event.
  33.      *
  34.      * @param nodeId The id of the node the event came from
  35.      */
  36.     protected SubscriptionEvent(String nodeId)
  37.     {
  38.         super(nodeId);
  39.     }

  40.     /**
  41.      * Construct an event with multiple subscriptions.
  42.      *
  43.      * @param nodeId The id of the node the event came from
  44.      * @param subscriptionIds The list of subscription id's
  45.      */
  46.     protected SubscriptionEvent(String nodeId, List<String> subscriptionIds)
  47.     {
  48.         super(nodeId);
  49.        
  50.         if (subscriptionIds != null)
  51.             subIds = subscriptionIds;
  52.     }

  53.     /**
  54.      * Get the subscriptions this event is associated with.
  55.      *
  56.      * @return List of subscription id's
  57.      */
  58.     public List<String> getSubscriptions()
  59.     {
  60.         return Collections.unmodifiableList(subIds);
  61.     }
  62.    
  63.     /**
  64.      * Set the list of subscription id's for this event.
  65.      *
  66.      * @param subscriptionIds The list of subscription id's
  67.      */
  68.     protected void setSubscriptions(List<String> subscriptionIds)
  69.     {
  70.         if (subscriptionIds != null)
  71.             subIds = subscriptionIds;
  72.     }
  73. }