Source Code Cross Referenced for RoleList.java in  » J2EE » fleXive » com » flexive » shared » 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 » J2EE » fleXive » com.flexive.shared.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2008
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.shared.security;
034:
035:        import com.flexive.shared.FxArrayUtils;
036:
037:        import java.io.Serializable;
038:        import java.util.ArrayList;
039:        import java.util.List;
040:        import java.util.StringTokenizer;
041:        import java.util.Arrays;
042:
043:        /**
044:         * A class for transporting and processing a list of roles.
045:         *
046:         * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
047:         */
048:        public class RoleList implements  Serializable {
049:            private static final long serialVersionUID = 9101501258624365441L;
050:
051:            private Role[] list = null;
052:
053:            /**
054:             * Constructor
055:             *
056:             * @param roles the roles in the list
057:             */
058:            public RoleList(Role[] roles) {
059:                this .list = FxArrayUtils.clone(roles);
060:            }
061:
062:            /**
063:             * Constructor
064:             *
065:             * @param roles the roles in the list
066:             */
067:            public RoleList(byte[] roles) {
068:                if (roles == null)
069:                    roles = new byte[0];
070:                list = new Role[roles.length];
071:                for (int i = 0; i < roles.length; i++) {
072:                    list[i] = Role.getById(roles[i]);
073:                }
074:            }
075:
076:            /**
077:             * Constructor for a empts role list
078:             */
079:            public RoleList() {
080:                list = new Role[0];
081:            }
082:
083:            /**
084:             * Constructor
085:             *
086:             * @param roles the roles in the list, as Integer id objects in a array list
087:             */
088:            public RoleList(ArrayList roles) {
089:                if (roles == null)
090:                    roles = new ArrayList(0);
091:                list = new Role[roles.size()];
092:                for (int i = 0; i < roles.size(); i++) {
093:                    Integer id = (Integer) roles.get(i);
094:                    list[i] = Role.getById(id);
095:                }
096:            }
097:
098:            /**
099:             * Constructs a role list from a string with the comma separated role id's.
100:             *
101:             * @param roles a list of comma separated role id's.
102:             */
103:            public RoleList(String roles) {
104:                // Handle empty strings
105:                if (roles == null || roles.length() == 0) {
106:                    list = new Role[0];
107:                    return;
108:                }
109:                // Build the list
110:                List<Role> tmp1 = new java.util.ArrayList<Role>(20);
111:                StringTokenizer st = new java.util.StringTokenizer(roles, ",",
112:                        false);
113:                while (st.hasMoreTokens()) {
114:                    String value = st.nextToken();
115:                    Role aRole = Role.getById(Integer.valueOf(value));
116:                    tmp1.add(aRole);
117:                }
118:                list = tmp1.toArray(new Role[tmp1.size()]);
119:            }
120:
121:            /**
122:             * Returns the amount of roles in the list.
123:             *
124:             * @return the amount of roles in the list
125:             */
126:            public int size() {
127:                return list.length;
128:            }
129:
130:            /**
131:             * Returns all roles in the list.
132:             *
133:             * @return all roles in the list
134:             */
135:            public Role[] getRoles() {
136:                return FxArrayUtils.clone(list);
137:            }
138:
139:            /**
140:             * Returns all roles as array list.
141:             *
142:             * @return the list
143:             */
144:            public ArrayList<Role> getList() {
145:                if (list == null || list.length == 0) {
146:                    return new ArrayList<Role>(0);
147:                }
148:                ArrayList<Role> result = new ArrayList<Role>(list.length);
149:                result.addAll(Arrays.asList(list));
150:                return result;
151:            }
152:
153:            /**
154:             * Returns the role at the given position.
155:             *
156:             * @param pos the position
157:             * @return the role at the given position
158:             */
159:            public Role get(int pos) {
160:                return this .list[pos];
161:            }
162:
163:            /**
164:             * Adds a role to the end of the list, but only if its not already part of it
165:             *
166:             * @param roleId the role to add
167:             */
168:            public void add(byte roleId) {
169:                // Check if the role is already part of the list
170:                for (Role aList : list)
171:                    if (aList.getId() == roleId)
172:                        return;
173:                // Add the role
174:                Role[] tmp = new Role[list.length + 1];
175:                System.arraycopy(list, 0, tmp, 0, list.length);
176:                tmp[tmp.length - 1] = Role.getById(roleId);
177:                list = tmp;
178:            }
179:
180:            /**
181:             * Returns a array holding the id's of all roles in the list.
182:             *
183:             * @return a array holding the id's of all roles in the list
184:             */
185:            public long[] toIdArray() {
186:                long idArr[] = new long[list.length];
187:                for (int i = 0; i < list.length; i++)
188:                    idArr[i] = list[i].getId();
189:                return idArr;
190:            }
191:
192:            /**
193:             * Returns a array holding the names of all roles in the list.
194:             *
195:             * @return a array holding the names of all roles in the list
196:             */
197:            public String[] toNameArray() {
198:                if (list == null)
199:                    return new String[0];
200:                String idArr[] = new String[list.length];
201:                for (int i = 0; i < list.length; i++)
202:                    idArr[i] = list[i].getName();
203:                return idArr;
204:            }
205:
206:            /**
207:             * Removes a role from the list.
208:             *
209:             * @param role the roles to remove from the list
210:             */
211:            public void remove(Role role) {
212:                remove(role.getId());
213:            }
214:
215:            /**
216:             * Removes groups from the list.
217:             *
218:             * @param role the groups to remove from the list
219:             */
220:            public void remove(Role role[]) {
221:                for (Role aRole : role)
222:                    remove(aRole.getId());
223:            }
224:
225:            /**
226:             * Removes role identified by the unique id from the list.
227:             *
228:             * @param roleId the role to remove from the list
229:             */
230:            public void remove(long roleId[]) {
231:                for (long aRoleId : roleId)
232:                    remove(aRoleId);
233:            }
234:
235:            /**
236:             * Removes a role identified by its unique id from the list.
237:             *
238:             * @param roleId the role to remove from the list
239:             */
240:            public void remove(long roleId) {
241:                if (list != null) {
242:                    int elementFound = 0;
243:                    while (elementFound != -1) {
244:                        // Look for the elemenet
245:                        elementFound = -1;
246:                        for (int i = 0; i < list.length; i++) {
247:                            if (list[i].getId() == roleId) {
248:                                elementFound = i;
249:                                break;
250:                            }
251:                        }
252:                        // Delete the element
253:                        if (elementFound != -1) {
254:                            Role tmp[] = new Role[list.length - 1];
255:                            int pos = 0;
256:                            for (int i = 0; i < list.length; i++) {
257:                                if (i != elementFound)
258:                                    tmp[pos++] = list[i];
259:                            }
260:                            list = tmp;
261:                        }
262:                    }
263:                }
264:            }
265:
266:            /**
267:             * Returns a string representation of the roles.
268:             *
269:             * @return a string representation of the roles
270:             */
271:            @Override
272:            public String toString() {
273:                return RoleList.class + "@[" + toNameString() + "]";
274:            }
275:
276:            /**
277:             * Returns a comma seperated list of the role names.
278:             *
279:             * @return a comma seperated list of the role names.
280:             */
281:            public String toNameString() {
282:                StringBuilder result = new StringBuilder(50);
283:                for (Role entry : list) {
284:                    if (result.length() > 0)
285:                        result.append(',');
286:                    result.append(entry.getName());
287:                }
288:                return result.toString();
289:            }
290:
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.