Source Code Cross Referenced for JDK11Hooks.java in  » Library » Apache-common-Discovery » org » apache » commons » discovery » jdk » 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 » Library » Apache common Discovery » org.apache.commons.discovery.jdk 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.discovery.jdk;
018:
019:        import java.io.IOException;
020:        import java.net.URL;
021:        import java.util.Enumeration;
022:
023:        /**
024:         * @author Richard A. Sitze
025:         */
026:        public class JDK11Hooks extends JDKHooks {
027:            private static final ClassLoader systemClassLoader = new PsuedoSystemClassLoader();
028:
029:            /**
030:             * Get the system property
031:             *
032:             * @param propName name of the property
033:             * @return value of the property
034:             */
035:            public String getSystemProperty(final String propName) {
036:                return System.getProperty(propName);
037:            }
038:
039:            /**
040:             * The thread context class loader is available for JDK 1.2
041:             * or later, if certain security conditions are met.
042:             * 
043:             * @return The thread context class loader, if available.
044:             *         Otherwise return null.
045:             */
046:            public ClassLoader getThreadContextClassLoader() {
047:                return null;
048:            }
049:
050:            /**
051:             * The system class loader is available for JDK 1.2
052:             * or later, if certain security conditions are met.
053:             * 
054:             * @return The system class loader, if available.
055:             *         Otherwise return null.
056:             */
057:            public ClassLoader getSystemClassLoader() {
058:                return systemClassLoader;
059:            }
060:
061:            /**
062:             * Implement ClassLoader.getResources for JDK 1.1
063:             * 
064:             * On JDK1.1 there is no getResources() method. We emulate this by
065:             * using introspection and doing the lookup ourself, using the list
066:             * of URLs, via getURLs().
067:             */
068:            public Enumeration getResources(ClassLoader loader,
069:                    String resourceName) throws IOException {
070:                /**
071:                 * The simple answer is/was:
072:                 *    return loader.getResources(resourceName);
073:                 * 
074:                 * However, some classloaders overload the behavior of getResource
075:                 * (loadClass, etc) such that the order of returned results changes
076:                 * from normally expected behavior.
077:                 * 
078:                 * Example: locate classes/resources from child ClassLoaders first,
079:                 *          parents last (in some J2EE environs).
080:                 * 
081:                 * The resource returned by getResource() should be the same as the
082:                 * first resource returned by getResources().  Unfortunately, this
083:                 * is not, and cannot be: getResources() is 'final' in the current
084:                 * JDK's (1.2, 1.3, 1.4).
085:                 * 
086:                 * To address this, the implementation of this method will
087:                 * return an Enumeration such that the first element is the
088:                 * results of getResource, and all trailing elements are
089:                 * from getResources.  On each iteration, we check so see
090:                 * if the resource (from getResources) matches the first resource,
091:                 * and eliminate the redundent element.
092:                 */
093:
094:                final URL first = (URL) loader.getResource(resourceName);
095:                final Enumeration rest = loader.getResources(resourceName);
096:
097:                return new Enumeration() {
098:                    private boolean firstDone = (first == null);
099:                    private URL next = getNext();
100:
101:                    public Object nextElement() {
102:                        URL o = next;
103:                        next = getNext();
104:                        return o;
105:                    }
106:
107:                    public boolean hasMoreElements() {
108:                        return next != null;
109:                    }
110:
111:                    private URL getNext() {
112:                        URL n;
113:
114:                        if (!firstDone) {
115:                            /**
116:                             * First time through, use results of getReference()
117:                             * if they were non-null.
118:                             */
119:                            firstDone = true;
120:                            n = first;
121:                        } else {
122:                            /**
123:                             * Subsequent times through,
124:                             * use results of getReferences()
125:                             * but take out anything that matches 'first'.
126:                             * 
127:                             * Iterate through list until we find one that
128:                             * doesn't match 'first'.
129:                             */
130:                            n = null;
131:                            while (rest.hasMoreElements() && n == null) {
132:                                n = (URL) rest.nextElement();
133:                                if (first != null && n != null
134:                                        && n.equals(first)) {
135:                                    n = null;
136:                                }
137:                            }
138:                        }
139:
140:                        return n;
141:                    }
142:                };
143:            }
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.