Source Code Cross Referenced for ImagingException.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » javax » media » jai » util » 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 » 6.0 JDK Modules » Java Advanced Imaging » javax.media.jai.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ImagingException.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.1 $
009:         * $Date: 2005/02/11 04:57:57 $
010:         * $State: Exp $
011:         */
012:        package javax.media.jai.util;
013:
014:        import java.lang.reflect.InvocationTargetException;
015:        import java.lang.reflect.Method;
016:        import java.io.PrintStream;
017:        import java.io.PrintWriter;
018:        import java.security.PrivilegedActionException;
019:
020:        /**
021:         * This class is designed to contain information of the (abnormal)
022:         * situations that happen in JAI and the operations plugged into JAI.
023:         * The behavior of this class imitates the <code>Exception</code> class
024:         * in Java<sup><font size="-2">TM</font></sup> 2 Platform version 1.4
025:         * to define a chained exception and is call-compatible
026:         * with Java<sup><font size="-2">TM</font></sup> 2 Platform version 1.4:
027:         * The cause can be stored and retrieved from the
028:         * instance of this class. Also, the root cause for an instance
029:         * can be retrieved.
030:         *
031:         * @since JAI 1.1.2
032:         */
033:        public class ImagingException extends RuntimeException {
034:            /** The cached cause. */
035:            private Throwable cause = null;
036:
037:            /** The default constructor. */
038:            public ImagingException() {
039:                super ();
040:            }
041:
042:            /**
043:             * The constructor to accept the message that describes the situation.
044:             *
045:             * @param message The message to describe the situation.
046:             */
047:            public ImagingException(String message) {
048:                super (message);
049:            }
050:
051:            /**
052:             * The constructor to accept the cause of this <code>ImagingException</code>.
053:             *
054:             * @param cause The cause of this <code>ImagingException</code>.
055:             */
056:            public ImagingException(Throwable cause) {
057:                super ();
058:                this .cause = cause;
059:            }
060:
061:            /**
062:             * The constructor to accept the cause of this <code>ImagingException</code>
063:             * and the message that describes the situation.
064:             *
065:             * @param message The message that describes the situation.
066:             * @param cause The cause of this <code>ImagingException</code>
067:             */
068:            public ImagingException(String message, Throwable cause) {
069:                super (message);
070:                this .cause = cause;
071:            }
072:
073:            /**
074:             * Returns the cause of this <code>ImagingException</code>.
075:             */
076:            public Throwable getCause() {
077:                return cause;
078:            }
079:
080:            /**
081:             * Recursively retrieves the root cause of this
082:             * <code>ImagingException</code>.
083:             */
084:            public Throwable getRootCause() {
085:                Throwable rootCause = cause;
086:                Throwable atop = this ;
087:
088:                while (rootCause != atop && rootCause != null) {
089:                    try {
090:                        atop = rootCause;
091:                        Method getCause = rootCause.getClass().getMethod(
092:                                "getCause", null);
093:                        rootCause = (Throwable) getCause
094:                                .invoke(rootCause, null);
095:                    } catch (Exception e) {
096:                        // do nothing.  This happens (1) getCause method is not defined.
097:                        // (2) Reflection error.  So rootCause will be the same as
098:                        // atop. Then stop the loop.
099:                        if (rootCause instanceof  InvocationTargetException)
100:                            rootCause = ((InvocationTargetException) rootCause)
101:                                    .getTargetException();
102:                        else if (rootCause instanceof  PrivilegedActionException)
103:                            rootCause = ((PrivilegedActionException) rootCause)
104:                                    .getException();
105:                        else
106:                            rootCause = atop;
107:                    } finally {
108:                        if (rootCause == null)
109:                            rootCause = atop;
110:                    }
111:                }
112:
113:                return rootCause;
114:            }
115:
116:            /**
117:             * Prints the stack trace. For Java<sup><font size="-2">TM</font></sup> 2
118:             * Platform version 1.4 and up, calls the same
119:             * method in the super class.  For Java<sup><font size="-2">TM</font></sup>
120:             * 2 Platform version 1.3, prints the stack trace of
121:             * this <code>ImagingException</code> and the trace of its cause.
122:             */
123:            public void printStackTrace() {
124:                printStackTrace(System.err);
125:            }
126:
127:            /**
128:             * Prints the stack trace.  For Java<sup><font size="-2">TM</font></sup>
129:             * 2 Platform version 1.4 and up, calls the same
130:             * method in the super class.  For Java<sup><font size="-2">TM</font></sup>
131:             * 2 Platform version 1.4, prints the stack trace of
132:             * this <code>ImagingException</code> and the trace of its cause.
133:             */
134:            public void printStackTrace(PrintStream s) {
135:
136:                synchronized (s) {
137:                    super .printStackTrace(s);
138:                    boolean is14 = false;
139:                    try {
140:                        String version = System.getProperty("java.version");
141:                        is14 = version.indexOf("1.4") >= 0;
142:                    } catch (Exception e) {
143:                    }
144:
145:                    if (!is14 && cause != null) {
146:                        s.println("Caused by:");
147:                        cause.printStackTrace(s);
148:                    }
149:
150:                }
151:            }
152:
153:            /**
154:             * Prints the stack trace.  For Java<sup><font size="-2">TM</font></sup> 2
155:             * Platform version 1.4 and up, calls the same
156:             * method in the super class.  For Java<sup><font size="-2">TM</font></sup>
157:             * 2 Platform version 1.43, prints the stack trace of
158:             * this <code>ImagingException</code> and the trace of its cause.
159:             */
160:
161:            public void printStackTrace(PrintWriter s) {
162:                synchronized (s) {
163:                    super .printStackTrace(s);
164:                    boolean is14 = false;
165:                    try {
166:                        String version = System.getProperty("java.version");
167:                        is14 = version.indexOf("1.4") >= 0;
168:                    } catch (Exception e) {
169:                    }
170:
171:                    if (!is14 && cause != null) {
172:                        s.println("Caused by:");
173:                        cause.printStackTrace(s);
174:                    }
175:                }
176:            }
177:            /*
178:             public static void main(String[] args) {
179:             Exception ce = new ImagingException(new RuntimeException("test"));
180:             Throwable cause = ce.getCause();
181:             System.out.println("Cause: " + cause);
182:             System.out.println("Root cause: " + ((ImagingException)ce).getRootCause());
183:             ce.printStackTrace();
184:             }
185:             */
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.