Showing the changes to java/pkg/com/sun/naming/internal/VersionHelper.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,155 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package com.sun.naming.internal; | ||
| 27 | |||
| 28 | import java.io.InputStream; | ||
| 29 | import java.io.IOException; | ||
| 30 | import java.net.MalformedURLException; | ||
| 31 | import java.net.URL; | ||
| 32 | import java.util.Enumeration; | ||
| 33 | import java.util.StringTokenizer; | ||
| 34 | import java.util.Vector; | ||
| 35 | |||
| 36 | import javax.naming.NamingEnumeration; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * VersionHelper was used by JNDI to accommodate differences between | ||
| 40 | * JDK 1.1.x and the Java 2 platform. As this is no longer necessary | ||
| 41 | * since JNDI's inclusion in the platform, this class currently | ||
| 42 | * serves as a set of utilities for performing system-level things, | ||
| 43 | * such as class-loading and reading system properties. | ||
| 44 | * | ||
| 45 | * @author Rosanna Lee | ||
| 46 | * @author Scott Seligman | ||
| 47 | */ | ||
| 48 | |||
| 49 | public abstract class VersionHelper { | ||
| 50 | private static VersionHelper helper = null; | ||
| 51 | |||
| 52 | final static String[] PROPS = new String[] { | ||
| 53 | javax.naming.Context.INITIAL_CONTEXT_FACTORY, | ||
| 54 | javax.naming.Context.OBJECT_FACTORIES, | ||
| 55 | javax.naming.Context.URL_PKG_PREFIXES, | ||
| 56 | javax.naming.Context.STATE_FACTORIES, | ||
| 57 | javax.naming.Context.PROVIDER_URL, | ||
| 58 | javax.naming.Context.DNS_URL, | ||
| 59 | // The following shouldn't create a runtime dependence on ldap package. | ||
| 60 | javax.naming.ldap.LdapContext.CONTROL_FACTORIES | ||
| 61 | }; | ||
| 62 | |||
| 63 | public final static int INITIAL_CONTEXT_FACTORY = 0; | ||
| 64 | public final static int OBJECT_FACTORIES = 1; | ||
| 65 | public final static int URL_PKG_PREFIXES = 2; | ||
| 66 | public final static int STATE_FACTORIES = 3; | ||
| 67 | public final static int PROVIDER_URL = 4; | ||
| 68 | public final static int DNS_URL = 5; | ||
| 69 | public final static int CONTROL_FACTORIES = 6; | ||
| 70 | |||
| 71 | VersionHelper() {} // Disallow anyone from creating one of these. | ||
| 72 | |||
| 73 | static { | ||
| 74 | helper = new VersionHelper12(); | ||
| 75 | } | ||
| 76 | |||
| 77 | public static VersionHelper getVersionHelper() { | ||
| 78 | return helper; | ||
| 79 | } | ||
| 80 | |||
| 81 | public abstract Class loadClass(String className) | ||
| 82 | throws ClassNotFoundException; | ||
| 83 | |||
| 84 | abstract Class loadClass(String className, ClassLoader cl) | ||
| 85 | throws ClassNotFoundException; | ||
| 86 | |||
| 87 | public abstract Class loadClass(String className, String codebase) | ||
| 88 | throws ClassNotFoundException, MalformedURLException; | ||
| 89 | |||
| 90 | /* | ||
| 91 | * Returns a JNDI property from the system properties. Returns | ||
| 92 | * null if the property is not set, or if there is no permission | ||
| 93 | * to read it. | ||
| 94 | */ | ||
| 95 | abstract String getJndiProperty(int i); | ||
| 96 | |||
| 97 | /* | ||
| 98 | * Reads each property in PROPS from the system properties, and | ||
| 99 | * returns their values -- in order -- in an array. For each | ||
| 100 | * unset property, the corresponding array element is set to null. | ||
| 101 | * Returns null if there is no permission to call System.getProperties(). | ||
| 102 | */ | ||
| 103 | abstract String[] getJndiProperties(); | ||
| 104 | |||
| 105 | /* | ||
| 106 | * Returns the resource of a given name associated with a particular | ||
| 107 | * class (never null), or null if none can be found. | ||
| 108 | */ | ||
| 109 | abstract InputStream getResourceAsStream(Class c, String name); | ||
| 110 | |||
| 111 | /* | ||
| 112 | * Returns an input stream for a file in <java.home>/lib, | ||
| 113 | * or null if it cannot be located or opened. | ||
| 114 | * | ||
| 115 | * @param filename The file name, sans directory. | ||
| 116 | */ | ||
| 117 | abstract InputStream getJavaHomeLibStream(String filename); | ||
| 118 | |||
| 119 | /* | ||
| 120 | * Returns an enumeration (never null) of InputStreams of the | ||
| 121 | * resources of a given name associated with a particular class | ||
| 122 | * loader. Null represents the bootstrap class loader in some | ||
| 123 | * Java implementations. | ||
| 124 | */ | ||
| 125 | abstract NamingEnumeration getResources(ClassLoader cl, String name) | ||
| 126 | throws IOException; | ||
| 127 | |||
| 128 | /* | ||
| 129 | * Returns the context class loader associated with the current thread. | ||
| 130 | * Null indicates the bootstrap class loader in some Java implementations. | ||
| 131 | * | ||
| 132 | * @throws SecurityException if the class loader is not accessible. | ||
| 133 | */ | ||
| 134 | abstract ClassLoader getContextClassLoader(); | ||
| 135 | |||
| 136 | static protected URL[] getUrlArray(String codebase) | ||
| 137 | throws MalformedURLException { | ||
| 138 | // Parse codebase into separate URLs | ||
| 139 | StringTokenizer parser = new StringTokenizer(codebase); | ||
| 140 | Vector vec = new Vector(10); | ||
| 141 | while (parser.hasMoreTokens()) { | ||
| 142 | vec.addElement(parser.nextToken()); | ||
| 143 | } | ||
| 144 | String[] url = new String[vec.size()]; | ||
| 145 | for (int i = 0; i < url.length; i++) { | ||
| 146 | url[i] = (String)vec.elementAt(i); | ||
| 147 | } | ||
| 148 | |||
| 149 | URL[] urlArray = new URL[url.length]; | ||
| 150 | for (int i = 0; i < urlArray.length; i++) { | ||
| 151 | urlArray[i] = new URL(url[i]); | ||
| 152 | } | ||
| 153 | return urlArray; | ||
| 154 | } | ||
| 155 | } | ||