KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > ClientSecurityInfo


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
24 package com.sun.enterprise.resource;
25
26 import java.security.Principal JavaDoc;
27 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
28 import com.sun.enterprise.deployment.ResourcePrincipal;
29
30 /**
31  * This class represents the client-specific information associated
32  * with a resource. Used for pool partitioning
33  *
34  * @author Tony Ng
35  */

36 public class ClientSecurityInfo {
37
38     // union: either store Principal or ConnectionRequestInfo
39
private ResourcePrincipal prin;
40     private ConnectionRequestInfo JavaDoc info;
41
42     static private final int NULL_HASH_CODE = new Integer JavaDoc(1).hashCode();
43
44     public ClientSecurityInfo(ResourcePrincipal prin) {
45         if (prin == null) {
46             throw new NullPointerException JavaDoc("Principal is null");
47         }
48         this.prin = prin;
49         this.info = null;
50     }
51
52     public ClientSecurityInfo(ConnectionRequestInfo JavaDoc info) {
53         // info can be null
54
this.prin = null;
55         this.info = info;
56     }
57
58
59     public ResourcePrincipal getPrincipal() {
60         return prin;
61     }
62
63     public ConnectionRequestInfo JavaDoc getConnectionRequestInfo() {
64         return info;
65     }
66
67     public boolean equals(Object JavaDoc obj) {
68         if (this == obj) return true;
69         if (obj == null) return false;
70         if (obj instanceof ClientSecurityInfo) {
71             ClientSecurityInfo other = (ClientSecurityInfo) obj;
72             return ((isEqual(prin, other.prin)) &&
73                     (isEqual(info, other.info)));
74         }
75         return false;
76     }
77
78     public int hashCode() {
79         int result = NULL_HASH_CODE;
80         if (prin != null) {
81             result = prin.hashCode();
82         }
83         if (info != null) {
84             result += info.hashCode();
85         }
86         return result;
87     }
88
89     private boolean isEqual(Object JavaDoc a, Object JavaDoc b) {
90         if (a == null) {
91             return (b == null);
92         } else {
93             return (a.equals(b));
94         }
95     }
96
97     public String JavaDoc toString() {
98     return "ClientSecurityInfo: prin=" + prin + " info="+info;
99     }
100 }
101
Popular Tags