Source Code Cross Referenced for TranslationTestDiscoverer.java in  » UML » AndroMDA-3.2 » org » andromda » translation » ocl » testsuite » 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 » UML » AndroMDA 3.2 » org.andromda.translation.ocl.testsuite 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.translation.ocl.testsuite;
002:
003:        import java.io.File;
004:
005:        import java.net.URL;
006:
007:        import java.util.LinkedHashMap;
008:        import java.util.Map;
009:        import java.util.Arrays;
010:        import java.util.List;
011:
012:        import org.andromda.core.common.XmlObjectFactory;
013:        import org.apache.commons.lang.StringUtils;
014:        import org.apache.log4j.Logger;
015:
016:        /**
017:         * Finds all translation tests from the current base directory up.
018:         *
019:         * @author Chad Brandon
020:         */
021:        public class TranslationTestDiscoverer {
022:            private static Logger logger = Logger
023:                    .getLogger(TranslationTestDiscoverer.class);
024:
025:            /**
026:             * This is the prefix of translation tests, each translation test must start with this in order to be found.
027:             */
028:            private static final String TEST_PREFIX = "TranslationTest-";
029:
030:            /**
031:             * Names of ignored files when file.isDirectory()
032:             */
033:            private static final List IGNORED_DIRECTORIES = Arrays
034:                    .asList(new String[] { "CVS", ".svn" });
035:
036:            /**
037:             * Stores the discovered translation tests.
038:             */
039:            private Map translationTests = new LinkedHashMap();
040:
041:            /**
042:             * The shared instance
043:             */
044:            private static TranslationTestDiscoverer instance;
045:
046:            /**
047:             * Gets the shared instance of this TranslationTestDiscoverer.
048:             *
049:             * @return the shared TranslationTestDiscoverer.
050:             */
051:            public static TranslationTestDiscoverer instance() {
052:                if (instance == null) {
053:                    instance = new TranslationTestDiscoverer();
054:                }
055:                return instance;
056:            }
057:
058:            /**
059:             * This method discovers all translation tests within the given <code>directory</code>.
060:             */
061:            public void discoverTests(final String directory) {
062:                if (directory == null || directory.trim().length() == 0) {
063:                    throw new TranslationTestDiscovererException(
064:                            "The 'directory' "
065:                                    + " was not specified, please specify this value with the location from which to"
066:                                    + " begin the discovery of translation test files");
067:                }
068:                if (this .translationTests.isEmpty()) {
069:                    this .discoverTests(new File(directory));
070:                }
071:            }
072:
073:            /**
074:             * This method discovers all translation tests within the <code>currentDirectory</code>, it travels down the
075:             * directory structure looking for files that have a prefix of 'TranslationTest-'.
076:             */
077:            private void discoverTests(final File currentDirectory) {
078:                try {
079:                    final String[] files = currentDirectory.list();
080:                    if (files == null || files.length == 0) {
081:                        if (logger.isDebugEnabled()) {
082:                            logger
083:                                    .debug("no files or directories found in directory '"
084:                                            + currentDirectory + "'");
085:                        }
086:                    } else {
087:                        for (int ctr = 0; ctr < files.length; ctr++) {
088:                            File file = new File(currentDirectory, files[ctr]);
089:                            if (StringUtils.trimToEmpty(file.getName())
090:                                    .startsWith(TEST_PREFIX)) {
091:                                final URL testUrl = file.toURL();
092:                                if (logger.isInfoEnabled()) {
093:                                    logger.info("found translation test --> '"
094:                                            + testUrl + "'");
095:                                }
096:
097:                                TranslationTest test = (TranslationTest) XmlObjectFactory
098:                                        .getInstance(TranslationTest.class)
099:                                        .getObject(testUrl);
100:                                test.setUri(testUrl);
101:                                this .translationTests.put(
102:                                        test.getTranslation(), test);
103:                            } else if (file.isDirectory()
104:                                    && !IGNORED_DIRECTORIES.contains(file
105:                                            .getName())) {
106:                                this .discoverTests(file);
107:                            }
108:                        }
109:                    }
110:                } catch (final Throwable throwable) {
111:                    logger.error(throwable);
112:                    throw new TranslationTestDiscovererException(throwable);
113:                }
114:            }
115:
116:            /**
117:             * Returns the TranslationTest for the given <code>translation</code> (if one can be found), otherwise returns
118:             * null.
119:             *
120:             * @param translation the name of the translation
121:             * @return TranslationTest
122:             */
123:            public TranslationTest getTest(String translation) {
124:                return (TranslationTest) this .translationTests.get(StringUtils
125:                        .trimToEmpty(translation));
126:            }
127:
128:            /**
129:             * Returns the discovered translation tests keyed by <code>translation<code>.
130:             */
131:            public Map getTests() {
132:                return this .translationTests;
133:            }
134:
135:            /**
136:             * Shuts down this instance and releases any resources.
137:             */
138:            public void shutdown() {
139:                this.translationTests.clear();
140:                instance = null;
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.