KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > security > struct > JPrincipal


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JPrincipal.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.security.struct;
27
28 import java.io.Serializable JavaDoc;
29 import java.security.Principal JavaDoc;
30
31 /**
32  * Implementation of Principal class.
33  * @author Florent Benoit
34  */

35 public class JPrincipal implements Principal JavaDoc, Serializable JavaDoc {
36
37     /**
38      * UID for serialization.
39      */

40     private static final long serialVersionUID = 5864848835776239991L;
41
42     /**
43      * Name of this principal.
44      */

45     private String JavaDoc name = null;
46
47     /**
48      * Constructor.
49      * @param name the name of this principal
50      */

51     public JPrincipal(final String JavaDoc name) {
52         this.name = name;
53     }
54
55     /**
56      * Compares this principal to the specified object. Returns true if the
57      * object passed in matches the principal represented by the implementation
58      * of this interface.
59      * @param another principal to compare with.
60      * @return true if the principal passed in is the same as that encapsulated
61      * by this principal, and false otherwise.
62      */

63     @Override JavaDoc
64     public boolean equals(final Object JavaDoc another) {
65         if (!(another instanceof Principal JavaDoc)) {
66             return false;
67         }
68         // else
69
return name.equals(((Principal JavaDoc) another).getName());
70     }
71
72     /**
73      * Returns a string representation of this principal.
74      * @return a string representation of this principal.
75      */

76     @Override JavaDoc
77     public String JavaDoc toString() {
78         return "Principal[" + name + "]";
79     }
80
81     /**
82      * Returns a hashcode for this principal.
83      * @return a hashcode for this principal.
84      */

85     @Override JavaDoc
86     public int hashCode() {
87         return name.hashCode();
88     }
89
90     /**
91      * Returns the name of this principal.
92      * @return the name of this principal.
93      */

94     public String JavaDoc getName() {
95         return name;
96     }
97
98 }
99
Popular Tags