Source Code Cross Referenced for PermissionSet.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.Permission;
028:
029:        /**
030:         * This class represents a set of Permissions.  It makes it easy to
031:         * build a UI that would allow someone to add a group of Permissions
032:         * to a Role.  It enforces that only
033:         * Permission objects are allowed in the set and only relevant methods
034:         * are available.
035:         *
036:         * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
037:         * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
038:         * @author <a href="mailto:marco@intermeta.de">Marco Kn&uuml;ttel</a>
039:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
040:         * @version $Id: PermissionSet.java 534527 2007-05-02 16:10:59Z tv $
041:         */
042:        public class PermissionSet extends SecuritySet {
043:            /** Serial Version UID */
044:            private static final long serialVersionUID = 8276935936763076884L;
045:
046:            /**
047:             * Constructs an empty PermissionSet
048:             */
049:            public PermissionSet() {
050:                super ();
051:            }
052:
053:            /**
054:             * Constructs a new PermissionSet with specified contents.
055:             *
056:             * If the given collection contains multiple objects that are
057:             * identical WRT equals() method, some objects will be overwritten.
058:             *
059:             * @param permissions A collection of permissions to be contained in the set.
060:             */
061:            public PermissionSet(Collection permissions) {
062:                super ();
063:                add(permissions);
064:            }
065:
066:            /**
067:             * Adds a Permission to this PermissionSet.
068:             *
069:             * @param permission A Permission.
070:             * @return True if Permission was added; false if PermissionSet
071:             * already contained the Permission.
072:             */
073:            public boolean add(Permission permission) {
074:                boolean res = contains(permission);
075:                nameMap.put(permission.getName(), permission);
076:                idMap.put(permission.getIdAsObj(), permission);
077:                return res;
078:            }
079:
080:            /**
081:             * Adds the Permissions in a Collection to this PermissionSet.
082:             *
083:             * @param permissions A Collection of Permissions.
084:             * @return True if this PermissionSet changed as a result; false
085:             * if no change to this PermissionSet occurred (this PermissionSet
086:             * already contained all members of the added PermissionSet).
087:             */
088:            public boolean add(Collection permissions) {
089:                boolean res = false;
090:                for (Iterator it = permissions.iterator(); it.hasNext();) {
091:                    Permission p = (Permission) it.next();
092:                    res |= add(p);
093:                }
094:                return res;
095:            }
096:
097:            /**
098:             * Adds the Permissions in another PermissionSet to this
099:             * PermissionSet.
100:             *
101:             * @param permissionSet A PermissionSet.
102:             * @return True if this PermissionSet changed as a result; false
103:             * if no change to this PermissionSet occurred (this PermissionSet
104:             * already contained all members of the added PermissionSet).
105:             */
106:            public boolean add(PermissionSet permissionSet) {
107:                boolean res = false;
108:                for (Iterator it = permissionSet.iterator(); it.hasNext();) {
109:                    Permission p = (Permission) it.next();
110:                    res |= add(p);
111:                }
112:                return res;
113:            }
114:
115:            /**
116:             * Removes a Permission from this PermissionSet.
117:             *
118:             * @param permission A Permission.
119:             * @return True if this PermissionSet contained the Permission
120:             * before it was removed.
121:             */
122:            public boolean remove(Permission permission) {
123:                boolean res = contains(permission);
124:                nameMap.remove(permission.getName());
125:                idMap.remove(permission.getIdAsObj());
126:                return res;
127:            }
128:
129:            /**
130:             * Checks whether this PermissionSet contains a Permission.
131:             *
132:             * @param permission A Permission.
133:             * @return True if this PermissionSet contains the Permission,
134:             * false otherwise.
135:             */
136:            public boolean contains(Permission permission) {
137:                return nameMap.containsValue((Object) permission);
138:            }
139:
140:            /**
141:             * Returns a Permission with the given name, if it is contained in
142:             * this PermissionSet.
143:             *
144:             * @param permissionName Name of Permission.
145:             * @return Permission if argument matched a Permission in this
146:             * PermissionSet; null if no match.
147:             * @deprecated Use <a href="#getPermissionByName">getPermissionByName</a> instead.
148:             */
149:            public Permission getPermission(String permissionName) {
150:                return getPermissionByName(permissionName);
151:            }
152:
153:            /**
154:             * Returns a Permission with the given name, if it is contained in
155:             * this PermissionSet.
156:             *
157:             * @param permissionName Name of Permission.
158:             * @return Permission if argument matched a Permission in this
159:             * PermissionSet; null if no match.
160:             */
161:            public Permission getPermissionByName(String permissionName) {
162:                return (StringUtils.isNotEmpty(permissionName)) ? (Permission) nameMap
163:                        .get(permissionName)
164:                        : null;
165:            }
166:
167:            /**
168:             * Returns a Permission with the given id, if it is contained in
169:             * this PermissionSet.
170:             *
171:             * @param permissionId Id of the Permission.
172:             * @return Permission if argument matched a Permission in this
173:             * PermissionSet; null if no match.
174:             */
175:            public Permission getPermissionById(int permissionId) {
176:                return (permissionId != 0) ? (Permission) idMap
177:                        .get(new Integer(permissionId)) : null;
178:            }
179:
180:            /**
181:             * Returns an Array of Permissions in this PermissionSet.
182:             *
183:             * @return An Array of Permission Objects.
184:             */
185:            public Permission[] getPermissionsArray() {
186:                return (Permission[]) getSet().toArray(new Permission[0]);
187:            }
188:
189:            /**
190:             * Print out a PermissionSet as a String
191:             *
192:             * @returns The Permission Set as String
193:             *
194:             */
195:            public String toString() {
196:                StringBuffer sb = new StringBuffer();
197:                sb.append("PermissionSet: ");
198:
199:                for (Iterator it = iterator(); it.hasNext();) {
200:                    Permission p = (Permission) it.next();
201:                    sb.append('[');
202:                    sb.append(p.getName());
203:                    sb.append(" -> ");
204:                    sb.append(p.getIdAsObj());
205:                    sb.append(']');
206:                    if (it.hasNext()) {
207:                        sb.append(", ");
208:                    }
209:                }
210:
211:                return sb.toString();
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.