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. public abstract class SubscriptionEvent extends NodeEvent {
  26.     private List<String> subIds = Collections.emptyList();

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

  38.     /**
  39.      * Construct an event with multiple subscriptions.
  40.      *
  41.      * @param nodeId The id of the node the event came from
  42.      * @param subscriptionIds The list of subscription id's
  43.      */
  44.     protected SubscriptionEvent(String nodeId, List<String> subscriptionIds) {
  45.         super(nodeId);

  46.         if (subscriptionIds != null)
  47.             subIds = subscriptionIds;
  48.     }

  49.     /**
  50.      * Get the subscriptions this event is associated with.
  51.      *
  52.      * @return List of subscription id's
  53.      */
  54.     public List<String> getSubscriptions() {
  55.         return Collections.unmodifiableList(subIds);
  56.     }

  57.     /**
  58.      * Set the list of subscription id's for this event.
  59.      *
  60.      * @param subscriptionIds The list of subscription id's
  61.      */
  62.     protected void setSubscriptions(List<String> subscriptionIds) {
  63.         if (subscriptionIds != null)
  64.             subIds = subscriptionIds;
  65.     }
  66. }