Source Code Cross Referenced for RoleValidator.java in  » EJB-Server-JBoss-4.2.1 » jmx » javax » management » relation » 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 » EJB Server JBoss 4.2.1 » jmx » javax.management.relation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package javax.management.relation;
023:
024:        import java.util.ArrayList;
025:        import java.util.HashSet;
026:        import java.util.Iterator;
027:
028:        import javax.management.MBeanServer;
029:        import javax.management.MBeanException;
030:        import javax.management.ObjectName;
031:
032:        /**
033:         * This is a helper class for performing role validation. It is used by
034:         * both the RelationSupport and RelationService classes.<p>
035:         *
036:         * It is package private and NOT part of the specification.
037:         *
038:         * <p><b>Revisions:</b>
039:         * <p><b>20020311 Adrian Brock:</b>
040:         * <ul>
041:         * <li>ValidateRole always failed
042:         * <li>Throws wrong exception when not writable
043:         * </ul>
044:         *
045:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
046:         * @version $Revision: 57200 $
047:         *
048:         */
049:        class RoleValidator {
050:            // Constants ---------------------------------------------------
051:
052:            // Static ------------------------------------------------------
053:
054:            /**
055:             * Check a role for a relation type
056:             *
057:             * @param relationService the relation service object name
058:             * @param server the MBeanServer of the relation service
059:             * @param relationTypeName the relation to validate against
060:             * @param role the role to validate
061:             * @param write pass to true to check for a writable role
062:             * @return zero for success or a RoleStatus value for failure
063:             * @exception RelationTypeNotFoundException when the relation type
064:             *            does not exist in the relation service
065:             */
066:            public static int checkRole(ObjectName relationService,
067:                    MBeanServer server, String relationTypeName, Role role,
068:                    boolean write) throws RelationTypeNotFoundException {
069:                // Get the role information
070:                RoleInfo roleInfo = null;
071:                try {
072:                    roleInfo = (RoleInfo) server.invoke(relationService,
073:                            "getRoleInfo", new Object[] { relationTypeName,
074:                                    role.getRoleName() }, new String[] {
075:                                    "java.lang.String", "java.lang.String" });
076:                } catch (MBeanException mbe) {
077:                    Exception e = mbe.getTargetException();
078:                    if (e instanceof  RelationTypeNotFoundException)
079:                        throw (RelationTypeNotFoundException) e;
080:                    if (e instanceof  RoleInfoNotFoundException)
081:                        return RoleStatus.NO_ROLE_WITH_NAME;
082:                    throw new RuntimeException(e.toString());
083:                } catch (Exception e) {
084:                    throw new RuntimeException(e.toString());
085:                }
086:
087:                // Check if the role is writable
088:                if (write == true && roleInfo.isWritable() == false)
089:                    return RoleStatus.ROLE_NOT_WRITABLE;
090:
091:                // Check the cardinality of the role
092:                ArrayList mbeans = (ArrayList) role.getRoleValue();
093:                int beanCount = mbeans.size();
094:                int minimum = roleInfo.getMinDegree();
095:                if (minimum != RoleInfo.ROLE_CARDINALITY_INFINITY
096:                        && minimum > beanCount)
097:                    return RoleStatus.LESS_THAN_MIN_ROLE_DEGREE;
098:                int maximum = roleInfo.getMaxDegree();
099:                if (maximum != RoleInfo.ROLE_CARDINALITY_INFINITY
100:                        && maximum < beanCount)
101:                    return RoleStatus.MORE_THAN_MAX_ROLE_DEGREE;
102:
103:                // Check the MBeans
104:                String className = roleInfo.getRefMBeanClassName();
105:                Iterator iterator = mbeans.iterator();
106:                while (iterator.hasNext()) {
107:                    try {
108:                        ObjectName objectName = (ObjectName) iterator.next();
109:                        if (server.isInstanceOf(objectName, className) == false)
110:                            return RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS;
111:                    } catch (Exception e) {
112:                        return RoleStatus.REF_MBEAN_NOT_REGISTERED;
113:                    }
114:                }
115:                // All done
116:                return 0;
117:            }
118:
119:            /**
120:             * Check the Roles for a relation Type.
121:             *
122:             * @param relationService the relation service object name
123:             * @param server the MBeanServer of the relation service
124:             * @param relationTypeName the relation to validate against
125:             * @param roleList the roles to validate
126:             * @param write pass to true to check for a writable role
127:             * @return a RoleResult containing resolved and unresolved roles
128:             * @exception RelationTypeNotFoundException when the relation type
129:             *            does not exist in the relation service
130:             */
131:            public static RoleResult checkRoles(ObjectName relationService,
132:                    MBeanServer server, String relationTypeName,
133:                    RoleList roleList, boolean write)
134:                    throws RelationTypeNotFoundException {
135:                // Set up the return value
136:                RoleList resolved = new RoleList();
137:                RoleUnresolvedList unresolved = new RoleUnresolvedList();
138:                RoleResult result = new RoleResult(resolved, unresolved);
139:
140:                // Check each role
141:                Iterator iterator = roleList.iterator();
142:                while (iterator.hasNext()) {
143:                    Role role = (Role) iterator.next();
144:                    int status = checkRole(relationService, server,
145:                            relationTypeName, role, write);
146:                    if (status == 0)
147:                        resolved.add(role);
148:                    else
149:                        unresolved.add(new RoleUnresolved(role.getRoleName(),
150:                                role.getRoleValue(), status));
151:                }
152:                // All Done
153:                return result;
154:            }
155:
156:            /**
157:             * Validate a role for a relation Type.
158:             *
159:             * @param relationService the relation service object name
160:             * @param server the MBeanServer of the relation service
161:             * @param relationTypeName the relation to validate against
162:             * @param role the role to validate
163:             * @param write pass to true to check for a writable role
164:             * @exception InvalidRoleValueException when a role does not match its 
165:             *            definition in the relation type's roleinfos
166:             * @exception RelationTypeNotFoundException when the relation type
167:             *            does not exist in the relation service
168:             * @exception RoleNotFoundException when a role does not exist
169:             *            in the role
170:             */
171:            public static void validateRole(ObjectName relationService,
172:                    MBeanServer server, String relationTypeName, Role role,
173:                    boolean write) throws InvalidRoleValueException,
174:                    RelationTypeNotFoundException, RoleNotFoundException {
175:                int status = checkRole(relationService, server,
176:                        relationTypeName, role, write);
177:
178:                if (status == RoleStatus.NO_ROLE_WITH_NAME)
179:                    throw new RoleNotFoundException(role.getRoleName());
180:                if (status == RoleStatus.ROLE_NOT_WRITABLE)
181:                    throw new RoleNotFoundException(role.getRoleName()
182:                            + " not writable");
183:                else if (status != 0)
184:                    throw new InvalidRoleValueException(role.getRoleName());
185:            }
186:
187:            /**
188:             * Validate the Roles for a relation Type.
189:             *
190:             * @param relationService the relation service object name
191:             * @param server the MBeanServer of the relation service
192:             * @param relationTypeName the relation to validate against
193:             * @param roleList the roles to validate
194:             * @param write pass to true to check for a writable role
195:             * @exception InvalidRoleValueException when there is a duplicate role name
196:             *            or a role does not match its definition in the 
197:             *            relation type's roleinfos
198:             * @exception RelationTypeNotFoundException when the relation type
199:             *            does not exist in the relation service
200:             * @exception RoleNotFoundException when a role does not exist
201:             *            in the role
202:             */
203:            public static void validateRoles(ObjectName relationService,
204:                    MBeanServer server, String relationTypeName,
205:                    RoleList roleList, boolean write)
206:                    throws InvalidRoleValueException,
207:                    RelationTypeNotFoundException, RoleNotFoundException {
208:                Iterator iterator;
209:
210:                // Check for duplicate roles
211:                HashSet roleNames = new HashSet();
212:                iterator = roleList.iterator();
213:                while (iterator.hasNext()) {
214:                    Object roleName = iterator.next();
215:                    if (roleNames.contains(roleName))
216:                        throw new InvalidRoleValueException("Duplicate role "
217:                                + roleName);
218:                    roleNames.add(roleName);
219:                }
220:
221:                // Check the roles
222:                RoleResult result = checkRoles(relationService, server,
223:                        relationTypeName, roleList, write);
224:                RoleUnresolvedList errors = result.getRolesUnresolved();
225:                iterator = errors.iterator();
226:                if (iterator.hasNext()) {
227:                    RoleUnresolved unresolved = (RoleUnresolved) iterator
228:                            .next();
229:                    int status = unresolved.getProblemType();
230:                    if (status == RoleStatus.NO_ROLE_WITH_NAME)
231:                        throw new RoleNotFoundException(unresolved
232:                                .getRoleName());
233:                    if (status == RoleStatus.ROLE_NOT_WRITABLE)
234:                        throw new RoleNotFoundException(unresolved
235:                                .getRoleName()
236:                                + " not writable");
237:                    else
238:                        throw new InvalidRoleValueException(unresolved
239:                                .getRoleName());
240:                }
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.