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

net.sf.eBus.client.sysmessages.LogonReply Maven / Gradle / Ivy

//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later
// version.
//
// This library is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General
// Public License along with this library; if not, write to the
//
// Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330,
// Boston, MA
// 02111-1307 USA
//
// The Initial Developer of the Original Code is Charles W. Rapp.
// Portions created by Charles W. Rapp are
// Copyright 2012, 2013, 2016. Charles W. Rapp
// All Rights Reserved.
//

package net.sf.eBus.client.sysmessages;

import java.io.Serializable;
import net.sf.eBus.messages.EFieldInfo;
import static net.sf.eBus.messages.EReplyMessage.ReplyStatus;

/**
 * This message is sent in reply to a logon message. The subject
 * contains the eBus identifier received in the
 * {@link LogonMessage}.
 *
 * @see AbstractLogonMessage
 * @see LogonMessage
 * @see LogoffMessage
 *
 * @author Charles Rapp
 */

@EFieldInfo(fields={"logonStatus", "reason"})
public final class LogonReply
    extends AbstractLogonMessage
    implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//

    //-----------------------------------------------------------
    // Constructors.
    //

    /**
     * Creates a new logon reply instance for the given eBus
     * identifier, logon status, and reason.
     * @param eid the eBus identifier.
     * @param logonStatus either the logon request was accepted
     * or rejected.
     * @param reason the reason for a rejected logon. May be
     * {@code null} or empty.
     * @throws IllegalArgumentException
     * if {@code eid} is either {@code null} or empty or
     * {@code logonStatus} is {@code null}.
     */
    public LogonReply(final String eid,
                      final ReplyStatus logonStatus,
                      final String reason)
        throws IllegalArgumentException
    {
        super (eid);

        if (logonStatus == null)
        {
            throw (
                new IllegalArgumentException(
                    "null logonStatus"));
        }

        this.logonStatus = logonStatus;
        this.reason = reason;
    } // end of LogonReply(String, ReplyStatus, String)

    /**
     * Creates a new logon reply from the de-serialized values.
     * @param subject
     * {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}.
     * @param timestamp the message millisecond timestamp.
     * @param eid the eBus identifier.
     * @param logonStatus either the logon request was accepted
     * or rejected.
     * @param reason the reason for a rejected logon. May be
     * {@code null} or empty.
     * @throws IllegalArgumentException
     * if:
     * 
    *
  • * {@code subject} is either {@code null} or empty, *
  • *
  • * {@code eid} is either {@code null} or empty, or *
  • *
  • * {@code logonStatus} is {@code null}. *
  • *
*/ public LogonReply(final String subject, final long timestamp, final String eid, final ReplyStatus logonStatus, final String reason) throws IllegalArgumentException { super (subject, timestamp, eid); if (logonStatus == null) { throw ( new IllegalArgumentException( "null logonStatus")); } this.logonStatus = logonStatus; this.reason = reason; } // end of LogonReply(...) // // end of Constructors. //----------------------------------------------------------- //----------------------------------------------------------- // Object Method Overrides. // /** * Returns {@code true} if {@code o} is a * non-{@code null LogonReply} instance with reply status and * reason equal to {@code this LogonReply} instance and * {@code false} otherwise. * @param o comparison object. * @return {@code true} if the message fields are equal * and {@code false} otherwise. */ @Override public boolean equals(final Object o) { boolean retcode = (this == o); if (retcode == false && o instanceof LogonReply) { final LogonReply lr = (LogonReply) o; retcode = (super.equals(o) == true && logonStatus == lr.logonStatus && (reason == null ? lr.reason == null : reason.equals(lr.reason) == true)); } return (retcode); } // endof equals(Object) /** * Returns the feed status message hash code. * @return the feed status message hash code. */ @Override public int hashCode() { return ( (((super.hashCode() * 37) + logonStatus.ordinal()) * 37) + (reason == null ? 0 : reason.hashCode())); } // end of hashCode() /** * Returns a human-readable text version of this message. * @return text version of this message. */ @Override public String toString() { return ( String.format( "%s%n logon status: %s%n reason: %s", super.toString(), logonStatus, (reason == null ? "(none)" : reason))); } // end of toString() // // end of Object Method Overrides. //----------------------------------------------------------- //--------------------------------------------------------------- // Member data. // /** * Either the logon attempt succeeded or failed. */ public final ReplyStatus logonStatus; /** * Explanation for a rejected logon request. May be * {@code null} or empty. */ public final String reason; //----------------------------------------------------------- // Constants. // /** * Serialization version identifier. */ private static final long serialVersionUID = 0x060100L; } // end of class LogonReply




© 2015 - 2025 Weber Informatics LLC | Privacy Policy