KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonathan > apis > protocols > ip > IpSessionIdentifier


1 /***
2  * Jonathan: an Open Distributed Processing Environment
3  * Copyright (C) 1999 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Release: 2.0
20  *
21  * Contact: jonathan@objectweb.org
22  *
23  * Author: Bruno Dumant
24  */

25
26
27 package org.objectweb.jonathan.apis.protocols.ip;
28
29 import org.objectweb.jonathan.apis.protocols.SessionIdentifier;
30 import org.objectweb.jonathan.apis.protocols.ProtocolIdentifiers;
31
32
33 /**
34  * IpSessionIdentifier is a specific
35  * {@link org.objectweb.jonathan.apis.protocols.SessionIdentifier
36  * SessionIdentifier} type for IP protocols. An IP session identifier contains
37  * a host name, and a port
38  * number.
39  */

40 abstract public class IpSessionIdentifier implements SessionIdentifier, ProtocolIdentifiers {
41
42     /** Hostname of this session identifier. */
43     public String JavaDoc hostname;
44
45     /** Port number of this session identifier. */
46     public int port;
47
48     /**
49      * Constructs a new IpSessionIdentifier with the specified host name and port
50      * number.
51      *
52      * @param hostname a host name;
53      * @param port a port number;
54      * @return an IP session identifier.
55      */

56     public IpSessionIdentifier(String JavaDoc hostname, int port) {
57         this.hostname = hostname;
58         this.port = port;
59     }
60
61     /**
62      * Constructs a new empty IpSessionIdentifier.
63      */

64     public IpSessionIdentifier() {
65         this.port = 0;
66     }
67
68     /**
69      * Returns a hash code value for this IpSessionIdentifier.
70      *
71      * @return a hash code value for this object.
72      */

73     public int hashCode() {
74         if (hostname == null) {
75             return port;
76         } else {
77             return hostname.hashCode() + port;
78         }
79     }
80    
81     /**
82      * Compares this object to the specified object.
83      * <p>
84      * The result is true if and only if the argument is not null and is a
85      * IpSessionIdentifier object that has the same host name and port number.
86      *
87      * @param o the object to compare with.
88      * @return true if the objects are the same; false otherwise.
89      */

90     public boolean equals(Object JavaDoc o) {
91         if (o != null && o instanceof IpSessionIdentifier) {
92             IpSessionIdentifier k = (IpSessionIdentifier)o;
93             return port == k.port && hostname.equals(k.hostname);
94         } else {
95             return false;
96         }
97     }
98
99     /**
100      * Returns a string representation of this session identifier.
101      *
102      * @return a string representation of this session identifier.
103      */

104     public String JavaDoc toString() {
105         return "IpSessionIdentifier["+hostname+","+port+"]";
106     }
107
108     /**
109      * Return an empty array: this is a leaf protocol in the protocol
110      * tree.
111      *
112      * @return the session identifiers corresponding to the lower level
113      * protocol layers, if any.
114      */

115     public SessionIdentifier[] next() {
116     return new SessionIdentifier[0];
117     }
118
119     public final int getProtocolId() {
120     return ProtocolIdentifiers.TCPIP;
121     }
122
123 }
124
Popular Tags