Source Code Cross Referenced for ClassUtil.java in  » Testing » mockrunner-0.4 » com » mockrunner » util » common » 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 » mockrunner 0.4 » com.mockrunner.util.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.util.common;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collections;
005:        import java.util.List;
006:
007:        public class ClassUtil {
008:            private final static String[] KEYWORDS = new String[] { "abstract",
009:                    "assert", "boolean", "break", "byte", "case", "catch",
010:                    "char", "class", "const", "continue", "default", "do",
011:                    "double", "else", "enum", "extends", "final", "finally",
012:                    "float", "for", "goto", "if", "implements", "import",
013:                    "instanceof", "int", "interface", "long", "native", "new",
014:                    "package", "private", "protected", "public", "return",
015:                    "short", "static", "strictFP", "super", "switch",
016:                    "synchronized", "this", "throw", "throws", "transient",
017:                    "try", "void", "volatile", "while" };
018:
019:            /**
020:             * Returns the name of the package of the specified class.
021:             * If the class has no package, an empty String will be
022:             * returned.
023:             * @param clazz the Class
024:             * @return the package name
025:             */
026:            public static String getPackageName(Class clazz) {
027:                Package classPackage = clazz.getPackage();
028:                if (null == classPackage)
029:                    return "";
030:                return classPackage.getName();
031:            }
032:
033:            /**
034:             * Returns the name of the specified class. This method
035:             * only returns the class name without package information.
036:             * If the specified class represents a primitive type, the
037:             * name of the primitive type will be returned. If the
038:             * specified class is an array, <code>[]</code> will be
039:             * appended to the name (once for each dimension).
040:             * @param clazz the Class
041:             * @return the class name
042:             */
043:            public static String getClassName(Class clazz) {
044:                String dimensions = "";
045:                while (clazz.isArray()) {
046:                    clazz = clazz.getComponentType();
047:                    dimensions += "[]";
048:                }
049:                String classPackage = getPackageName(clazz);
050:                if (classPackage.length() == 0) {
051:                    return clazz.getName() + dimensions;
052:                } else {
053:                    return clazz.getName().substring(classPackage.length() + 1)
054:                            + dimensions;
055:                }
056:            }
057:
058:            /**
059:             * Returns the inheritance hierarchy of the specified class.
060:             * The returned array includes all superclasses of the specified class
061:             * starting with the most general superclass, which is
062:             * <code>java.lang.Object</code>. The returned array also
063:             * includes the class itself as the last element. Implemented
064:             * interfaces are not included.
065:             * @param clazz the Class
066:             * @return all superclasses, most general superclass first
067:             */
068:            public static Class[] getInheritanceHierarchy(Class clazz) {
069:                List classes = new ArrayList();
070:                Class currentClass = clazz;
071:                while (null != currentClass) {
072:                    classes.add(currentClass);
073:                    currentClass = currentClass.getSuperclass();
074:                }
075:                Collections.reverse(classes);
076:                return (Class[]) classes.toArray(new Class[classes.size()]);
077:            }
078:
079:            /**
080:             * Returns if the specified string is a Java language
081:             * keyword.
082:             * @param name the string
083:             * @return <code>true</code> if it is a keyword,
084:             *         <code>false</code> otherwise
085:             */
086:            public static boolean isKeyword(String name) {
087:                for (int ii = 0; ii < KEYWORDS.length; ii++) {
088:                    if (KEYWORDS[ii].equals(name))
089:                        return true;
090:                }
091:                return false;
092:            }
093:
094:            /**
095:             * Returns a suitable argument name for arguments
096:             * of type <code>argumentType</code>. Simply takes
097:             * the class name and converts the starting characters
098:             * to lower case (by preserving one upper case character).
099:             * E.g. the result of <code>JMSTestModule</code> is
100:             * <code>jmsTestModule</code>.
101:             * If the specified <code>argumentType</code> is an array,
102:             * an <code>"s"</code> is appended to the string.
103:             * If the resulting string is a Java keyword, <code>"Value"</code> 
104:             * is appended to the string (which is always the case with
105:             * primitive types).
106:             * @param argumentType the argument type
107:             * @return a suitable mixed case argument name
108:             */
109:            public static String getArgumentName(Class argumentType) {
110:                String dimensions = "";
111:                while (argumentType.isArray()) {
112:                    argumentType = argumentType.getComponentType();
113:                    dimensions = "s";
114:                }
115:                String name = getClassName(argumentType);
116:                int index = 0;
117:                while (index < name.length() - 1
118:                        && Character.isUpperCase(name.charAt(index))
119:                        && Character.isUpperCase(name.charAt(index + 1))) {
120:                    index++;
121:                }
122:                if (index == name.length() - 1) {
123:                    index++;
124:                }
125:                name = StringUtil.lowerCase(name, 0, index);
126:                if (isKeyword(name)) {
127:                    name += "Value";
128:                }
129:                name += dimensions;
130:                return name;
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.