All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jivesoftware.openfire.event.GroupEventDispatcher Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * 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.
 */

package org.jivesoftware.openfire.event;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jivesoftware.openfire.group.Group;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Dispatches group events. Each event has a {@link EventType type}
 * and optional parameters, as follows:

* *

* * * * * * * * * *
Event TypeExtra Params
{@link EventType#group_created group_created}None
{@link EventType#group_deleting group_deleting}None
{@link EventType#member_added member_added}A param named member with a String username as a * payload
{@link EventType#member_removed member_removed}A param named member with a String username as a * payload
{@link EventType#admin_added admin_added}A param named admin with a String username * as a payload
{@link EventType#admin_removed admin_removed}A param named admin with a String username * as a payload
{@link EventType#group_modified group_modified} * * * * * * * * * * * * * * * * * * * * * * * * *
ReasonKeyValue
Name modified
 typenameModified
 originalValue(Name before it was modified) *

Description modified
 typedescriptionModified
 originalValue(Description before it was * modified)

Property modified
 typepropertyModified
 propertyKey(Name of the property)
 originalValue(Property value before it was * modified)

Property added
 typepropertyAdded
 propertyKey(Name of the new property)

Property deleted
 typepropertyDeleted
 propertyKey(Name of the property deleted)
* * @author Matt Tucker */ public class GroupEventDispatcher { private static final Logger Log = LoggerFactory.getLogger(GroupEventDispatcher.class); private static List listeners = new CopyOnWriteArrayList<>(); private GroupEventDispatcher() { // Not instantiable. } /** * Registers a listener to receive events. * * @param listener the listener. */ public static void addListener(GroupEventListener listener) { if (listener == null) { throw new NullPointerException(); } listeners.add(listener); } /** * Unregisters a listener to receive events. * * @param listener the listener. */ public static void removeListener(GroupEventListener listener) { listeners.remove(listener); } /** * Dispatches an event to all listeners. * * @param group the group. * @param eventType the event type. * @param params event parameters. */ public static void dispatchEvent(Group group, EventType eventType, Map params) { for (GroupEventListener listener : listeners) { try { switch (eventType) { case group_created: { listener.groupCreated(group, params); break; } case group_deleting: { listener.groupDeleting(group, params); break; } case member_added: { listener.memberAdded(group, params); break; } case member_removed: { listener.memberRemoved(group, params); break; } case admin_added: { listener.adminAdded(group, params); break; } case admin_removed: { listener.adminRemoved(group, params); break; } case group_modified: { listener.groupModified(group, params); break; } default: break; } } catch (Exception e) { Log.error(e.getMessage(), e); } } } /** * Represents valid event types. */ public enum EventType { /** * A new group was created. */ group_created, /** * A group is about to be deleted. Note that this event is fired before * a group is actually deleted. This allows for referential cleanup * before the group is gone. */ group_deleting, /** * The name, description, or extended property of a group was changed. */ group_modified, /** * A member was added to a group. */ member_added, /** * A member was removed from a group. */ member_removed, /** * An administrator was added to a group. */ admin_added, /** * An administrator was removed from a group. */ admin_removed; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy