KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > client > prefs > LoginInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.appserv.management.client.prefs;
24
25 /**
26  * An immutable class that represents an arbitrary LoginInfo for Appserver Administration Client. A LoginInfo
27  * is specific to an admin host and admin port. Thus, with this scheme, there can be
28  * at the most one LoginInfo for an operating system user of Appserver, for a given admin host
29  * and admin port.
30  * @since Appserver 9.0
31  */

32 public final class LoginInfo implements Comparable JavaDoc<LoginInfo> {
33     private String JavaDoc host;
34     private int port;
35     private String JavaDoc user;
36     private String JavaDoc password;
37     
38     /**
39      * Creates an Immutable instance of a LoginInfo from given 4-tuple.
40      * The host, user and password may not be null.
41      * The port may not be a negative integer.
42      * @param host String representing host
43      * @param port integer representing port
44      * @param user String representing user
45      * @param password String representing password
46      * @throws IllegalArgumentException if parameter contract is violated
47      */

48     public LoginInfo(final String JavaDoc host, final int port, final String JavaDoc user, final String JavaDoc password) {
49         if (host == null || port < 0 || user == null || password == null)
50             throw new IllegalArgumentException JavaDoc("null value"); // TODO
51
init(host, port, user, password);
52     }
53     public String JavaDoc getHost() {
54         return ( host );
55     }
56     public int getPort() {
57         return ( port );
58     }
59     public String JavaDoc getUser() {
60         return ( user );
61     }
62     public String JavaDoc getPassword() {
63         return ( password );
64     }
65     public boolean equals(final Object JavaDoc other) {
66         boolean same = false;
67         if (other instanceof LoginInfo) {
68             final LoginInfo that = (LoginInfo) other;
69             same = this.host.equals(that.host) &&
70                    this.port == that.port &&
71                    this.user.equals(that.user) &&
72                    this.password.equals(that.password);
73         }
74         return ( same );
75     }
76     public int hashCode() {
77         return ( (int) 31 * host.hashCode() + 23 * port + 53 * user.hashCode() + 13 * password.hashCode() );
78     }
79     
80     private void init(final String JavaDoc host, final int port, final String JavaDoc user, final String JavaDoc password) {
81         this.host = host;
82         this.port = port;
83         this.user = user;
84         this.password = password;
85     }
86     
87     public String JavaDoc toString() {
88         return ( host + port + user + password );
89     }
90
91     public int compareTo(final LoginInfo that) {
92         final String JavaDoc thisKey = this.user + this.host + this.port;
93         final String JavaDoc thatKey = that.user + that.host + that.port;
94         return ( thisKey.compareTo(thatKey) );
95     }
96 }
Popular Tags