Source Code Cross Referenced for ClassLoaderUtil.java in  » Workflow-Engines » OSWorkflow » com » opensymphony » workflow » loader » 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 » Workflow Engines » OSWorkflow » com.opensymphony.workflow.loader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.workflow.loader;
006:
007:        import java.io.IOException;
008:        import java.io.InputStream;
009:
010:        import java.net.URL;
011:
012:        /**
013:         * This class is extremely useful for loading resources and classes in a fault tolerant manner
014:         * that works across different applications servers.
015:         *
016:         * It has come out of many months of frustrating use of multiple application servers at Atlassian,
017:         * please don't change things unless you're sure they're not going to break in one server or another!
018:         *
019:         * @version $Revision: 1.2 $
020:         */
021:        public class ClassLoaderUtil {
022:            //~ Methods ////////////////////////////////////////////////////////////////
023:
024:            /**
025:             * Load a given resource.
026:             *
027:             * This method will try to load the resource using the following methods (in order):
028:             * <ul>
029:             *  <li>From Thread.currentThread().getContextClassLoader()
030:             *  <li>From ClassLoaderUtil.class.getClassLoader()
031:             *  <li>callingClass.getClassLoader()
032:             * </ul>
033:             *
034:             * @param resourceName The name of the resource to load
035:             * @param callingClass The Class object of the calling object
036:             */
037:            public static URL getResource(String resourceName,
038:                    Class callingClass) {
039:                URL url = Thread.currentThread().getContextClassLoader()
040:                        .getResource(resourceName);
041:
042:                if (url == null) {
043:                    url = ClassLoaderUtil.class.getClassLoader().getResource(
044:                            resourceName);
045:                }
046:
047:                if (url == null) {
048:                    ClassLoader cl = callingClass.getClassLoader();
049:
050:                    if (cl != null) {
051:                        url = cl.getResource(resourceName);
052:                    }
053:                }
054:
055:                if ((url == null) && (resourceName != null)
056:                        && (resourceName.charAt(0) != '/')) {
057:                    return getResource('/' + resourceName, callingClass);
058:                }
059:
060:                return url;
061:            }
062:
063:            /**
064:             * This is a convenience method to load a resource as a stream.
065:             *
066:             * The algorithm used to find the resource is given in getResource()
067:             *
068:             * @param resourceName The name of the resource to load
069:             * @param callingClass The Class object of the calling object
070:             */
071:            public static InputStream getResourceAsStream(String resourceName,
072:                    Class callingClass) {
073:                URL url = getResource(resourceName, callingClass);
074:
075:                try {
076:                    return (url != null) ? url.openStream() : null;
077:                } catch (IOException e) {
078:                    return null;
079:                }
080:            }
081:
082:            /**
083:             * Load a class with a given name.
084:             *
085:             * It will try to load the class in the following order:
086:             * <ul>
087:             *  <li>From Thread.currentThread().getContextClassLoader()
088:             *  <li>Using the basic Class.forName()
089:             *  <li>From ClassLoaderUtil.class.getClassLoader()
090:             *  <li>From the callingClass.getClassLoader()
091:             * </ul>
092:             *
093:             * @param className The name of the class to load
094:             * @param callingClass The Class object of the calling object
095:             * @throws ClassNotFoundException If the class cannot be found anywhere.
096:             */
097:            public static Class loadClass(String className, Class callingClass)
098:                    throws ClassNotFoundException {
099:                try {
100:                    return Thread.currentThread().getContextClassLoader()
101:                            .loadClass(className);
102:                } catch (ClassNotFoundException e) {
103:                    try {
104:                        return Class.forName(className);
105:                    } catch (ClassNotFoundException ex) {
106:                        try {
107:                            return ClassLoaderUtil.class.getClassLoader()
108:                                    .loadClass(className);
109:                        } catch (ClassNotFoundException exc) {
110:                            return callingClass.getClassLoader().loadClass(
111:                                    className);
112:                        }
113:                    }
114:                }
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.