KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > security > management > DefaultUserImpl


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.security.management;
19
20 import java.io.Serializable JavaDoc;
21 import java.security.Principal JavaDoc;
22
23 /**
24  * Default implementation for a user of the system.
25  * <p>
26  * This provides a simple implementation of the user
27  * of the system.
28  * </p>
29  *
30  * @author $Author: dvoet $ $Date: 2003/05/05 21:21:35 $
31  * @version $Revision: 1.3 $
32  *
33  * @since carbon 1.2
34  */

35 public class DefaultUserImpl implements Principal JavaDoc, Serializable JavaDoc {
36     /** Holds the name of the user. */
37     protected String JavaDoc name;
38
39     /**
40      * Constructs a new user object with the given name.
41      *
42      * @param name the name of the user
43      */

44     public DefaultUserImpl(String JavaDoc name) {
45         this.name = name;
46     }
47
48     /**
49      * Returns the name of the user.
50      *
51      * @return the name of the user
52      */

53     public String JavaDoc getName() {
54         return this.name;
55     }
56
57     /**
58      * Checks the name of the two users to see if they are equal.
59      *
60      * @param obj another object to compare this to
61      *
62      * @return if the two users have the same unique name
63      */

64     public boolean equals(Object JavaDoc obj) {
65         boolean result = false;
66
67         if (obj instanceof Principal JavaDoc) {
68             if (this.getName().equals(((Principal JavaDoc) obj).getName())) {
69                 result = true;
70             }
71         }
72
73         return result;
74     }
75
76     /**
77      * Returns a hashcode based on the name of the user.
78      *
79      * @return a hashcode based on the name
80      */

81     public int hashCode() {
82         return getName().hashCode();
83     }
84
85     /**
86      * Returns a string representation of the object.
87      *
88      * @return a string representation of the object
89      */

90     public String JavaDoc toString() {
91         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(32);
92         sb.append(this.getClass().getName());
93         sb.append(" [");
94         sb.append("name=");
95         sb.append(getName());
96         sb.append("]");
97
98         return sb.toString();
99     }
100 }
101
Popular Tags