KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > PrincipalImpl


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.enterprise.deployment;
24
25 import java.security.Principal JavaDoc;
26
27 /**
28  * This class implements the principal interface.
29  *
30  * @author Harish Prabandham
31  */

32 public class PrincipalImpl implements Principal JavaDoc, java.io.Serializable JavaDoc {
33
34     /**
35      * @serial
36      */

37     private String JavaDoc name;
38
39      /**
40      * Construct a principal from a string user name.
41      * @param user The string form of the principal name.
42      */

43     public PrincipalImpl(String JavaDoc user) {
44     this.name = user;
45     }
46
47     /**
48      * This function returns true if the object passed matches
49      * the principal represented in this implementation
50      * @param another the Principal to compare with.
51      * @return true if the Principal passed is the same as that
52      * encapsulated in this object, false otherwise
53      */

54     public boolean equals(Object JavaDoc another) {
55         // XXX for bug 4889642: if groupA and userA have
56
// the same name, then groupA.equals(userA) return false
57
// BUT userA.equals(groupA) return "true"
58
if (another instanceof Group) {
59             return false;
60         } else if (another instanceof PrincipalImpl) {
61         Principal JavaDoc p = (Principal JavaDoc) another;
62         return getName().equals(p.getName());
63     } else
64         return false;
65     }
66     
67     /**
68      * Prints a stringified version of the principal.
69      * @return A java.lang.String object returned by the method getName()
70      */

71     public String JavaDoc toString() {
72     return getName();
73     }
74
75     /**
76      * Returns the hashcode for this Principal object
77      * @return a hashcode for the principal.
78      */

79     public int hashCode() {
80     return name.hashCode();
81     }
82
83     /**
84      * Gets the name of the Principal as a java.lang.String
85      * @return the name of the principal.
86      */

87     public String JavaDoc getName() {
88     return name;
89     }
90
91 }
92
Popular Tags