Source Code Cross Referenced for RelationTypeSupport.java in  » JMX » jfoxmx » 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 » JMX » jfoxmx » javax.management.relation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.org
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package javax.management.relation;
009:
010:        import java.util.HashMap;
011:        import java.util.List;
012:        import java.util.ArrayList;
013:        import java.util.Map;
014:
015:        /**
016:         * A RelationTypeSupport object implements the RelationType interface.
017:         * <P>It represents a relation type, providing role information for each role
018:         * expected to be supported in every relation of that type.
019:         *
020:         * <P>A relation type includes a relation type name and a list of
021:         * role infos (represented by RoleInfo objects).
022:         *
023:         * <P>A relation type has to be declared in the Relation Service:
024:         * <P>- either using the createRelationType() method, where a RelationTypeSupport
025:         * object will be created and kept in the Relation Service
026:         * <P>- either using the addRelationType() method where the user has to doCreate
027:         * an object implementing the RelationType interface, and this object will be
028:         * used as representing a relation type in the Relation Service.
029:         *
030:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
031:         */
032:
033:        public class RelationTypeSupport implements  RelationType {
034:
035:            // Name
036:            private String name = null;
037:
038:            // HashMap mapping <role name (String)> -> <role info (RoleInfo object)>
039:            private Map roleInfoMap = new HashMap();
040:
041:            // Flag to specify whether the relation type has been declared in the
042:            // Relation Service (so can no longer be updated)
043:            private boolean isInRelationService = false;
044:
045:            /**
046:             * Constructor where all role definitions are dynamically created and
047:             * passed as parameter.
048:             *
049:             * @param relationTypeName  Name of relation type
050:             * @param roleInfoArray  List of role definitions (RoleInfo objects)
051:             *
052:             * @exception IllegalArgumentException  if null parameter
053:             * @exception InvalidRelationTypeException  if:
054:             * <P>- the same name has been used for two different roles
055:             * <P>- no role info provided
056:             * <P>- one null role info provided
057:             */
058:            public RelationTypeSupport(String relationTypeName,
059:                    RoleInfo[] roleInfoArray) throws IllegalArgumentException,
060:                    InvalidRelationTypeException {
061:                if (relationTypeName == null || roleInfoArray == null
062:                        || roleInfoArray.length == 0) {
063:                    throw new IllegalArgumentException(
064:                            "Invalid parameter: relationTypeName and roleInfo can not be null or empty");
065:                }
066:                name = relationTypeName;
067:                roleInfoMap = _constructRoleInfoMap(roleInfoArray);// Can throw InvalidRelationTypeException, ClassNotFoundException
068:            }
069:
070:            // Constructor to be used when creating an instance of a subclass
071:            //
072:            // -param relationTypeName  Name of relation type
073:            //
074:            // -exception IllegalArgumentException  if null parameter
075:            protected RelationTypeSupport(String relationTypeName) {
076:                if (relationTypeName == null) {
077:                    throw new IllegalArgumentException(
078:                            "Invalid parameter: relationTypeName can not be null");
079:                }
080:                name = relationTypeName;
081:            }
082:
083:            /**
084:             * Returns the relation type name
085:             */
086:            public String getRelationTypeName() {
087:                return name;
088:            }
089:
090:            /**
091:             * Returns the list of role definitions (ArrayList of RoleInfo objects).
092:             */
093:            public List getRoleInfos() {
094:                return new ArrayList(roleInfoMap.values());
095:            }
096:
097:            /**
098:             * Returns the role info (RoleInfo object) for the given role info name
099:             * (null if not found).
100:             *
101:             * @param roleName  role info name
102:             *
103:             * @return RoleInfo object providing role definition
104:             * does not exist
105:             *
106:             * @exception IllegalArgumentException  if null parameter
107:             * @exception RoleInfoNotFoundException  if no role info with that name in
108:             * relation type.
109:             */
110:            public RoleInfo getRoleInfo(String roleName)
111:                    throws IllegalArgumentException, RoleInfoNotFoundException {
112:                if (roleName == null) {
113:                    throw new IllegalArgumentException(
114:                            "Invalid parameter: roleName can not be null");
115:                }
116:
117:                // No null RoleInfo allowed, so use get()
118:                RoleInfo roleInfo = (RoleInfo) (roleInfoMap.get(roleName));
119:
120:                if (roleInfo == null) {
121:                    throw new RoleInfoNotFoundException(
122:                            "No role info for role " + roleName);
123:                }
124:                return roleInfo;
125:            }
126:
127:            // Adds a role info
128:            // This method of course shall not be used after the creation of the
129:            // relation type, because updating it would invalidate that the relations
130:            // created associated to that type still conform to it.
131:            // Can throw a RuntimeException if trying to update a relation type
132:            // decalred in the Relation Service.
133:            //
134:            // -param roleInfo  role info to be added
135:            //
136:            // -exception IllegalArgumentException  if null parameter
137:            // -exception InvalidRelationTypeException  if there is already a role
138:            //  info in current relation type with the same name
139:            protected void addRoleInfo(RoleInfo roleInfo)
140:                    throws IllegalArgumentException,
141:                    InvalidRelationTypeException {
142:
143:                if (roleInfo == null) {
144:                    throw new IllegalArgumentException(
145:                            "Invalid parameter: roleInfo can not be null");
146:                }
147:
148:                if (isInRelationService) {
149:                    throw new RuntimeException(
150:                            "Relation type cannot be updated as it is declared in the Relation Service.");
151:                }
152:
153:                String roleName = roleInfo.getName();
154:
155:                // Checks if the role info has already been described
156:                if (roleInfoMap.containsKey(roleName)) {
157:                    throw new InvalidRelationTypeException(
158:                            "Two role infos provided for role: " + roleInfo);
159:                }
160:                roleInfoMap.put(roleName, roleInfo);
161:
162:            }
163:
164:            // Sets the internal flag to specify that the relation type has been
165:            // declared in the Relation Service
166:            void setRelationServiceFlag(boolean flag) {
167:                isInRelationService = flag;
168:            }
169:
170:            // check the roleInfoArray then construct it to roleInfoMap
171:            private Map _constructRoleInfoMap(RoleInfo[] roleInfoArray)
172:                    throws IllegalArgumentException,
173:                    InvalidRelationTypeException {
174:                Map _roleInfoMap = new HashMap();
175:                for (int i = 0; i < roleInfoArray.length; i++) {
176:                    RoleInfo roleInfo = roleInfoArray[i];
177:                    if (roleInfo == null) {
178:                        throw new InvalidRelationTypeException(
179:                                "Null role info provided at index " + i
180:                                        + " of roleInfoArray " + roleInfoArray);
181:                    }
182:
183:                    String roleName = roleInfo.getName();
184:                    if (_roleInfoMap.containsKey(roleName)) {
185:                        throw new InvalidRelationTypeException(
186:                                "Two role infos provided for role " + roleInfo);
187:                    }
188:                    _roleInfoMap.put(roleName, roleInfo);
189:                }
190:
191:                return _roleInfoMap;
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.