Source Code Cross Referenced for FixtureTemplateCreator.java in  » Testing » StoryTestIQ » fitnesse » 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 » StoryTestIQ » fitnesse 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:        package fitnesse;
004:
005:        import fit.*;
006:        import java.lang.reflect.*;
007:        import java.util.*;
008:
009:        // This command-line tool takes in a fit.Fixture class name and prints out a FitNesse table template.
010:        public class FixtureTemplateCreator {
011:            public static void main(String[] args) throws Exception {
012:                if (args.length < 1)
013:                    return;
014:
015:                new FixtureTemplateCreator().run(args[0]);
016:            }
017:
018:            public void run(String fixtureName) throws Exception {
019:                String defaultTableTemplate = "!|" + fixtureName + "|";
020:
021:                try {
022:                    Class fixtureClass = ClassLoader.getSystemClassLoader()
023:                            .loadClass(fixtureName);
024:                    Object fixtureInstance = fixtureClass.newInstance();
025:
026:                    if (!Fixture.class.isInstance(fixtureInstance))
027:                        throw new InstantiationException();
028:                    else if (RowFixture.class.isInstance(fixtureInstance))
029:                        System.out.println(makeRowFixtureTemplate(
030:                                defaultTableTemplate, fixtureClass));
031:                    else if (ColumnFixture.class.isInstance(fixtureInstance))
032:                        System.out.println(makeColumnFixtureTemplate(
033:                                defaultTableTemplate, fixtureClass));
034:                    else
035:                        System.out.println(defaultTableTemplate);
036:                } catch (ClassNotFoundException e) {
037:                    System.out.println("# Could not find " + fixtureName
038:                            + " in the classpath. #");
039:                } catch (InstantiationException ie) {
040:                    System.out.println("# " + fixtureName
041:                            + " is not a valid fixture! #");
042:                }
043:            }
044:
045:            private StringBuffer makeRowFixtureTemplate(
046:                    String defaultTableTemplate, Class fixtureClass) {
047:                Class targetClass = getTargetClassFromRowFixture(fixtureClass);
048:                return makeColumnFixtureTemplate(defaultTableTemplate,
049:                        targetClass);
050:            }
051:
052:            private StringBuffer makeColumnFixtureTemplate(
053:                    String defaultTableTemplate, Class fixtureClass) {
054:                StringBuffer tableTemplate = new StringBuffer(
055:                        defaultTableTemplate + "\n");
056:                List publicFieldsFound = new ArrayList();
057:                List publicMethodsFound = new ArrayList();
058:                getPublicMembers(fixtureClass, publicFieldsFound,
059:                        publicMethodsFound);
060:                addCellsForColumnFixture(tableTemplate, publicFieldsFound,
061:                        publicMethodsFound);
062:
063:                return tableTemplate;
064:            }
065:
066:            private void getPublicMembers(Class aClass, List publicFields,
067:                    List publicMethods) {
068:                Field[] fields = aClass.getDeclaredFields();
069:                for (int i = 0; i < fields.length; i++) {
070:                    Field field = fields[i];
071:                    if (Modifier.isPublic(field.getModifiers()))
072:                        publicFields.add(field);
073:                }
074:
075:                Method[] methods = aClass.getDeclaredMethods();
076:                for (int i = 0; i < methods.length; i++) {
077:                    Method method = methods[i];
078:                    if (Modifier.isPublic(method.getModifiers()))
079:                        publicMethods.add(method);
080:                }
081:            }
082:
083:            private void addCellsForColumnFixture(StringBuffer tableTemplate,
084:                    List publicFields, List publicMethods) {
085:                StringBuffer headerRow = new StringBuffer("|");
086:                StringBuffer valueRow = new StringBuffer("|");
087:
088:                addCellsForFieldNamesAndTypes(publicFields, headerRow, valueRow);
089:                addCellsForMethodNamesAndReturnTypes(publicMethods, headerRow,
090:                        valueRow);
091:
092:                tableTemplate.append(headerRow).append("\n").append(valueRow)
093:                        .append("\n");
094:            }
095:
096:            private void addCellsForFieldNamesAndTypes(List publicFields,
097:                    StringBuffer headerRow, StringBuffer valueRow) {
098:                for (Iterator f = publicFields.iterator(); f.hasNext();) {
099:                    Field field = (Field) f.next();
100:                    String name = field.getName();
101:                    String type = getShortClassName(field.getType().getName());
102:
103:                    String pad = createSpaces(Math.abs(name.length()
104:                            - type.length()));
105:                    if (name.length() < type.length())
106:                        name += pad;
107:                    else if (type.length() < name.length())
108:                        type += pad;
109:
110:                    headerRow.append(name).append("|");
111:                    valueRow.append(type).append("|");
112:                }
113:            }
114:
115:            private void addCellsForMethodNamesAndReturnTypes(
116:                    List publicMethods, StringBuffer headerRow,
117:                    StringBuffer valueRow) {
118:                for (Iterator m = publicMethods.iterator(); m.hasNext();) {
119:                    Method method = (Method) m.next();
120:                    String name = method.getName() + "()";
121:                    String type = getShortClassName(method.getReturnType()
122:                            .getName());
123:                    type = fixClassName(type);
124:
125:                    String pad = createSpaces(Math.abs(name.length()
126:                            - type.length()));
127:                    if (name.length() < type.length())
128:                        name += pad;
129:                    else if (type.length() < name.length())
130:                        type += pad;
131:
132:                    headerRow.append(name).append("|");
133:                    valueRow.append(type).append("|");
134:                }
135:            }
136:
137:            private String createSpaces(int numSpaces) {
138:                StringBuffer spaces = new StringBuffer("");
139:                for (int j = 0; j < numSpaces; j++)
140:                    spaces.append(" ");
141:                return spaces.toString();
142:            }
143:
144:            protected String getShortClassName(String fullyQualifiedClassName) {
145:                String[] parts = fullyQualifiedClassName.split("\\.");
146:                return parts[parts.length - 1];
147:            }
148:
149:            protected String fixClassName(String className) {
150:                if (className.endsWith(";"))
151:                    className = className.substring(0, className.length() - 1)
152:                            + "[]";
153:                return className;
154:            }
155:
156:            protected Class getTargetClassFromRowFixture(Class rowFixtureClass) {
157:                Class targetClass = null;
158:
159:                try {
160:                    Method method_getTargetClass = rowFixtureClass.getMethod(
161:                            "getTargetClass", null);
162:                    targetClass = (Class) method_getTargetClass.invoke(
163:                            rowFixtureClass.newInstance(), null);
164:                } catch (NoSuchMethodException nsme) {
165:                    return null;
166:                } catch (Exception e) {
167:                    e.printStackTrace();
168:                    return null;
169:                }
170:                return targetClass;
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.