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