001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.pubsub;
018
019import java.util.Collections;
020import java.util.List;
021
022/**
023 * Base class to represents events that are associated to subscriptions.
024 *
025 * @author Robin Collier
026 */
027public abstract class SubscriptionEvent extends NodeEvent {
028    private List<String> subIds = Collections.emptyList();
029
030    /**
031     * Construct an event with no subscription id's.  This can
032     * occur when there is only one subscription to a node.  The
033     * event may or may not report the subscription id along
034     * with the event.
035     *
036     * @param nodeId The id of the node the event came from
037     */
038    protected SubscriptionEvent(String nodeId) {
039        super(nodeId);
040    }
041
042    /**
043     * Construct an event with multiple subscriptions.
044     *
045     * @param nodeId The id of the node the event came from
046     * @param subscriptionIds The list of subscription id's
047     */
048    protected SubscriptionEvent(String nodeId, List<String> subscriptionIds) {
049        super(nodeId);
050
051        if (subscriptionIds != null)
052            subIds = subscriptionIds;
053    }
054
055    /**
056     * Get the subscriptions this event is associated with.
057     *
058     * @return List of subscription id's
059     */
060    public List<String> getSubscriptions() {
061        return Collections.unmodifiableList(subIds);
062    }
063
064    /**
065     * Set the list of subscription id's for this event.
066     *
067     * @param subscriptionIds The list of subscription id's
068     */
069    protected void setSubscriptions(List<String> subscriptionIds) {
070        if (subscriptionIds != null)
071            subIds = subscriptionIds;
072    }
073}