Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/naming/internal/VersionHelper.java
38923 views
1
/*
2
* Copyright (c) 1999, 2011, 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.StringTokenizer;
33
import java.util.Vector;
34
35
import javax.naming.NamingEnumeration;
36
37
/**
38
* VersionHelper was used by JNDI to accommodate differences between
39
* JDK 1.1.x and the Java 2 platform. As this is no longer necessary
40
* since JNDI's inclusion in the platform, this class currently
41
* serves as a set of utilities for performing system-level things,
42
* such as class-loading and reading system properties.
43
*
44
* @author Rosanna Lee
45
* @author Scott Seligman
46
*/
47
48
public abstract class VersionHelper {
49
private static VersionHelper helper = null;
50
51
final static String[] PROPS = new String[] {
52
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
53
javax.naming.Context.OBJECT_FACTORIES,
54
javax.naming.Context.URL_PKG_PREFIXES,
55
javax.naming.Context.STATE_FACTORIES,
56
javax.naming.Context.PROVIDER_URL,
57
javax.naming.Context.DNS_URL,
58
// The following shouldn't create a runtime dependence on ldap package.
59
javax.naming.ldap.LdapContext.CONTROL_FACTORIES
60
};
61
62
public final static int INITIAL_CONTEXT_FACTORY = 0;
63
public final static int OBJECT_FACTORIES = 1;
64
public final static int URL_PKG_PREFIXES = 2;
65
public final static int STATE_FACTORIES = 3;
66
public final static int PROVIDER_URL = 4;
67
public final static int DNS_URL = 5;
68
public final static int CONTROL_FACTORIES = 6;
69
70
VersionHelper() {} // Disallow anyone from creating one of these.
71
72
static {
73
helper = new VersionHelper12();
74
}
75
76
public static VersionHelper getVersionHelper() {
77
return helper;
78
}
79
80
public abstract Class<?> loadClassWithoutInit(String className)
81
throws ClassNotFoundException;
82
83
public abstract Class<?> loadClass(String className)
84
throws ClassNotFoundException;
85
86
abstract Class<?> loadClass(String className, ClassLoader cl)
87
throws ClassNotFoundException;
88
89
public abstract Class<?> loadClass(String className, String codebase)
90
throws ClassNotFoundException, MalformedURLException;
91
92
/*
93
* Returns a JNDI property from the system properties. Returns
94
* null if the property is not set, or if there is no permission
95
* to read it.
96
*/
97
abstract String getJndiProperty(int i);
98
99
/*
100
* Reads each property in PROPS from the system properties, and
101
* returns their values -- in order -- in an array. For each
102
* unset property, the corresponding array element is set to null.
103
* Returns null if there is no permission to call System.getProperties().
104
*/
105
abstract String[] getJndiProperties();
106
107
/*
108
* Returns the resource of a given name associated with a particular
109
* class (never null), or null if none can be found.
110
*/
111
abstract InputStream getResourceAsStream(Class<?> c, String name);
112
113
/*
114
* Returns an input stream for a file in <java.home>/lib,
115
* or null if it cannot be located or opened.
116
*
117
* @param filename The file name, sans directory.
118
*/
119
abstract InputStream getJavaHomeLibStream(String filename);
120
121
/*
122
* Returns an enumeration (never null) of InputStreams of the
123
* resources of a given name associated with a particular class
124
* loader. Null represents the bootstrap class loader in some
125
* Java implementations.
126
*/
127
abstract NamingEnumeration<InputStream> getResources(
128
ClassLoader cl, String name)
129
throws IOException;
130
131
/*
132
* Returns the context class loader associated with the current thread.
133
* Null indicates the bootstrap class loader in some Java implementations.
134
*
135
* @throws SecurityException if the class loader is not accessible.
136
*/
137
abstract ClassLoader getContextClassLoader();
138
139
static protected URL[] getUrlArray(String codebase)
140
throws MalformedURLException {
141
// Parse codebase into separate URLs
142
StringTokenizer parser = new StringTokenizer(codebase);
143
Vector<String> vec = new Vector<>(10);
144
while (parser.hasMoreTokens()) {
145
vec.addElement(parser.nextToken());
146
}
147
String[] url = new String[vec.size()];
148
for (int i = 0; i < url.length; i++) {
149
url[i] = vec.elementAt(i);
150
}
151
152
URL[] urlArray = new URL[url.length];
153
for (int i = 0; i < urlArray.length; i++) {
154
urlArray[i] = new URL(url[i]);
155
}
156
return urlArray;
157
}
158
}
159
160