Source Code Cross Referenced for DiagnosticUtil.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » iapi » services » diag » 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 » Database DBMS » db derby 10.2 » org.apache.derby.iapi.services.diag 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.iapi.services.diag.DiagnosticUtil
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.iapi.services.diag;
023:
024:        /**
025:
026:         The Diagnostic framework is meant to provide a way to include as much
027:         diagnostic capability within the distributed release of the cloudscape
028:         product without adversely affecting the runtime speed or foot print of
029:         a running configuration that needs not use this information.
030:
031:         In order to decrease the class size of running objects diagnostic information
032:         should be put in "helper" classes.  So to provide diagnostic capabiility
033:         on the implementation of class Foo.java create a class D_Foo.java.  Class
034:         D_Foo must implement the Diagnosticable interface.  
035:
036:         This class provide utility functions to get at the information provided by
037:         the D_* helper class:
038:         findDiagnostic() - given and object "obj", get an instance of D_obj. 
039:         toDiagString()   - return the "best" diagnostic string available about
040:         a given object.
041:
042:         **/
043:
044:        public class DiagnosticUtil {
045:            /* Constructors for This class: */
046:            private DiagnosticUtil() {
047:            }
048:
049:            /* Private/Protected methods of This class: */
050:
051:            /**
052:             * Given an object return instance of the diagnostic object for this class.
053:             * <p>
054:             * Given an object this routine will determine the classname of the object
055:             * and then try to instantiate a new instance of the diagnostic object
056:             * for this class by prepending on "D_" to the last element of theclassname.
057:               If no matching class is found then the same lookup is made on the super-class
058:               of the object, looking all the way up the hierachy until a diagnostic class
059:               is found.
060:             * <BR>
061:               This routine will call "init(ref)" on the new instance and then return the new instance.
062:             *
063:             * @return A new instance of the diagnostic object for input object, or
064:             *         null if one could not be found for some reason.
065:             *
066:             * @param ref   The object which to build the diagnostic object for.
067:             **/
068:            public static Diagnosticable findDiagnostic(Object ref) {
069:                Class refClass = ref.getClass();
070:
071:                for (;;) {
072:                    try {
073:                        String className = refClass.getName();
074:                        int lastDot = className.lastIndexOf('.') + 1;
075:                        String diagClassName = className.substring(0, lastDot)
076:                                + "D_" + className.substring(lastDot);
077:
078:                        Class diagClass;
079:
080:                        try {
081:                            diagClass = Class.forName(diagClassName);
082:                        } catch (ClassNotFoundException cnfe) {
083:
084:                            // try the super-class of the object
085:                            refClass = refClass.getSuperclass();
086:                            if (refClass == null)
087:                                return null;
088:
089:                            continue;
090:                        }
091:
092:                        Diagnosticable diag_obj = (Diagnosticable) diagClass
093:                                .newInstance();
094:
095:                        diag_obj.init(ref);
096:
097:                        return diag_obj;
098:                    } catch (Exception e) {
099:                        return null;
100:                    }
101:                }
102:            }
103:
104:            /**
105:             * Return a diagnostic string associated with an object.
106:             * <p>
107:             * A utility interface to use if you just want to print a single string 
108:             * that represents the object in question.  In following order this routine
109:             * will deliver the string to use:
110:             * 
111:             *     1) find diagnostic help class, and use class.diag()
112:             *     2) else just use class.toString()
113:             *
114:             * <p>
115:             *
116:             * @return The string describing the class input.
117:             *
118:             * @param obj The object to print out.
119:             *
120:             **/
121:            public static String toDiagString(Object obj) {
122:                String ret_string = null;
123:
124:                if (obj == null)
125:                    return "null";
126:
127:                try {
128:                    Diagnosticable diag = DiagnosticUtil.findDiagnostic(obj);
129:                    if (diag != null)
130:                        ret_string = diag.diag();
131:                } catch (Throwable t) {
132:                    // do nothing, ret_string should still be null on error
133:                }
134:
135:                if (ret_string == null) {
136:                    ret_string = obj.toString();
137:                }
138:
139:                return (ret_string);
140:            }
141:
142:            /* Public Methods of This class: */
143:            /* Public Methods of XXXX class: */
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.