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.jndi.toolkit.ctx;
27 
28 import javax.naming.*;
29 import javax.naming.directory.*;
30 
31 /* Direct subclasses of ComponentDirContext must provide implementations for
32  * the abstract c_ DirContext methods, and override the c_ Context methods
33  * (which are no longer abstract because they have been overriden by
34  * AtomicContext, the direct superclass of PartialDSCompositeContext).
35  *
36  * If the subclass is supports implicit nns, it must override all the
37  * c_*_nns methods corresponding to those in DirContext and Context.
38  * See ComponentContext for details.
39  *
40  * @author Rosanna Lee
41  */
42 
43 public abstract class ComponentDirContext extends PartialCompositeDirContext {
44 
ComponentDirContext()45     protected ComponentDirContext () {
46         _contextType = _COMPONENT;
47     }
48 
49 // ------ Abstract methods whose implementations are provided by subclass
50 
51     /* Equivalent to methods in DirContext */
c_getAttributes(Name name, String[] attrIds, Continuation cont)52     protected abstract Attributes c_getAttributes(Name name,
53                                                  String[] attrIds,
54                                                  Continuation cont)
55         throws NamingException;
56 
c_modifyAttributes(Name name, int mod_op, Attributes attrs, Continuation cont)57     protected abstract void c_modifyAttributes(Name name, int mod_op,
58                                             Attributes attrs,
59                                             Continuation cont)
60             throws NamingException;
61 
c_modifyAttributes(Name name, ModificationItem[] mods, Continuation cont)62     protected abstract void c_modifyAttributes(Name name,
63                                             ModificationItem[] mods,
64                                             Continuation cont)
65         throws NamingException;
66 
c_bind(Name name, Object obj, Attributes attrs, Continuation cont)67     protected abstract void c_bind(Name name, Object obj,
68                                    Attributes attrs,
69                                    Continuation cont)
70         throws NamingException;
71 
c_rebind(Name name, Object obj, Attributes attrs, Continuation cont)72     protected abstract void c_rebind(Name name, Object obj,
73                                      Attributes attrs,
74                                      Continuation cont)
75         throws NamingException;
76 
c_createSubcontext(Name name, Attributes attrs, Continuation cont)77     protected abstract DirContext c_createSubcontext(Name name,
78                                                     Attributes attrs,
79                                                     Continuation cont)
80         throws NamingException;
81 
c_search( Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)82     protected abstract NamingEnumeration<SearchResult> c_search(
83                             Name name,
84                             Attributes matchingAttributes,
85                             String[] attributesToReturn,
86                             Continuation cont)
87         throws NamingException;
88 
c_search( Name name, String filter, SearchControls cons, Continuation cont)89     protected abstract NamingEnumeration<SearchResult> c_search(
90                             Name name,
91                             String filter,
92                             SearchControls cons,
93                             Continuation cont)
94         throws NamingException;
95 
c_search( Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)96     protected abstract NamingEnumeration<SearchResult> c_search(
97                             Name name,
98                             String filterExpr,
99                             Object[] filterArgs,
100                             SearchControls cons,
101                             Continuation cont)
102         throws NamingException;
103 
c_getSchema(Name name, Continuation cont)104     protected abstract DirContext c_getSchema(Name name, Continuation cont)
105         throws NamingException;
106 
c_getSchemaClassDefinition(Name name, Continuation cont)107     protected abstract DirContext c_getSchemaClassDefinition(Name name,
108                                                             Continuation cont)
109         throws NamingException;
110 
111 // ------- default implementations of c_*_nns methods from DirContext
112 
113     // The following methods are called when the DirContext methods
114     // are invoked with a name that has a trailing slash.
115     // For naming systems that support implicit nns,
116     // the trailing slash signifies the implicit nns.
117     // For such naming systems, override these c_*_nns methods.
118     //
119     // For naming systems that support junctions (explicit nns),
120     // the trailing slash is meaningless because a junction does not
121     // have an implicit nns.  The default implementation here
122     // throws a NameNotFoundException for such names.
123     // If a context wants to accept a trailing slash as having
124     // the same meaning as the same name without a trailing slash,
125     // then it should override these c_*_nns methods.
126 
127     // See ComponentContext for details.
128 
c_getAttributes_nns(Name name, String[] attrIds, Continuation cont)129     protected Attributes c_getAttributes_nns(Name name,
130                                             String[] attrIds,
131                                             Continuation cont)
132         throws NamingException {
133             c_processJunction_nns(name, cont);
134             return null;
135         }
136 
c_modifyAttributes_nns(Name name, int mod_op, Attributes attrs, Continuation cont)137     protected void c_modifyAttributes_nns(Name name,
138                                        int mod_op,
139                                        Attributes attrs,
140                                        Continuation cont)
141         throws NamingException {
142             c_processJunction_nns(name, cont);
143         }
144 
c_modifyAttributes_nns(Name name, ModificationItem[] mods, Continuation cont)145     protected void c_modifyAttributes_nns(Name name,
146                                        ModificationItem[] mods,
147                                        Continuation cont)
148         throws NamingException {
149             c_processJunction_nns(name, cont);
150         }
151 
c_bind_nns(Name name, Object obj, Attributes attrs, Continuation cont)152     protected void c_bind_nns(Name name,
153                               Object obj,
154                               Attributes attrs,
155                               Continuation cont)
156         throws NamingException  {
157             c_processJunction_nns(name, cont);
158         }
159 
c_rebind_nns(Name name, Object obj, Attributes attrs, Continuation cont)160     protected void c_rebind_nns(Name name,
161                                 Object obj,
162                                 Attributes attrs,
163                                 Continuation cont)
164         throws NamingException  {
165             c_processJunction_nns(name, cont);
166         }
167 
c_createSubcontext_nns(Name name, Attributes attrs, Continuation cont)168     protected DirContext c_createSubcontext_nns(Name name,
169                                                Attributes attrs,
170                                                Continuation cont)
171         throws NamingException  {
172             c_processJunction_nns(name, cont);
173             return null;
174         }
175 
c_search_nns( Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)176     protected NamingEnumeration<SearchResult> c_search_nns(
177                         Name name,
178                         Attributes matchingAttributes,
179                         String[] attributesToReturn,
180                         Continuation cont)
181         throws NamingException {
182             c_processJunction_nns(name, cont);
183             return null;
184         }
185 
c_search_nns( Name name, String filter, SearchControls cons, Continuation cont)186     protected NamingEnumeration<SearchResult> c_search_nns(
187                         Name name,
188                         String filter,
189                         SearchControls cons,
190                         Continuation cont)
191         throws NamingException  {
192             c_processJunction_nns(name, cont);
193             return null;
194         }
195 
c_search_nns( Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)196     protected NamingEnumeration<SearchResult> c_search_nns(
197                         Name name,
198                         String filterExpr,
199                         Object[] filterArgs,
200                         SearchControls cons,
201                         Continuation cont)
202         throws NamingException  {
203             c_processJunction_nns(name, cont);
204             return null;
205         }
206 
c_getSchema_nns(Name name, Continuation cont)207     protected DirContext c_getSchema_nns(Name name, Continuation cont)
208         throws NamingException {
209             c_processJunction_nns(name, cont);
210             return null;
211         }
212 
c_getSchemaClassDefinition_nns(Name name, Continuation cont)213     protected DirContext c_getSchemaClassDefinition_nns(Name name, Continuation cont)
214         throws NamingException {
215             c_processJunction_nns(name, cont);
216             return null;
217         }
218 
219 // ------- implementations of p_ DirContext methods using corresponding
220 // ------- DirContext c_ and c_*_nns methods
221 
222     /* Implements for abstract methods declared in PartialCompositeDirContext */
p_getAttributes(Name name, String[] attrIds, Continuation cont)223     protected Attributes p_getAttributes(Name name,
224                                         String[] attrIds,
225                                         Continuation cont)
226         throws NamingException  {
227         HeadTail res = p_resolveIntermediate(name, cont);
228         Attributes answer = null;
229         switch (res.getStatus()) {
230             case TERMINAL_NNS_COMPONENT:
231                 answer = c_getAttributes_nns(res.getHead(), attrIds, cont);
232                 break;
233 
234             case TERMINAL_COMPONENT:
235                 answer = c_getAttributes(res.getHead(), attrIds, cont);
236                 break;
237 
238             default:
239                 /* USE_CONTINUATION */
240                 /* cont already set or exception thrown */
241                 break;
242             }
243         return answer;
244     }
245 
p_modifyAttributes(Name name, int mod_op, Attributes attrs, Continuation cont)246     protected void p_modifyAttributes(Name name, int mod_op,
247                                    Attributes attrs,
248                                    Continuation cont)
249         throws NamingException {
250         HeadTail res = p_resolveIntermediate(name, cont);
251         switch (res.getStatus()) {
252             case TERMINAL_NNS_COMPONENT:
253                 c_modifyAttributes_nns(res.getHead(), mod_op, attrs, cont);
254                 break;
255 
256             case TERMINAL_COMPONENT:
257                 c_modifyAttributes(res.getHead(), mod_op, attrs, cont);
258                 break;
259 
260             default:
261                 /* USE_CONTINUATION */
262                 /* cont already set or exception thrown */
263                 break;
264             }
265     }
p_modifyAttributes(Name name, ModificationItem[] mods, Continuation cont)266     protected void p_modifyAttributes(Name name,
267                                    ModificationItem[] mods,
268                                    Continuation cont)
269         throws NamingException {
270         HeadTail res = p_resolveIntermediate(name, cont);
271         switch (res.getStatus()) {
272             case TERMINAL_NNS_COMPONENT:
273                 c_modifyAttributes_nns(res.getHead(), mods, cont);
274                 break;
275 
276             case TERMINAL_COMPONENT:
277                 c_modifyAttributes(res.getHead(), mods, cont);
278                 break;
279 
280             default:
281                 /* USE_CONTINUATION */
282                 /* cont already set or exception thrown */
283                 break;
284             }
285     }
286 
p_bind(Name name, Object obj, Attributes attrs, Continuation cont)287     protected void p_bind(Name name,
288                           Object obj,
289                           Attributes attrs,
290                           Continuation cont)
291         throws NamingException {
292         HeadTail res = p_resolveIntermediate(name, cont);
293         switch (res.getStatus()) {
294             case TERMINAL_NNS_COMPONENT:
295                 c_bind_nns(res.getHead(), obj, attrs, cont);
296                 break;
297 
298             case TERMINAL_COMPONENT:
299                 c_bind(res.getHead(), obj, attrs, cont);
300                 break;
301 
302             default:
303                 /* USE_CONTINUATION */
304                 /* cont already set or exception thrown */
305                 break;
306             }
307     }
308 
p_rebind(Name name, Object obj, Attributes attrs, Continuation cont)309     protected void p_rebind(Name name, Object obj,
310                             Attributes attrs, Continuation cont)
311         throws NamingException {
312         HeadTail res = p_resolveIntermediate(name, cont);
313         switch (res.getStatus()) {
314             case TERMINAL_NNS_COMPONENT:
315                 c_rebind_nns(res.getHead(), obj, attrs, cont);
316                 break;
317 
318             case TERMINAL_COMPONENT:
319                 c_rebind(res.getHead(), obj, attrs, cont);
320                 break;
321 
322             default:
323                 /* USE_CONTINUATION */
324                 /* cont already set or exception thrown */
325                 break;
326             }
327     }
328 
p_createSubcontext(Name name, Attributes attrs, Continuation cont)329     protected DirContext p_createSubcontext(Name name,
330                                            Attributes attrs,
331                                            Continuation cont)
332         throws NamingException {
333         HeadTail res = p_resolveIntermediate(name, cont);
334         DirContext answer = null;
335         switch (res.getStatus()) {
336             case TERMINAL_NNS_COMPONENT:
337                 answer = c_createSubcontext_nns(res.getHead(), attrs, cont);
338                 break;
339 
340             case TERMINAL_COMPONENT:
341                 answer = c_createSubcontext(res.getHead(), attrs, cont);
342                 break;
343 
344             default:
345                 /* USE_CONTINUATION */
346                 /* cont already set or exception thrown */
347                 break;
348             }
349         return answer;
350     }
351 
p_search( Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)352     protected NamingEnumeration<SearchResult> p_search(
353                     Name name,
354                     Attributes matchingAttributes,
355                     String[] attributesToReturn,
356                     Continuation cont)
357         throws NamingException {
358         HeadTail res = p_resolveIntermediate(name, cont);
359         NamingEnumeration<SearchResult> answer = null;
360         switch (res.getStatus()) {
361             case TERMINAL_NNS_COMPONENT:
362                 answer = c_search_nns(res.getHead(), matchingAttributes,
363                                       attributesToReturn, cont);
364                 break;
365 
366             case TERMINAL_COMPONENT:
367                 answer = c_search(res.getHead(), matchingAttributes,
368                                   attributesToReturn, cont);
369                 break;
370 
371             default:
372                 /* USE_CONTINUATION */
373                 /* cont already set or exception thrown */
374                 break;
375             }
376         return answer;
377     }
378 
p_search(Name name, String filter, SearchControls cons, Continuation cont)379     protected NamingEnumeration<SearchResult> p_search(Name name,
380                                                        String filter,
381                                                        SearchControls cons,
382                                                        Continuation cont)
383         throws NamingException {
384         HeadTail res = p_resolveIntermediate(name, cont);
385         NamingEnumeration<SearchResult> answer = null;
386         switch (res.getStatus()) {
387             case TERMINAL_NNS_COMPONENT:
388                 answer = c_search_nns(res.getHead(), filter, cons, cont);
389                 break;
390 
391             case TERMINAL_COMPONENT:
392                 answer = c_search(res.getHead(), filter, cons, cont);
393                 break;
394 
395             default:
396                 /* USE_CONTINUATION */
397                 /* cont already set or exception thrown */
398                 break;
399             }
400         return answer;
401     }
402 
p_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)403     protected NamingEnumeration<SearchResult> p_search(Name name,
404                                                        String filterExpr,
405                                                        Object[] filterArgs,
406                                                        SearchControls cons,
407                                                        Continuation cont)
408             throws NamingException {
409         HeadTail res = p_resolveIntermediate(name, cont);
410         NamingEnumeration<SearchResult> answer = null;
411         switch (res.getStatus()) {
412             case TERMINAL_NNS_COMPONENT:
413                 answer = c_search_nns(res.getHead(),
414                                       filterExpr, filterArgs, cons, cont);
415                 break;
416 
417             case TERMINAL_COMPONENT:
418                 answer = c_search(res.getHead(), filterExpr, filterArgs, cons, cont);
419                 break;
420 
421             default:
422                 /* USE_CONTINUATION */
423                 /* cont already set or exception thrown */
424                 break;
425             }
426         return answer;
427     }
428 
p_getSchema(Name name, Continuation cont)429     protected DirContext p_getSchema(Name name, Continuation cont)
430         throws NamingException  {
431             DirContext answer = null;
432             HeadTail res = p_resolveIntermediate(name, cont);
433             switch (res.getStatus()) {
434             case TERMINAL_NNS_COMPONENT:
435                 answer = c_getSchema_nns(res.getHead(), cont);
436                 break;
437 
438             case TERMINAL_COMPONENT:
439                 answer = c_getSchema(res.getHead(), cont);
440                 break;
441 
442             default:
443                 /* USE_CONTINUATION */
444                 /* cont already set or exception thrown */
445                 break;
446             }
447             return answer;
448         }
449 
p_getSchemaClassDefinition(Name name, Continuation cont)450     protected DirContext p_getSchemaClassDefinition(Name name, Continuation cont)
451         throws NamingException  {
452             DirContext answer = null;
453             HeadTail res = p_resolveIntermediate(name, cont);
454             switch (res.getStatus()) {
455             case TERMINAL_NNS_COMPONENT:
456                 answer = c_getSchemaClassDefinition_nns(res.getHead(), cont);
457                 break;
458 
459             case TERMINAL_COMPONENT:
460                 answer = c_getSchemaClassDefinition(res.getHead(), cont);
461                 break;
462 
463             default:
464                 /* USE_CONTINUATION */
465                 /* cont already set or exception thrown */
466                 break;
467             }
468             return answer;
469         }
470 }
471