KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > NobodyPrincipal


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.security;
8
9 import java.security.Principal JavaDoc;
10
11 /** An implementation of Principal and Comparable that represents no role.
12 Any Principal or name of a Principal when compared to an NobodyPrincipal
13 using {@link #equals(Object) equals} or {@link #compareTo(Object) compareTo}
14 will always be found not equal to the NobodyPrincipal.
15
16 Note that this class is not likely to operate correctly in a collection
17 since the hashCode() and equals() methods are not correlated.
18
19 @author Scott.Stark@jboss.org
20 @version $Revision: 1.5 $
21 */

22 public class NobodyPrincipal implements Comparable JavaDoc, Principal JavaDoc
23 {
24     public static final String JavaDoc NOBODY = "<NOBODY>";
25     public static final NobodyPrincipal NOBODY_PRINCIPAL = new NobodyPrincipal();
26
27     public int hashCode()
28     {
29         return NOBODY.hashCode();
30     }
31
32     /**
33     @return "<NOBODY>"
34     */

35     public String JavaDoc getName()
36     {
37         return NOBODY;
38     }
39
40     public String JavaDoc toString()
41     {
42         return NOBODY;
43     }
44     
45     /** This method always returns 0 to indicate equality for any argument.
46     This is only meaningful when comparing against other Principal objects
47      or names of Principals.
48
49     @return false to indicate inequality for any argument.
50     */

51     public boolean equals(Object JavaDoc another)
52     {
53         return false;
54     }
55
56     /** This method always returns 1 to indicate inequality for any argument.
57     This is only meaningful when comparing against other Principal objects
58      or names of Principals.
59
60     @return 1 to indicate inequality for any argument.
61     */

62     public int compareTo(Object JavaDoc o)
63     {
64         return 1;
65     }
66
67 }
68
Popular Tags