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