PublisherModel.java 2.48 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile: $
 * $Revision: $
 * $Date: $
 *
6
 * Copyright (C) 2005-2008 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
8 9 10 11 12 13 14 15 16 17 18
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
Matt Tucker's avatar
Matt Tucker committed
19 20
 */

21
package org.jivesoftware.openfire.pubsub.models;
Matt Tucker's avatar
Matt Tucker committed
22

23
import org.jivesoftware.openfire.pubsub.Node;
Matt Tucker's avatar
Matt Tucker committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
import org.xmpp.packet.JID;

/**
 * Policy that defines who is allowed to publish items to the node.
 *
 * @author Matt Tucker
 */
public abstract class PublisherModel {

    public final static PublisherModel open = new OpenPublisher();
    public final static PublisherModel publishers = new OnlyPublishers();
    public final static PublisherModel subscribers = new OnlySubscribers();

    /**
     * Returns the specific subclass of PublisherModel as specified by the publisher
     * model name. If an unknown name is specified then an IllegalArgumentException
     * is going to be thrown.
     *
     * @param name the name of the subsclass.
     * @return the specific subclass of PublisherModel as specified by the access
     *         model name.
     */
    public static PublisherModel valueOf(String name) {
        if ("open".equals(name)) {
            return open;
        }
        else if ("publishers".equals(name)) {
            return publishers;
        }
        else if ("subscribers".equals(name)) {
            return subscribers;
        }
        throw new IllegalArgumentException("Unknown publisher model: " + name);
    }
    /**
     * Returns the name as defined by the JEP-60 spec.
     *
     * @return the name as defined by the JEP-60 spec.
     */
    public abstract String getName();

    /**
     * Returns true if the entity is allowed to publish items to the specified node.
     *
     * @param node       the node that may get a new published item by the specified entity.
     * @param entity     the JID of the entity that wants to publish an item to the node.
     * @return true if the subscriber is allowed to publish items to the specified node.
     */
    public abstract boolean canPublish(Node node, JID entity);

}