Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/naming/internal/VersionHelper.java
38923 views
/*1* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.naming.internal;2627import java.io.InputStream;28import java.io.IOException;29import java.net.MalformedURLException;30import java.net.URL;31import java.util.StringTokenizer;32import java.util.Vector;3334import javax.naming.NamingEnumeration;3536/**37* VersionHelper was used by JNDI to accommodate differences between38* JDK 1.1.x and the Java 2 platform. As this is no longer necessary39* since JNDI's inclusion in the platform, this class currently40* serves as a set of utilities for performing system-level things,41* such as class-loading and reading system properties.42*43* @author Rosanna Lee44* @author Scott Seligman45*/4647public abstract class VersionHelper {48private static VersionHelper helper = null;4950final static String[] PROPS = new String[] {51javax.naming.Context.INITIAL_CONTEXT_FACTORY,52javax.naming.Context.OBJECT_FACTORIES,53javax.naming.Context.URL_PKG_PREFIXES,54javax.naming.Context.STATE_FACTORIES,55javax.naming.Context.PROVIDER_URL,56javax.naming.Context.DNS_URL,57// The following shouldn't create a runtime dependence on ldap package.58javax.naming.ldap.LdapContext.CONTROL_FACTORIES59};6061public final static int INITIAL_CONTEXT_FACTORY = 0;62public final static int OBJECT_FACTORIES = 1;63public final static int URL_PKG_PREFIXES = 2;64public final static int STATE_FACTORIES = 3;65public final static int PROVIDER_URL = 4;66public final static int DNS_URL = 5;67public final static int CONTROL_FACTORIES = 6;6869VersionHelper() {} // Disallow anyone from creating one of these.7071static {72helper = new VersionHelper12();73}7475public static VersionHelper getVersionHelper() {76return helper;77}7879public abstract Class<?> loadClassWithoutInit(String className)80throws ClassNotFoundException;8182public abstract Class<?> loadClass(String className)83throws ClassNotFoundException;8485abstract Class<?> loadClass(String className, ClassLoader cl)86throws ClassNotFoundException;8788public abstract Class<?> loadClass(String className, String codebase)89throws ClassNotFoundException, MalformedURLException;9091/*92* Returns a JNDI property from the system properties. Returns93* null if the property is not set, or if there is no permission94* to read it.95*/96abstract String getJndiProperty(int i);9798/*99* Reads each property in PROPS from the system properties, and100* returns their values -- in order -- in an array. For each101* unset property, the corresponding array element is set to null.102* Returns null if there is no permission to call System.getProperties().103*/104abstract String[] getJndiProperties();105106/*107* Returns the resource of a given name associated with a particular108* class (never null), or null if none can be found.109*/110abstract InputStream getResourceAsStream(Class<?> c, String name);111112/*113* Returns an input stream for a file in <java.home>/lib,114* or null if it cannot be located or opened.115*116* @param filename The file name, sans directory.117*/118abstract InputStream getJavaHomeLibStream(String filename);119120/*121* Returns an enumeration (never null) of InputStreams of the122* resources of a given name associated with a particular class123* loader. Null represents the bootstrap class loader in some124* Java implementations.125*/126abstract NamingEnumeration<InputStream> getResources(127ClassLoader cl, String name)128throws IOException;129130/*131* Returns the context class loader associated with the current thread.132* Null indicates the bootstrap class loader in some Java implementations.133*134* @throws SecurityException if the class loader is not accessible.135*/136abstract ClassLoader getContextClassLoader();137138static protected URL[] getUrlArray(String codebase)139throws MalformedURLException {140// Parse codebase into separate URLs141StringTokenizer parser = new StringTokenizer(codebase);142Vector<String> vec = new Vector<>(10);143while (parser.hasMoreTokens()) {144vec.addElement(parser.nextToken());145}146String[] url = new String[vec.size()];147for (int i = 0; i < url.length; i++) {148url[i] = vec.elementAt(i);149}150151URL[] urlArray = new URL[url.length];152for (int i = 0; i < urlArray.length; i++) {153urlArray[i] = new URL(url[i]);154}155return urlArray;156}157}158159160