Source Code Cross Referenced for FactoryFinder.java in  » EJB-Server-GlassFish » servlet » javax » el » 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 » EJB Server GlassFish » servlet » javax.el 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms
003:         * of the Common Development and Distribution License
004:         * (the "License").  You may not use this file except
005:         * in compliance with the License.
006:         *
007:         * You can obtain a copy of the license at
008:         * glassfish/bootstrap/legal/CDDLv1.0.txt or
009:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
010:         * See the License for the specific language governing
011:         * permissions and limitations under the License.
012:         *
013:         * When distributing Covered Code, include this CDDL
014:         * HEADER in each file and include the License file at
015:         * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable,
016:         * add the following below this CDDL HEADER, with the
017:         * fields enclosed by brackets "[]" replaced with your
018:         * own identifying information: Portions Copyright [yyyy]
019:         * [name of copyright owner]
020:         *
021:         * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
022:         */
023:
024:        package javax.el;
025:
026:        import java.lang.reflect.Constructor;
027:        import java.io.InputStream;
028:        import java.io.File;
029:        import java.io.FileInputStream;
030:        import java.util.Properties;
031:        import java.io.BufferedReader;
032:        import java.io.InputStreamReader;
033:
034:        class FactoryFinder {
035:
036:            /**
037:             * Creates an instance of the specified class using the specified 
038:             * <code>ClassLoader</code> object.
039:             *
040:             * @exception ELException if the given class could not be found
041:             *            or could not be instantiated
042:             */
043:            private static Object newInstance(String className,
044:                    ClassLoader classLoader, Properties properties) {
045:                try {
046:                    Class spiClass;
047:                    if (classLoader == null) {
048:                        spiClass = Class.forName(className);
049:                    } else {
050:                        spiClass = classLoader.loadClass(className);
051:                    }
052:                    if (properties != null) {
053:                        Constructor constr = null;
054:                        try {
055:                            constr = spiClass.getConstructor(Properties.class);
056:                        } catch (Exception ex) {
057:                        }
058:                        if (constr != null) {
059:                            return constr.newInstance(properties);
060:                        }
061:                    }
062:                    return spiClass.newInstance();
063:                } catch (ClassNotFoundException x) {
064:                    throw new ELException("Provider " + className
065:                            + " not found", x);
066:                } catch (Exception x) {
067:                    throw new ELException("Provider " + className
068:                            + " could not be instantiated: " + x, x);
069:                }
070:            }
071:
072:            /**
073:             * Finds the implementation <code>Class</code> object for the given
074:             * factory name, or if that fails, finds the <code>Class</code> object
075:             * for the given fallback class name. The arguments supplied must be
076:             * used in order. If using the first argument is successful, the second
077:             * one will not be used.
078:             * <P>
079:             * This method is package private so that this code can be shared.
080:             *
081:             * @return the <code>Class</code> object of the specified message factory;
082:             *         may not be <code>null</code>
083:             *
084:             * @param factoryId             the name of the factory to find, which is
085:             *                              a system property
086:             * @param fallbackClassName     the implementation class name, which is
087:             *                              to be used only if nothing else
088:             *                              is found; <code>null</code> to indicate that
089:             *                              there is no fallback class name
090:             * @exception ELException if there is an error
091:             */
092:            static Object find(String factoryId, String fallbackClassName,
093:                    Properties properties) {
094:                ClassLoader classLoader;
095:                try {
096:                    classLoader = Thread.currentThread()
097:                            .getContextClassLoader();
098:                } catch (Exception x) {
099:                    throw new ELException(x.toString(), x);
100:                }
101:
102:                String serviceId = "META-INF/services/" + factoryId;
103:                // try to find services in CLASSPATH
104:                try {
105:                    InputStream is = null;
106:                    if (classLoader == null) {
107:                        is = ClassLoader.getSystemResourceAsStream(serviceId);
108:                    } else {
109:                        is = classLoader.getResourceAsStream(serviceId);
110:                    }
111:
112:                    if (is != null) {
113:                        BufferedReader rd = new BufferedReader(
114:                                new InputStreamReader(is, "UTF-8"));
115:
116:                        String factoryClassName = rd.readLine();
117:                        rd.close();
118:
119:                        if (factoryClassName != null
120:                                && !"".equals(factoryClassName)) {
121:                            return newInstance(factoryClassName, classLoader,
122:                                    properties);
123:                        }
124:                    }
125:                } catch (Exception ex) {
126:                }
127:
128:                // try to read from $java.home/lib/el.properties
129:                try {
130:                    String javah = System.getProperty("java.home");
131:                    String configFile = javah + File.separator + "lib"
132:                            + File.separator + "el.properties";
133:                    File f = new File(configFile);
134:                    if (f.exists()) {
135:                        Properties props = new Properties();
136:                        props.load(new FileInputStream(f));
137:                        String factoryClassName = props.getProperty(factoryId);
138:                        return newInstance(factoryClassName, classLoader,
139:                                properties);
140:                    }
141:                } catch (Exception ex) {
142:                }
143:
144:                // Use the system property
145:                try {
146:                    String systemProp = System.getProperty(factoryId);
147:                    if (systemProp != null) {
148:                        return newInstance(systemProp, classLoader, properties);
149:                    }
150:                } catch (SecurityException se) {
151:                }
152:
153:                if (fallbackClassName == null) {
154:                    throw new ELException("Provider for " + factoryId
155:                            + " cannot be found", null);
156:                }
157:
158:                return newInstance(fallbackClassName, classLoader, properties);
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.