KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > ConnectionToken


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq;
23
24 import java.io.Serializable JavaDoc;
25
26 import org.jboss.mq.il.ClientIL;
27
28 /**
29  * This class is the broker point of view on a SpyConnection (it contains a
30  * ConnectionReceiver).
31  *
32  * Remember that for most IL's it will be serialized!
33  *
34  * @author <a HREF="Norbert.Lataille@m4x.org">Norbert Lataille</a>
35  * @author <a HREF="Cojonudo14@hotmail.com">Hiram Chirino</a>
36  * @author <a HREF="pra@tim.se">Peter Antman</a>
37  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
38  * @version $Revision: 37459 $
39  */

40 public class ConnectionToken implements Serializable JavaDoc
41 {
42    // Constants -----------------------------------------------------
43

44    /** The serialVersionUID */
45    private static final long serialVersionUID = 1344893519455875890L;
46    
47    // Attributes ----------------------------------------------------
48

49    /**
50      * Used by the server to callback to client. Will (most of the time) be
51      * serialized when sent to the server.
52      */

53    public ClientIL clientIL;
54
55    /**
56      * The clientID of the connection.
57      */

58    protected String JavaDoc clientID;
59
60    /**
61      * A secured hashed unique sessionId that is valid only as long as the
62      * connection live. Set during authentication and used for authorization.
63      */

64    private String JavaDoc sessionId;
65    
66    /** The hash code */
67    private int hash;
68    
69    // Static --------------------------------------------------------
70

71    // Constructors --------------------------------------------------
72

73    /**
74     * Create a new ConnectionToken
75     *
76     * @param clientID the client id
77     * @param clientIL the client il
78     */

79    public ConnectionToken(String JavaDoc clientID, ClientIL clientIL)
80    {
81       this.clientIL = clientIL;
82       setClientID(clientID);
83    }
84    
85    /**
86     * Create a new ConnectionToken
87     *
88     * @param clientID the client id
89     * @param clientIL the client il
90     * @param sessionId the session id
91     */

92    public ConnectionToken(String JavaDoc clientID, ClientIL clientIL, String JavaDoc sessionId)
93    {
94       this(clientID, clientIL);
95       this.sessionId = sessionId;
96    }
97    
98    // Public --------------------------------------------------------
99

100    /**
101     * Get the client id
102     *
103     * @return the client id
104     */

105    public String JavaDoc getClientID()
106    {
107       return clientID;
108    }
109
110    /**
111     * Set the client id
112     *
113     * @param clientID the client id
114     */

115    public void setClientID(String JavaDoc clientID)
116    {
117       this.clientID = clientID;
118       if (clientID == null)
119          hash = 0;
120       else
121          hash = clientID.hashCode();
122    }
123
124    /**
125     * Get the session id
126     *
127     * @return the session id
128     */

129    public String JavaDoc getSessionId()
130    {
131       return sessionId;
132    }
133    
134    // Object overrides ----------------------------------------------
135

136    public boolean equals(Object JavaDoc obj)
137    {
138       if (!(obj instanceof ConnectionToken) || obj == null)
139          return false;
140
141       if (obj.hashCode() != hash)
142          return false;
143       String JavaDoc yourID = ((ConnectionToken) obj).clientID;
144       String JavaDoc yourSessionId = ((ConnectionToken) obj).sessionId;
145       if (clientID == null && yourID != null)
146          return false;
147       else if (sessionId == null && yourSessionId != null)
148          return false;
149       else if (clientID != null && clientID.equals(yourID) == false)
150          return false;
151       else if (sessionId != null && sessionId.equals(yourSessionId) == false)
152          return false;
153       else
154          return true;
155    }
156
157    public int hashCode()
158    {
159       return hash;
160    }
161
162    public String JavaDoc toString()
163    {
164       return "ConnectionToken:" + clientID + "/" + sessionId;
165    }
166    
167    // Package protected ---------------------------------------------
168

169    // Protected -----------------------------------------------------
170

171    // Private -------------------------------------------------------
172

173    // Inner classes -------------------------------------------------
174
}
Popular Tags