KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > jaas > JaasClientId


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.security.jaas;
19
20 import java.io.Serializable JavaDoc;
21
22
23 /**
24  * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
25  */

26 public class JaasClientId implements Serializable JavaDoc {
27     private final long clientId;
28     private final byte[] hash;
29     private transient int hashCode;
30     private transient String JavaDoc name;
31
32     public JaasClientId(long clientId, byte[] hash) {
33         this.clientId = clientId;
34         this.hash = hash;
35     }
36
37     public long getClientId() {
38         return clientId;
39     }
40
41     public byte[] getHash() {
42         return hash;
43     }
44
45     public boolean equals(Object JavaDoc obj) {
46         if (!(obj instanceof JaasClientId)) return false;
47
48         JaasClientId another = (JaasClientId) obj;
49         if (another.clientId != clientId) return false;
50         for (int i = 0; i < hash.length; i++) {
51             if (another.hash[i] != hash[i]) return false;
52         }
53         return true;
54     }
55
56     public String JavaDoc toString() {
57         if (name == null) {
58             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
59             buffer.append('[');
60             buffer.append(clientId);
61             buffer.append(":0x");
62             for (int i = 0; i < hash.length; i++) {
63                 buffer.append(HEXCHAR[(hash[i]>>>4)&0x0F]);
64                 buffer.append(HEXCHAR[(hash[i] )&0x0F]);
65             }
66             buffer.append(']');
67             name = buffer.toString();
68         }
69         return name;
70     }
71
72     /**
73      * Returns a hashcode for this LoginModuleId.
74      *
75      * @return a hashcode for this LoginModuleId.
76      */

77     public int hashCode() {
78         if (hashCode == 0) {
79             for (int i = 0; i < hash.length; i++) {
80                 hashCode ^= hash[i];
81             }
82             hashCode ^= (int)(clientId ^ (clientId >>> 32));
83         }
84         return hashCode;
85     }
86
87     private static final char[] HEXCHAR = {
88         '0', '1', '2', '3', '4', '5', '6', '7',
89         '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
90     };
91 }
92
Popular Tags