Source Code Cross Referenced for ModulesRepository.java in  » Testing » unitils » org » unitils » core » 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 » Testing » unitils » org.unitils.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007,  Unitils.org
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.unitils.core;
017:
018:        import static org.unitils.util.ReflectionUtils.getClassWithName;
019:
020:        import java.util.ArrayList;
021:        import java.util.HashMap;
022:        import java.util.List;
023:        import java.util.Map;
024:
025:        /**
026:         * A class for holding and retrieving modules.
027:         *
028:         * @author Tim Ducheyne
029:         * @author Filip Neven
030:         */
031:        public class ModulesRepository {
032:
033:            /* All modules */
034:            private List<Module> modules;
035:
036:            /* A map containing the test listeners of each module */
037:            private Map<Module, TestListener> testListeners;
038:
039:            /**
040:             * Creates a repository containing the given modules.
041:             *
042:             * @param modules the modules, not null
043:             */
044:            public ModulesRepository(List<Module> modules) {
045:                this .modules = modules;
046:                this .testListeners = createTestListeners(modules);
047:            }
048:
049:            /**
050:             * Gets all modules.
051:             *
052:             * @return the modules, not null
053:             */
054:            public List<Module> getModules() {
055:                return modules;
056:            }
057:
058:            /**
059:             * Gets all listeners.
060:             *
061:             * @return the listeners per module, not null
062:             */
063:            public Map<Module, TestListener> getTestListeners() {
064:                return testListeners;
065:            }
066:
067:            /**
068:             * Gets the modules that is of the given type or a sub-type.
069:             * A UnitilsException is thrown when there is not exactly 1 possible match.
070:             *
071:             * @param <T>  The module type
072:             * @param type the module type, not null
073:             * @return the module, not null
074:             */
075:            public <T extends Module> T getModuleOfType(Class<T> type) {
076:                List<T> modulesOfType = getModulesOfType(type);
077:                if (modulesOfType.size() > 1) {
078:                    throw new UnitilsException(
079:                            "More than one module found of type "
080:                                    + type.getName());
081:                }
082:                if (modulesOfType.size() < 1) {
083:                    throw new UnitilsException("No module found of type "
084:                            + type.getName());
085:                }
086:                return modulesOfType.get(0);
087:            }
088:
089:            /**
090:             * Gets all modules that are of the given type or a sub-type.
091:             *
092:             * @param <T>  The module type
093:             * @param type the type, not null
094:             * @return the modules, an empty list if none found
095:             */
096:            @SuppressWarnings({"unchecked"})
097:            public <T> List<T> getModulesOfType(Class<T> type) {
098:                List<T> result = new ArrayList<T>();
099:                for (Module module : modules) {
100:                    if (type.isAssignableFrom(module.getClass())) {
101:                        result.add((T) module);
102:                    }
103:                }
104:                return result;
105:            }
106:
107:            /**
108:             * Checks whether a module of a type with the given class name exists. The class name can also be
109:             * the super-type of an existing module.
110:             *
111:             * @param fullyQualifiedClassName The class name, not null
112:             * @return True if the module exists and is enabled
113:             */
114:            @SuppressWarnings("unchecked")
115:            public boolean isModuleEnabled(String fullyQualifiedClassName) {
116:                Class<? extends Module> moduleClass;
117:                try {
118:                    moduleClass = (Class<? extends Module>) getClassWithName(fullyQualifiedClassName);
119:
120:                } catch (UnitilsException e) {
121:                    // class could not be loaded
122:                    return false;
123:                }
124:                return isModuleEnabled(moduleClass);
125:            }
126:
127:            /**
128:             * Checks whether a module of a type exists. The class an also be the super-type of an existing module.
129:             *
130:             * @param moduleClass The class, not null
131:             * @return True if the module exists and is enabled
132:             */
133:            public boolean isModuleEnabled(Class<? extends Module> moduleClass) {
134:                List<? extends Module> modulesOfType = getModulesOfType(moduleClass);
135:                if (modulesOfType.size() > 1) {
136:                    throw new UnitilsException(
137:                            "More than one module found of type "
138:                                    + moduleClass.getName());
139:                }
140:                return modulesOfType.size() == 1;
141:            }
142:
143:            /**
144:             * Gets the listener corresponding to the given module.
145:             *
146:             * @param module the module, not null
147:             * @return the listener, null if the module could not be found
148:             */
149:            public TestListener getTestListener(Module module) {
150:                return testListeners.get(module);
151:            }
152:
153:            /**
154:             * Creates test listeners for each of the given modules.
155:             *
156:             * @param moduleList the modules, not null
157:             * @return the listeners for each module, not null
158:             */
159:            private Map<Module, TestListener> createTestListeners(
160:                    List<Module> moduleList) {
161:                Map<Module, TestListener> result = new HashMap<Module, TestListener>(
162:                        moduleList.size());
163:                for (Module module : moduleList) {
164:                    result.put(module, module.createTestListener());
165:                }
166:                return result;
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.