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


001:        package org.andromda.core.common;
002:
003:        import org.apache.commons.lang.StringUtils;
004:
005:        /**
006:         * Contains Exception handling utilities.
007:         *
008:         * @author Chad Brandon
009:         */
010:        public class ExceptionUtils {
011:            /**
012:             * Checks if the argument is null, and if so, throws an IllegalArgumentException, does nothing if not.
013:             *
014:             * @param methodExecuteName the name of the method we are currently executing
015:             * @param argumentName the name of the argument we are checking for null
016:             * @param argument the argument we are checking
017:             * @deprecated used {@link #checkNull(String, Object)} instead since we can detect the method name.
018:             */
019:            public static void checkNull(final String methodExecuteName,
020:                    final String argumentName, final Object argument) {
021:                checkNull(argumentName, argument, 3);
022:            }
023:
024:            /**
025:             * Checks if the argument is null, and if so, throws an IllegalArgumentException, does nothing if not.
026:             *
027:             * @param argumentName the name of the argument we are checking for null
028:             * @param argument the argument we are checking
029:             */
030:            public static void checkNull(final String argumentName,
031:                    final Object argument) {
032:                checkNull(argumentName, argument, 3);
033:            }
034:
035:            /**
036:             * Checks if the argument is null, and if so, throws an IllegalArgumentException, does nothing if not.
037:             *
038:             * @param argumentName the name of the argument we are checking for null
039:             * @param argument the argument we are checking
040:             * @param stackDepth the depth of the stack from which to retrieve the methodInformation.
041:             */
042:            private static void checkNull(final String argumentName,
043:                    final Object argument, final int stackDepth) {
044:                if (StringUtils.isEmpty(argumentName)) {
045:                    throw new IllegalArgumentException(
046:                            "'argumentName' can not be null or an empty String");
047:                }
048:
049:                if (argument == null) {
050:                    throw new IllegalArgumentException(
051:                            getMethodName(stackDepth) + " - '" + argumentName
052:                                    + "' can not be null");
053:                }
054:            }
055:
056:            /**
057:             * Checks if the argument is null or an empty String throws an IllegalArgumentException if it is, does nothing if
058:             * not.
059:             *
060:             * @param methodExecuteName the name of the method we are currently executing
061:             * @param argumentName the name of the argument we are checking for null
062:             * @param argument the argument we are checking
063:             * @deprecated use {@link #checkEmpty(String, String)} instead since we can detect the method name.
064:             */
065:            public static void checkEmpty(final String methodExecuteName,
066:                    final String argumentName, final String argument) {
067:                checkEmpty(argumentName, argument, 3);
068:            }
069:
070:            /**
071:             * Checks if the argument is null or an empty String throws an IllegalArgumentException if it is, does nothing if
072:             * not.
073:             *
074:             * @param argumentName the name of the argument we are checking for null
075:             * @param argument the argument we are checking
076:             */
077:            public static void checkEmpty(final String argumentName,
078:                    final String argument) {
079:                checkEmpty(argumentName, argument, 3);
080:            }
081:
082:            /**
083:             * Checks if the argument is null or an empty String throws an IllegalArgumentException if it is, does nothing if
084:             * not.
085:             *
086:             * @param argumentName the name of the argument we are checking for null
087:             * @param argument the argument we are checking
088:             * @param stackDepth the depth of the stack from which to retrieve the methodInformation.
089:             */
090:            private static void checkEmpty(final String argumentName,
091:                    final String argument, final int stackDepth) {
092:                if (StringUtils.isEmpty(argumentName)) {
093:                    throw new IllegalArgumentException(
094:                            "'argumentName' can not be null or an empty String");
095:                }
096:                if (StringUtils.isEmpty(argument)) {
097:                    throw new IllegalArgumentException(
098:                            getMethodName(stackDepth) + " - '" + argumentName
099:                                    + "' can not be null or an empty String");
100:                }
101:            }
102:
103:            /**
104:             * Checks if the argumentClass is assignable to assignableToClass, and if not throws an IllegalArgumentException,
105:             * otherwise does nothing.
106:             *
107:             * @param methodExecuteName the method name of the method, this method is being executed within
108:             * @param assignableToClass the Class that argumentClass must be assignable to
109:             * @param argumentClass the argumentClass we are checking
110:             * @param argumentName the name of the argument we are checking
111:             * @deprecated use {@link #checkAssignable(Class, String, Class)} since we can detect the method name.
112:             */
113:            public static void checkAssignable(final String methodExecuteName,
114:                    final Class assignableToClass, final String argumentName,
115:                    final Class argumentClass) {
116:                checkAssignable(assignableToClass, argumentName, argumentClass,
117:                        3);
118:            }
119:
120:            /**
121:             * Checks if the argumentClass is assignable to assignableToClass, and if not throws an IllegalArgumentException,
122:             * otherwise does nothing.
123:             *
124:             * @param assignableToClass the Class that argumentClass must be assignable to
125:             * @param argumentClass the argumentClass we are checking
126:             * @param argumentName the name of the argument we are checking
127:             */
128:            public static void checkAssignable(final Class assignableToClass,
129:                    final String argumentName, final Class argumentClass) {
130:                checkAssignable(assignableToClass, argumentName, argumentClass,
131:                        3);
132:            }
133:
134:            /**
135:             * Checks if the argumentClass is assignable to assignableToClass, and if not throws an IllegalArgumentException,
136:             * otherwise does nothing.
137:             *
138:             * @param assignableToClass the Class that argumentClass must be assignable to
139:             * @param argumentClass the argumentClass we are checking
140:             * @param argumentName the name of the argument we are checking
141:             * @param stackDepth the depth of the stack from which to retrieve the method information.
142:             */
143:            private static void checkAssignable(final Class assignableToClass,
144:                    final String argumentName, final Class argumentClass,
145:                    final int stackDepth) {
146:                if (assignableToClass == null) {
147:                    throw new IllegalArgumentException(
148:                            "'assignableToClass' can not be null");
149:                }
150:                if (argumentClass == null) {
151:                    throw new IllegalArgumentException(
152:                            "'argumentClass' can not be null");
153:                }
154:                if (StringUtils.isEmpty(argumentName)) {
155:                    throw new IllegalArgumentException(
156:                            "'argumentName can not be null or an empty String");
157:                }
158:
159:                // this is what the method is for
160:                if (!assignableToClass.isAssignableFrom(argumentClass)) {
161:                    throw new IllegalArgumentException(
162:                            getMethodName(stackDepth) + " - '" + argumentName
163:                                    + "' class --> '" + argumentClass
164:                                    + "' must be assignable to class --> '"
165:                                    + assignableToClass + "'");
166:                }
167:            }
168:
169:            /**
170:             * Attempts to retrieve the root cause of the exception, if it can not be
171:             * found, the <code>throwable</code> itself is returned.
172:             *
173:             * @param throwable the exception from which to retrieve the root cause.
174:             * @return the root cause of the exception
175:             */
176:            public static Throwable getRootCause(Throwable throwable) {
177:                final Throwable root = org.apache.commons.lang.exception.ExceptionUtils
178:                        .getRootCause(throwable);
179:                if (root != null) {
180:                    throwable = root;
181:                }
182:                return throwable;
183:            }
184:
185:            /**
186:             * Gets the appropriate method name for the method being checked.
187:             *
188:             * @return the name of the method.
189:             */
190:            private static String getMethodName(int stackDepth) {
191:                String methodName = null;
192:                final Throwable throwable = new Throwable();
193:                final StackTraceElement[] stack = throwable.getStackTrace();
194:                if (stack.length >= stackDepth) {
195:                    final StackTraceElement element = stack[stackDepth];
196:                    methodName = element.getClassName() + '.'
197:                            + element.getMethodName();
198:                }
199:                return methodName;
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.