Source Code Cross Referenced for NewInstance.java in  » Web-Server » Rimfaxe-Web-Server » org » xml » sax » helpers » 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 » Web Server » Rimfaxe Web Server » org.xml.sax.helpers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        // NewInstance.java - create a new instance of a class by name.
02:        // http://www.saxproject.org
03:        // Written by Edwin Goei, edwingo@apache.org
04:        // and by David Brownell, dbrownell@users.sourceforge.net
05:        // NO WARRANTY!  This class is in the Public Domain.
06:        // $Id: NewInstance.java,v 1.5 2002/02/01 20:06:20 db Exp $
07:
08:        package org.xml.sax.helpers;
09:
10:        import java.lang.reflect.Method;
11:        import java.lang.reflect.InvocationTargetException;
12:
13:        /**
14:         * Create a new instance of a class by name.
15:         *
16:         * <blockquote>
17:         * <em>This module, both source code and documentation, is in the
18:         * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
19:         * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
20:         * for further information.
21:         * </blockquote>
22:         *
23:         * <p>This class contains a static method for creating an instance of a
24:         * class from an explicit class name.  It tries to use the thread's context
25:         * ClassLoader if possible and falls back to using
26:         * Class.forName(String).</p>
27:         *
28:         * <p>This code is designed to compile and run on JDK version 1.1 and later
29:         * including versions of Java 2.</p>
30:         *
31:         * @author Edwin Goei, David Brownell
32:         * @version 2.0.1 (sax2r2)
33:         */
34:        class NewInstance {
35:
36:            /**
37:             * Creates a new instance of the specified class name
38:             *
39:             * Package private so this code is not exposed at the API level.
40:             */
41:            static Object newInstance(ClassLoader classLoader, String className)
42:                    throws ClassNotFoundException, IllegalAccessException,
43:                    InstantiationException {
44:                Class driverClass;
45:                if (classLoader == null) {
46:                    driverClass = Class.forName(className);
47:                } else {
48:                    driverClass = classLoader.loadClass(className);
49:                }
50:                return driverClass.newInstance();
51:            }
52:
53:            /**
54:             * Figure out which ClassLoader to use.  For JDK 1.2 and later use
55:             * the context ClassLoader.
56:             */
57:            static ClassLoader getClassLoader() {
58:                Method m = null;
59:
60:                try {
61:                    m = Thread.class.getMethod("getContextClassLoader", null);
62:                } catch (NoSuchMethodException e) {
63:                    // Assume that we are running JDK 1.1, use the current ClassLoader
64:                    return NewInstance.class.getClassLoader();
65:                }
66:
67:                try {
68:                    return (ClassLoader) m.invoke(Thread.currentThread(), null);
69:                } catch (IllegalAccessException e) {
70:                    // assert(false)
71:                    throw new UnknownError(e.getMessage());
72:                } catch (InvocationTargetException e) {
73:                    // assert(e.getTargetException() instanceof SecurityException)
74:                    throw new UnknownError(e.getMessage());
75:                }
76:            }
77:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.