001/*
002 * GWTEventService
003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt)
004 *
005 * This is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU Lesser General Public License as
007 * published by the Free Software Foundation; either version 3 of
008 * the License, or (at your option) any later version.
009 * Other licensing for GWTEventService may also be possible on request.
010 * Please view the license.txt of the project for more information.
011 *
012 * This software is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022package de.novanic.eventservice.client.event.domain;
023
024/**
025 * Domains/contexts are used to specify the range where events should occur and listened. That supports the reuse of
026 * events ({@link de.novanic.eventservice.client.event.Event} and listeners ({@link de.novanic.eventservice.client.event.listener.RemoteEventListener}.
027 * <br>
028 * <br>Example:
029 * <br>Your application is a multiplayer online game with a conversation system. You defined the following events and
030 * listeners.
031 *   <br>
032 *   <br>Events: NewUserEvent
033 *   <br>Listeners: ConversationListener, ConversationChannelListener, PlayerListListener
034 *   <br>
035 * <br>It makes sense to divide your elements into different domains, to ensure that a NewUserEvent affects only the right
036 * context/domain. For example one conversation domain and one game domain. ConversationListener and
037 * ConversationChannelListener should be added to the conversation domain and the PlayerListListener should be added to
038 * the game domain. Now you can distinguish the context of the NewUserEvent. If a user joined a conversation (NewUserEvent
039 * added to conversation domain), the two conversation listeners will recognize it and the PlayerListListener won't be
040 * informed about the NewUserEvent in the conversation context/domain.
041 *
042 * @author sstrohschein
043 * <br>Date: 15.08.2008
044 * <br>Time: 22:42:20
045 */
046public final class DefaultDomain implements Domain
047{
048    private String myName;
049
050    /**
051     * @deprecated That constructor is only for serialization! Please use
052     * {@link de.novanic.eventservice.client.event.domain.DefaultDomain#DefaultDomain(String)} instead.
053     * @see de.novanic.eventservice.client.event.domain.DefaultDomain#DefaultDomain(String)
054     */
055    @Deprecated
056    public DefaultDomain() {}
057
058    /**
059     * Creates a new domain with a specified name. The name should be unique to avoid 'collision' of events.
060     * @param aName unique domain name
061     */
062    public DefaultDomain(String aName) {
063        myName = aName;
064    }
065
066    /**
067     * Return the name of the domain.
068     * @return domain name
069     */
070    public String getName() {
071        return myName;
072    }
073
074    public int compareTo(Domain aDomain) {
075        if(aDomain != null) {
076            return myName.compareTo(aDomain.getName());
077        }
078        return 1;
079    }
080
081    public boolean equals(Object anObject) {
082        if(this == anObject) {
083            return true;
084        }
085        if(anObject == null || getClass() != anObject.getClass()) {
086            return false;
087        }
088
089        Domain theDomain = (Domain)anObject;
090        return myName.equals(theDomain.getName());
091    }
092
093    public int hashCode() {
094        return myName.hashCode();
095    }
096
097    public String toString() {
098        return myName;
099    }
100}