Source Code Cross Referenced for RoleSet.java in  » Web-Framework » TURBINE » org » apache » turbine » util » 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 » Web Framework » TURBINE » org.apache.turbine.util.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.util.security;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.util.Collection;
023:        import java.util.Iterator;
024:
025:        import org.apache.commons.lang.StringUtils;
026:
027:        import org.apache.turbine.om.security.Role;
028:
029:        /**
030:         * This class represents a set of Roles.  It makes it easy to build a
031:         * UI that would allow someone to add a group of Roles to a User.
032:         * It enforces that only Role objects are
033:         * allowed in the set and only relevant methods are available.
034:         *
035:         * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
036:         * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
037:         * @author <a href="mailto:marco@intermeta.de">Marco Kn&uuml;ttel</a>
038:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
039:         * @version $Id: RoleSet.java 534527 2007-05-02 16:10:59Z tv $
040:         */
041:        public class RoleSet extends SecuritySet {
042:            /** Serial Version UID */
043:            private static final long serialVersionUID = -5521518890129125912L;
044:
045:            /**
046:             * Constructs an empty RoleSet
047:             */
048:            public RoleSet() {
049:                super ();
050:            }
051:
052:            /**
053:             * Constructs a new RoleSet with specified contents.
054:             *
055:             * If the given collection contains multiple objects that are
056:             * identical WRT equals() method, some objects will be overwritten.
057:             *
058:             * @param roles A collection of roles to be contained in the set.
059:             */
060:            public RoleSet(Collection roles) {
061:                super ();
062:                add(roles);
063:            }
064:
065:            /**
066:             * Adds a Role to this RoleSet.
067:             *
068:             * @param role A Role.
069:             * @return True if Role was added; false if RoleSet already
070:             * contained the Role.
071:             */
072:            public boolean add(Role role) {
073:                boolean res = contains(role);
074:                nameMap.put(role.getName(), role);
075:                idMap.put(role.getIdAsObj(), role);
076:                return res;
077:            }
078:
079:            /**
080:             * Adds the Roles in a Collection to this RoleSet.
081:             *
082:             * @param roles A Collection of Roles.
083:             * @return True if this RoleSet changed as a result; false
084:             * if no change to this RoleSet occurred (this RoleSet
085:             * already contained all members of the added RoleSet).
086:             */
087:            public boolean add(Collection roles) {
088:                boolean res = false;
089:                for (Iterator it = roles.iterator(); it.hasNext();) {
090:                    Role r = (Role) it.next();
091:                    res |= add(r);
092:                }
093:                return res;
094:            }
095:
096:            /**
097:             * Adds the Roles in another RoleSet to this RoleSet.
098:             *
099:             * @param roleSet A RoleSet.
100:             * @return True if this RoleSet changed as a result; false
101:             * if no change to this RoleSet occurred (this RoleSet
102:             * already contained all members of the added RoleSet).
103:             */
104:            public boolean add(RoleSet roleSet) {
105:                boolean res = false;
106:                for (Iterator it = roleSet.iterator(); it.hasNext();) {
107:                    Role r = (Role) it.next();
108:                    res |= add(r);
109:                }
110:                return res;
111:            }
112:
113:            /**
114:             * Removes a Role from this RoleSet.
115:             *
116:             * @param role A Role.
117:             * @return True if this RoleSet contained the Role
118:             * before it was removed.
119:             */
120:            public boolean remove(Role role) {
121:                boolean res = contains(role);
122:                nameMap.remove(role.getName());
123:                idMap.remove(role.getIdAsObj());
124:                return res;
125:            }
126:
127:            /**
128:             * Checks whether this RoleSet contains a Role.
129:             *
130:             * @param role A Role.
131:             * @return True if this RoleSet contains the Role,
132:             * false otherwise.
133:             */
134:            public boolean contains(Role role) {
135:                return nameMap.containsValue((Object) role);
136:            }
137:
138:            /**
139:             * Returns a Role with the given name, if it is contained in
140:             * this RoleSet.
141:             *
142:             * @param roleName Name of Role.
143:             * @return Role if argument matched a Role in this
144:             * RoleSet; null if no match.
145:             * @deprecated Use <a href="#getRoleByName">getRoleByName</a> instead.
146:             */
147:            public Role getRole(String roleName) {
148:                return getRoleByName(roleName);
149:            }
150:
151:            /**
152:             * Returns a Role with the given name, if it is contained in
153:             * this RoleSet.
154:             *
155:             * @param roleName Name of Role.
156:             * @return Role if argument matched a Role in this
157:             * RoleSet; null if no match.
158:             */
159:            public Role getRoleByName(String roleName) {
160:                return (StringUtils.isNotEmpty(roleName)) ? (Role) nameMap
161:                        .get(roleName) : null;
162:            }
163:
164:            /**
165:             * Returns a Role with the given id, if it is contained in this
166:             * RoleSet.
167:             *
168:             * @param roleId id of the Role.
169:             * @return Role if argument matched a Role in this RoleSet; null
170:             * if no match.
171:             */
172:            public Role getRoleById(int roleId) {
173:                return (roleId != 0) ? (Role) idMap.get(new Integer(roleId))
174:                        : null;
175:            }
176:
177:            /**
178:             * Returns an Array of Roles in this RoleSet.
179:             *
180:             * @return An Array of Role objects.
181:             */
182:            public Role[] getRolesArray() {
183:                return (Role[]) getSet().toArray(new Role[0]);
184:            }
185:
186:            /**
187:             * Print out a RoleSet as a String
188:             *
189:             * @returns The Role Set as String
190:             *
191:             */
192:            public String toString() {
193:                StringBuffer sb = new StringBuffer();
194:                sb.append("RoleSet: ");
195:
196:                for (Iterator it = iterator(); it.hasNext();) {
197:                    Role r = (Role) it.next();
198:                    sb.append('[');
199:                    sb.append(r.getName());
200:                    sb.append(" -> ");
201:                    sb.append(r.getIdAsObj());
202:                    sb.append(']');
203:                    if (it.hasNext()) {
204:                        sb.append(", ");
205:                    }
206:                }
207:
208:                return sb.toString();
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.