001 /*
002 * Cumulus4j - Securing your data in the cloud - http://cumulus4j.org
003 * Copyright (C) 2011 NightLabs Consulting GmbH
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
017 */
018 package org.cumulus4j.keymanager.back.shared;
019
020 import java.io.Serializable;
021
022 import javax.xml.bind.annotation.XmlRootElement;
023
024 /**
025 * <p>
026 * Base-type for {@link Request} and {@link Response}.
027 * </p>
028 * <p>
029 * There should not be any other direct sub-classes of this class besides <code>Request</code> and
030 * <code>Response</code>.
031 * </p>
032 * <p>
033 * We implement a
034 * <a target="_blank" href="http://en.wikipedia.org/wiki/Request-response">request-response</a>
035 * <a target="_blank" href="http://en.wikipedia.org/wiki/Messaging_pattern">messaging-pattern</a>,
036 * hence for every <code>Request</code> instance,
037 * there must be exactly one <code>Response</code> instance. Both are identified
038 * by the {@link #getRequestID() requestID}
039 * </p>
040 *
041 * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de
042 */
043 @XmlRootElement
044 public abstract class Message implements Serializable
045 {
046 private static final long serialVersionUID = 1L;
047
048 private String requestID;
049
050 public Message() { }
051
052 /**
053 * Get the request-identifier. Because a {@link Response} belongs
054 * to a {@link Request} in a 1-1-relationship, both use the same <code>requestID</code>.
055 * @return the identifier of the request.
056 * @see #setRequestID(String)
057 */
058 public String getRequestID() {
059 return requestID;
060 }
061
062 /**
063 * Set the request-identifier.
064 * @param requestID the identifier of the request.
065 * @see #getRequestID()
066 */
067 public void setRequestID(String requestID) {
068 this.requestID = requestID;
069 }
070
071 @Override
072 public int hashCode()
073 {
074 return (requestID == null) ? 0 : requestID.hashCode();
075 }
076
077 @Override
078 public boolean equals(Object obj)
079 {
080 if (this == obj) return true;
081 if (obj == null) return false;
082 if (getClass() != obj.getClass()) return false;
083 Message other = (Message) obj;
084 return (
085 this.requestID == other.requestID ||
086 (this.requestID != null && this.requestID.equals(other.requestID))
087 );
088 }
089 }