001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
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: */
022: package org.jboss.mq;
023:
024: import java.io.Serializable;
025:
026: import org.jboss.mq.il.ClientIL;
027:
028: /**
029: * This class is the broker point of view on a SpyConnection (it contains a
030: * ConnectionReceiver).
031: *
032: * Remember that for most IL's it will be serialized!
033: *
034: * @author <a href="Norbert.Lataille@m4x.org">Norbert Lataille</a>
035: * @author <a href="Cojonudo14@hotmail.com">Hiram Chirino</a>
036: * @author <a href="pra@tim.se">Peter Antman</a>
037: * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
038: * @version $Revision: 57198 $
039: */
040: public class ConnectionToken implements Serializable {
041: // Constants -----------------------------------------------------
042:
043: /** The serialVersionUID */
044: private static final long serialVersionUID = 1344893519455875890L;
045:
046: // Attributes ----------------------------------------------------
047:
048: /**
049: * Used by the server to callback to client. Will (most of the time) be
050: * serialized when sent to the server.
051: */
052: public ClientIL clientIL;
053:
054: /**
055: * The clientID of the connection.
056: */
057: protected String clientID;
058:
059: /**
060: * A secured hashed unique sessionId that is valid only as long as the
061: * connection live. Set during authentication and used for authorization.
062: */
063: private String sessionId;
064:
065: /** The hash code */
066: private int hash;
067:
068: // Static --------------------------------------------------------
069:
070: // Constructors --------------------------------------------------
071:
072: /**
073: * Create a new ConnectionToken
074: *
075: * @param clientID the client id
076: * @param clientIL the client il
077: */
078: public ConnectionToken(String clientID, ClientIL clientIL) {
079: this .clientIL = clientIL;
080: setClientID(clientID);
081: }
082:
083: /**
084: * Create a new ConnectionToken
085: *
086: * @param clientID the client id
087: * @param clientIL the client il
088: * @param sessionId the session id
089: */
090: public ConnectionToken(String clientID, ClientIL clientIL,
091: String sessionId) {
092: this (clientID, clientIL);
093: this .sessionId = sessionId;
094: }
095:
096: // Public --------------------------------------------------------
097:
098: /**
099: * Get the client id
100: *
101: * @return the client id
102: */
103: public String getClientID() {
104: return clientID;
105: }
106:
107: /**
108: * Set the client id
109: *
110: * @param clientID the client id
111: */
112: public void setClientID(String clientID) {
113: this .clientID = clientID;
114: if (clientID == null)
115: hash = 0;
116: else
117: hash = clientID.hashCode();
118: }
119:
120: /**
121: * Get the session id
122: *
123: * @return the session id
124: */
125: public String getSessionId() {
126: return sessionId;
127: }
128:
129: // Object overrides ----------------------------------------------
130:
131: public boolean equals(Object obj) {
132: if (!(obj instanceof ConnectionToken) || obj == null)
133: return false;
134:
135: if (obj.hashCode() != hash)
136: return false;
137: String yourID = ((ConnectionToken) obj).clientID;
138: String yourSessionId = ((ConnectionToken) obj).sessionId;
139: if (clientID == null && yourID != null)
140: return false;
141: else if (sessionId == null && yourSessionId != null)
142: return false;
143: else if (clientID != null && clientID.equals(yourID) == false)
144: return false;
145: else if (sessionId != null
146: && sessionId.equals(yourSessionId) == false)
147: return false;
148: else
149: return true;
150: }
151:
152: public int hashCode() {
153: return hash;
154: }
155:
156: public String toString() {
157: return "ConnectionToken:" + clientID + "/" + sessionId;
158: }
159:
160: // Package protected ---------------------------------------------
161:
162: // Protected -----------------------------------------------------
163:
164: // Private -------------------------------------------------------
165:
166: // Inner classes -------------------------------------------------
167: }
|