Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.naming/share/classes/javax/naming/directory/InitialDirContext.java
41159 views
1
/*
2
* Copyright (c) 1999, 2009, 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
27
package javax.naming.directory;
28
29
import java.util.Hashtable;
30
import javax.naming.*;
31
32
/**
33
* This class is the starting context for performing
34
* directory operations. The documentation in the class description
35
* of InitialContext (including those for synchronization) apply here.
36
*
37
*
38
* @author Rosanna Lee
39
* @author Scott Seligman
40
*
41
* @see javax.naming.InitialContext
42
* @since 1.3
43
*/
44
45
public class InitialDirContext extends InitialContext implements DirContext {
46
47
/**
48
* Constructs an initial DirContext with the option of not
49
* initializing it. This may be used by a constructor in
50
* a subclass when the value of the environment parameter
51
* is not yet known at the time the {@code InitialDirContext}
52
* constructor is called. The subclass's constructor will
53
* call this constructor, compute the value of the environment,
54
* and then call {@code init()} before returning.
55
*
56
* @param lazy
57
* true means do not initialize the initial DirContext; false
58
* is equivalent to calling {@code new InitialDirContext()}
59
* @throws NamingException if a naming exception is encountered
60
*
61
* @see InitialContext#init(Hashtable)
62
* @since 1.3
63
*/
64
protected InitialDirContext(boolean lazy) throws NamingException {
65
super(lazy);
66
}
67
68
/**
69
* Constructs an initial DirContext.
70
* No environment properties are supplied.
71
* Equivalent to {@code new InitialDirContext(null)}.
72
*
73
* @throws NamingException if a naming exception is encountered
74
*
75
* @see #InitialDirContext(Hashtable)
76
*/
77
public InitialDirContext() throws NamingException {
78
super();
79
}
80
81
/**
82
* Constructs an initial DirContext using the supplied environment.
83
* Environment properties are discussed in the
84
* {@code javax.naming.InitialContext} class description.
85
*
86
* <p> If the {@code java.naming.provider.url} property of the supplied
87
* environment consists of a URL (or a list of URLs) using the ldap
88
* protocol the resulting {@link javax.naming.ldap.LdapContext} will use
89
* an LDAP server resolved by the configured {@link
90
* javax.naming.ldap.spi.LdapDnsProvider LdapDnsProviders}:
91
* <ol>
92
* <li>If this is the first {@code InitialDirContext} created with a
93
* {@code java.naming.provider.url} using the ldap protocol then the
94
* {@linkplain java.util.ServiceLoader ServiceLoader} mechanism is
95
* used to locate {@linkplain javax.naming.ldap.spi.LdapDnsProvider
96
* LdapDnsProvider} implementations using the system class loader.
97
* The order that providers are located is implementation specific
98
* and an implementation is free to cache the located providers.
99
* <li>The {@code lookupEndpoints} method of each provider, if instantiated,
100
* is invoked once with a combination of each of the URLs in the the
101
* {@code java.naming.provider.url} property and the environment until
102
* a provider returns non-empty or all providers have been exhausted.
103
* If none of the
104
* {@linkplain javax.naming.ldap.spi.LdapDnsProvider LdapDnsProviders}
105
* return a non-empty
106
* {@linkplain javax.naming.ldap.spi.LdapDnsProviderResult result} then
107
* the implementation will make a best-effort attempt to determine an
108
* endpoint. A
109
* {@linkplain java.util.ServiceConfigurationError ServiceConfigurationError},
110
* {@code Error} or {@code RuntimeException} thrown when loading or
111
* calling an {@linkplain javax.naming.ldap.spi.LdapDnsProvider
112
* LdapDnsProvider}, if encountered, will be propagated to the calling
113
* thread.
114
* </ol>
115
*
116
* <p> This constructor will not modify {@code environment}
117
* or save a reference to it, but may save a clone.
118
* Caller should not modify mutable keys and values in
119
* {@code environment} after it has been passed to the constructor.
120
*
121
* @param environment
122
* environment used to create the initial DirContext.
123
* Null indicates an empty environment.
124
*
125
* @throws NamingException if a naming exception is encountered
126
*/
127
public InitialDirContext(Hashtable<?,?> environment)
128
throws NamingException
129
{
130
super(environment);
131
}
132
133
private DirContext getURLOrDefaultInitDirCtx(String name)
134
throws NamingException {
135
Context answer = getURLOrDefaultInitCtx(name);
136
if (!(answer instanceof DirContext)) {
137
if (answer == null) {
138
throw new NoInitialContextException();
139
} else {
140
throw new NotContextException(
141
"Not an instance of DirContext");
142
}
143
}
144
return (DirContext)answer;
145
}
146
147
private DirContext getURLOrDefaultInitDirCtx(Name name)
148
throws NamingException {
149
Context answer = getURLOrDefaultInitCtx(name);
150
if (!(answer instanceof DirContext)) {
151
if (answer == null) {
152
throw new NoInitialContextException();
153
} else {
154
throw new NotContextException(
155
"Not an instance of DirContext");
156
}
157
}
158
return (DirContext)answer;
159
}
160
161
// DirContext methods
162
// Most Javadoc is deferred to the DirContext interface.
163
164
public Attributes getAttributes(String name)
165
throws NamingException {
166
return getAttributes(name, null);
167
}
168
169
public Attributes getAttributes(String name, String[] attrIds)
170
throws NamingException {
171
return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
172
}
173
174
public Attributes getAttributes(Name name)
175
throws NamingException {
176
return getAttributes(name, null);
177
}
178
179
public Attributes getAttributes(Name name, String[] attrIds)
180
throws NamingException {
181
return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
182
}
183
184
public void modifyAttributes(String name, int mod_op, Attributes attrs)
185
throws NamingException {
186
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
187
}
188
189
public void modifyAttributes(Name name, int mod_op, Attributes attrs)
190
throws NamingException {
191
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
192
}
193
194
public void modifyAttributes(String name, ModificationItem[] mods)
195
throws NamingException {
196
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
197
}
198
199
public void modifyAttributes(Name name, ModificationItem[] mods)
200
throws NamingException {
201
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
202
}
203
204
public void bind(String name, Object obj, Attributes attrs)
205
throws NamingException {
206
getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
207
}
208
209
public void bind(Name name, Object obj, Attributes attrs)
210
throws NamingException {
211
getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
212
}
213
214
public void rebind(String name, Object obj, Attributes attrs)
215
throws NamingException {
216
getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
217
}
218
219
public void rebind(Name name, Object obj, Attributes attrs)
220
throws NamingException {
221
getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
222
}
223
224
public DirContext createSubcontext(String name, Attributes attrs)
225
throws NamingException {
226
return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
227
}
228
229
public DirContext createSubcontext(Name name, Attributes attrs)
230
throws NamingException {
231
return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
232
}
233
234
public DirContext getSchema(String name) throws NamingException {
235
return getURLOrDefaultInitDirCtx(name).getSchema(name);
236
}
237
238
public DirContext getSchema(Name name) throws NamingException {
239
return getURLOrDefaultInitDirCtx(name).getSchema(name);
240
}
241
242
public DirContext getSchemaClassDefinition(String name)
243
throws NamingException {
244
return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
245
}
246
247
public DirContext getSchemaClassDefinition(Name name)
248
throws NamingException {
249
return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
250
}
251
252
// -------------------- search operations
253
254
public NamingEnumeration<SearchResult>
255
search(String name, Attributes matchingAttributes)
256
throws NamingException
257
{
258
return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
259
}
260
261
public NamingEnumeration<SearchResult>
262
search(Name name, Attributes matchingAttributes)
263
throws NamingException
264
{
265
return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
266
}
267
268
public NamingEnumeration<SearchResult>
269
search(String name,
270
Attributes matchingAttributes,
271
String[] attributesToReturn)
272
throws NamingException
273
{
274
return getURLOrDefaultInitDirCtx(name).search(name,
275
matchingAttributes,
276
attributesToReturn);
277
}
278
279
public NamingEnumeration<SearchResult>
280
search(Name name,
281
Attributes matchingAttributes,
282
String[] attributesToReturn)
283
throws NamingException
284
{
285
return getURLOrDefaultInitDirCtx(name).search(name,
286
matchingAttributes,
287
attributesToReturn);
288
}
289
290
public NamingEnumeration<SearchResult>
291
search(String name,
292
String filter,
293
SearchControls cons)
294
throws NamingException
295
{
296
return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
297
}
298
299
public NamingEnumeration<SearchResult>
300
search(Name name,
301
String filter,
302
SearchControls cons)
303
throws NamingException
304
{
305
return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
306
}
307
308
public NamingEnumeration<SearchResult>
309
search(String name,
310
String filterExpr,
311
Object[] filterArgs,
312
SearchControls cons)
313
throws NamingException
314
{
315
return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
316
filterArgs, cons);
317
}
318
319
public NamingEnumeration<SearchResult>
320
search(Name name,
321
String filterExpr,
322
Object[] filterArgs,
323
SearchControls cons)
324
throws NamingException
325
{
326
return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
327
filterArgs, cons);
328
}
329
}
330
331