Source Code Cross Referenced for Rank.java in  » Database-ORM » MMBase » org » mmbase » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » MMBase » org.mmbase.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.security;
011:
012:        import org.mmbase.util.HashCodeUtil;
013:        import org.mmbase.util.logging.Logger;
014:        import org.mmbase.util.logging.Logging;
015:        import java.util.*;
016:
017:        /**
018:         * This class defines Rank objects which are used in security implementation. Ranks can be
019:         * associated with users. Every Rank has an unique integer 'height' (so every rank is higher or
020:         * lower than any other rank) and a String which can be used to identify it.
021:         *
022:         * Possible Ranks are maintained by static methods in this class. Generally the 'anonymous', 'basic
023:         * user' and 'adminstrator' ranks should always be available, and only be delete with good reason.
024:         *
025:         *
026:         * @author Eduard Witteveen
027:         * @author Pierre van Rooden
028:         * @author Michiel Meeuwissen
029:         * @version $Id: Rank.java,v 1.18 2008/01/21 15:25:28 michiel Exp $
030:         */
031:        public final class Rank implements  Comparable<Rank>,
032:                java.io.Serializable {
033:
034:            private static Logger log = Logging.getLoggerInstance(Rank.class);
035:
036:            private static final int serialVersionUID = 1; // increase this if object chages.
037:
038:            /** int value for the anonymous Rank*/
039:            public final static int ANONYMOUS_INT = 0;
040:
041:            /** int value for the basic user Rank*/
042:            public final static int BASICUSER_INT = 100;
043:
044:            /** int value for the anonymous Rank*/
045:            public final static int ADMIN_INT = 73059;
046:
047:            /** Identifier for anonymous rank*/
048:            public final static Rank ANONYMOUS = new Rank(ANONYMOUS_INT,
049:                    "anonymous");
050:
051:            /** Identifier for basic user rank*/
052:            public final static Rank BASICUSER = new Rank(BASICUSER_INT,
053:                    "basic user");
054:
055:            /** Identifier for admin rank*/
056:            public final static Rank ADMIN = new Rank(ADMIN_INT,
057:                    "administrator");
058:
059:            private static Map<String, Rank> ranks = new HashMap();
060:
061:            static {
062:                registerRank(ANONYMOUS);
063:                registerRank(BASICUSER);
064:                registerRank(ADMIN);
065:            }
066:
067:            /**
068:             *	constructor
069:             */
070:            protected Rank(int rank, String description) {
071:                this .rank = rank;
072:                this .description = description;
073:            }
074:
075:            /**
076:             *	This method gives back the internal int value of the rank
077:             *	which can be used in switch statements
078:             *	@return the internal int value
079:             */
080:            public int getInt() {
081:                return rank;
082:            }
083:
084:            /**
085:             *	@return a string containing the description of the rank
086:             */
087:            public String toString() {
088:                return description;
089:            }
090:
091:            /** the int value of the instance */
092:            private int rank;
093:
094:            /** the description of this rank */
095:            private String description;
096:
097:            public static Rank getRank(String rankDesc) {
098:                return ranks.get(rankDesc);
099:            }
100:
101:            /**
102:             * @since MMBase-1.6.4
103:             */
104:            protected static Rank registerRank(Rank rank) {
105:                Rank prev = ranks.put(rank.toString(), rank);
106:                if (prev == null) {
107:                    log.service("Registered rank " + rank);
108:                } else {
109:                    log.service("Replaced rank " + rank);
110:                }
111:                return prev;
112:            }
113:
114:            /**
115:             * Creates and adds a new Rank for the security system.
116:             *
117:             * @since MMBase-1.6.4
118:             */
119:
120:            public static Rank createRank(int rank, String rankDesc) {
121:                Rank rankObject = new Rank(rank, rankDesc);
122:                registerRank(rankObject);
123:                return rankObject;
124:            }
125:
126:            /**
127:             * Removes a rank from the security system.
128:             * @since MMBase-1.6.4
129:             */
130:
131:            public static Rank deleteRank(String rankDesc) {
132:                return ranks.remove(rankDesc);
133:            }
134:
135:            /**
136:             * Returns all ranks currently known by the security implemetation.  Default and to start with there
137:             * are three ranks available: 'anonymous', 'basic user' and 'administrator'.  You probably
138:             * should never remove them.
139:             * @since MMBase-1.6.4
140:             */
141:            public static SortedSet<Rank> getRanks() {
142:                return new TreeSet<Rank>(ranks.values());
143:            }
144:
145:            /**
146:             * @since MMBase-1.6.4
147:             */
148:            // see javadoc of Object
149:            public boolean equals(Object o) {
150:                if (o instanceof  Rank) {
151:                    Rank r = (Rank) o;
152:                    return r.rank == rank && r.description.equals(description);
153:                } else {
154:                    return false;
155:                }
156:            }
157:
158:            /**
159:             * @see java.lang.Object#hashCode()
160:             */
161:            public int hashCode() {
162:                int result = 0;
163:                result = HashCodeUtil.hashCode(result, rank);
164:                result = HashCodeUtil.hashCode(result, description);
165:                return result;
166:            }
167:
168:            /**
169:             * @since MMBase-1.6.4
170:             */
171:            // see javadoc of Comparable
172:            public int compareTo(Rank r) {
173:                return rank - r.rank;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.