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 /**
32  * Direct subclasses of AtomicDirContext must provide implementations for
33  * the abstract a_ DirContext methods, and override the a_ Context methods
34  * (which are no longer abstract because they have been overriden by
35  * PartialCompositeDirContext with dummy implementations).
36  *
37  * If the subclass implements the notion of implicit nns,
38  * it must override the a_*_nns DirContext and Context methods as well.
39  *
40  * @author Rosanna Lee
41  *
42  */
43 
44 public abstract class AtomicDirContext extends ComponentDirContext {
45 
AtomicDirContext()46     protected AtomicDirContext() {
47         _contextType = _ATOMIC;
48     }
49 
50 // ------ Abstract methods whose implementations come from subclass
51 
a_getAttributes(String name, String[] attrIds, Continuation cont)52     protected abstract Attributes a_getAttributes(String name, String[] attrIds,
53                                                     Continuation cont)
54         throws NamingException;
55 
a_modifyAttributes(String name, int mod_op, Attributes attrs, Continuation cont)56     protected abstract void a_modifyAttributes(String name, int mod_op,
57                                                Attributes attrs,
58                                                Continuation cont)
59         throws NamingException;
60 
a_modifyAttributes(String name, ModificationItem[] mods, Continuation cont)61     protected abstract void a_modifyAttributes(String name,
62                                                ModificationItem[] mods,
63                                                Continuation cont)
64         throws NamingException;
65 
a_bind(String name, Object obj, Attributes attrs, Continuation cont)66     protected abstract void a_bind(String name, Object obj,
67                                    Attributes attrs,
68                                    Continuation cont)
69         throws NamingException;
70 
a_rebind(String name, Object obj, Attributes attrs, Continuation cont)71     protected abstract void a_rebind(String name, Object obj,
72                                      Attributes attrs,
73                                      Continuation cont)
74         throws NamingException;
75 
a_createSubcontext(String name, Attributes attrs, Continuation cont)76     protected abstract DirContext a_createSubcontext(String name,
77                                                     Attributes attrs,
78                                                     Continuation cont)
79         throws NamingException;
80 
a_search( Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)81     protected abstract NamingEnumeration<SearchResult> a_search(
82                                                   Attributes matchingAttributes,
83                                                   String[] attributesToReturn,
84                                                   Continuation cont)
85         throws NamingException;
86 
a_search( String name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)87     protected abstract NamingEnumeration<SearchResult> a_search(
88                                                   String name,
89                                                   String filterExpr,
90                                                   Object[] filterArgs,
91                                                   SearchControls cons,
92                                                   Continuation cont)
93         throws NamingException;
94 
a_search( String name, String filter, SearchControls cons, Continuation cont)95     protected abstract NamingEnumeration<SearchResult> a_search(
96                                                   String name,
97                                                   String filter,
98                                                   SearchControls cons,
99                                                   Continuation cont)
100         throws NamingException;
101 
a_getSchema(Continuation cont)102     protected abstract DirContext a_getSchema(Continuation cont)
103         throws NamingException;
104 
a_getSchemaClassDefinition(Continuation cont)105     protected abstract DirContext a_getSchemaClassDefinition(Continuation cont)
106         throws NamingException;
107 
108 // ------ Methods that need to be overridden by subclass
109 
110     //  default implementations of a_*_nns methods
111 
112     // The following methods are called when the DirContext methods
113     // are invoked with a name that has a trailing slash.
114     // For naming systems that support implicit nns,
115     // the trailing slash signifies the implicit nns.
116     // For such naming systems, override these a_*_nns methods.
117     //
118     // For naming systems that support junctions (explicit nns),
119     // the trailing slash is meaningless because a junction does not
120     // have an implicit nns.  The default implementation here
121     // throws a NameNotFoundException for such names.
122     // If a context wants to accept a trailing slash as having
123     // the same meaning as the same name without a trailing slash,
124     // then it should override these a_*_nns methods.
125 
a_getAttributes_nns(String name, String[] attrIds, Continuation cont)126     protected Attributes a_getAttributes_nns(String name,
127                                                String[] attrIds,
128                                                Continuation cont)
129         throws NamingException  {
130             a_processJunction_nns(name, cont);
131             return null;
132         }
133 
a_modifyAttributes_nns(String name, int mod_op, Attributes attrs, Continuation cont)134     protected void a_modifyAttributes_nns(String name, int mod_op,
135                                           Attributes attrs,
136                                           Continuation cont)
137         throws NamingException {
138             a_processJunction_nns(name, cont);
139         }
140 
a_modifyAttributes_nns(String name, ModificationItem[] mods, Continuation cont)141     protected void a_modifyAttributes_nns(String name,
142                                           ModificationItem[] mods,
143                                           Continuation cont)
144         throws NamingException {
145             a_processJunction_nns(name, cont);
146         }
147 
a_bind_nns(String name, Object obj, Attributes attrs, Continuation cont)148     protected void a_bind_nns(String name, Object obj,
149                               Attributes attrs,
150                               Continuation cont)
151         throws NamingException  {
152             a_processJunction_nns(name, cont);
153         }
154 
a_rebind_nns(String name, Object obj, Attributes attrs, Continuation cont)155     protected void a_rebind_nns(String name, Object obj,
156                                 Attributes attrs,
157                                 Continuation cont)
158         throws NamingException  {
159             a_processJunction_nns(name, cont);
160         }
161 
a_createSubcontext_nns(String name, Attributes attrs, Continuation cont)162     protected DirContext a_createSubcontext_nns(String name,
163                                                Attributes attrs,
164                                                Continuation cont)
165         throws NamingException  {
166             a_processJunction_nns(name, cont);
167             return null;
168         }
169 
a_search_nns( Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)170     protected NamingEnumeration<SearchResult> a_search_nns(
171                                              Attributes matchingAttributes,
172                                              String[] attributesToReturn,
173                                              Continuation cont)
174         throws NamingException {
175             a_processJunction_nns(cont);
176             return null;
177         }
178 
a_search_nns(String name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)179     protected NamingEnumeration<SearchResult> a_search_nns(String name,
180                                                            String filterExpr,
181                                                            Object[] filterArgs,
182                                                            SearchControls cons,
183                                                            Continuation cont)
184         throws NamingException {
185             a_processJunction_nns(name, cont);
186             return null;
187         }
188 
a_search_nns(String name, String filter, SearchControls cons, Continuation cont)189     protected NamingEnumeration<SearchResult> a_search_nns(String name,
190                                                            String filter,
191                                                            SearchControls cons,
192                                                            Continuation cont)
193         throws NamingException  {
194             a_processJunction_nns(name, cont);
195             return null;
196         }
197 
a_getSchema_nns(Continuation cont)198     protected DirContext a_getSchema_nns(Continuation cont) throws NamingException {
199         a_processJunction_nns(cont);
200         return null;
201     }
202 
a_getSchemaDefinition_nns(Continuation cont)203     protected DirContext a_getSchemaDefinition_nns(Continuation cont)
204         throws NamingException {
205             a_processJunction_nns(cont);
206             return null;
207         }
208 
209 // ------- implementations of c_ DirContext methods using corresponding
210 // ------- a_ and a_*_nns methods
211 
c_getAttributes(Name name, String[] attrIds, Continuation cont)212     protected Attributes c_getAttributes(Name name, String[] attrIds,
213                                            Continuation cont)
214         throws NamingException  {
215             if (resolve_to_penultimate_context(name, cont))
216                 return a_getAttributes(name.toString(), attrIds, cont);
217             return null;
218         }
219 
c_modifyAttributes(Name name, int mod_op, Attributes attrs, Continuation cont)220     protected void c_modifyAttributes(Name name, int mod_op,
221                                       Attributes attrs, Continuation cont)
222         throws NamingException {
223             if (resolve_to_penultimate_context(name, cont))
224                 a_modifyAttributes(name.toString(), mod_op, attrs, cont);
225         }
226 
c_modifyAttributes(Name name, ModificationItem[] mods, Continuation cont)227     protected void c_modifyAttributes(Name name, ModificationItem[] mods,
228                                       Continuation cont)
229         throws NamingException {
230             if (resolve_to_penultimate_context(name, cont))
231                 a_modifyAttributes(name.toString(), mods, cont);
232         }
233 
c_bind(Name name, Object obj, Attributes attrs, Continuation cont)234     protected void c_bind(Name name, Object obj,
235                           Attributes attrs, Continuation cont)
236         throws NamingException  {
237             if (resolve_to_penultimate_context(name, cont))
238                 a_bind(name.toString(), obj, attrs, cont);
239         }
240 
c_rebind(Name name, Object obj, Attributes attrs, Continuation cont)241     protected void c_rebind(Name name, Object obj,
242                             Attributes attrs, Continuation cont)
243         throws NamingException  {
244             if (resolve_to_penultimate_context(name, cont))
245                 a_rebind(name.toString(), obj, attrs, cont);
246         }
247 
c_createSubcontext(Name name, Attributes attrs, Continuation cont)248     protected DirContext c_createSubcontext(Name name,
249                                            Attributes attrs,
250                                            Continuation cont)
251         throws NamingException  {
252             if (resolve_to_penultimate_context(name, cont))
253                 return a_createSubcontext(name.toString(),
254                                           attrs, cont);
255             return null;
256         }
257 
c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)258     protected NamingEnumeration<SearchResult> c_search(Name name,
259                                          Attributes matchingAttributes,
260                                          String[] attributesToReturn,
261                                          Continuation cont)
262         throws NamingException  {
263             if (resolve_to_context(name, cont))
264                 return a_search(matchingAttributes, attributesToReturn, cont);
265             return null;
266         }
267 
c_search(Name name, String filter, SearchControls cons, Continuation cont)268     protected NamingEnumeration<SearchResult> c_search(Name name,
269                                                        String filter,
270                                                        SearchControls cons,
271                                                        Continuation cont)
272         throws NamingException {
273             if (resolve_to_penultimate_context(name, cont))
274                 return a_search(name.toString(), filter, cons, cont);
275             return null;
276         }
277 
c_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)278     protected NamingEnumeration<SearchResult> c_search(Name name,
279                                                        String filterExpr,
280                                                        Object[] filterArgs,
281                                                        SearchControls cons,
282                                                        Continuation cont)
283         throws NamingException  {
284             if (resolve_to_penultimate_context(name, cont))
285                 return a_search(name.toString(), filterExpr, filterArgs, cons, cont);
286             return null;
287         }
288 
c_getSchema(Name name, Continuation cont)289     protected DirContext c_getSchema(Name name, Continuation cont)
290         throws NamingException  {
291             if (resolve_to_context(name, cont))
292                 return a_getSchema(cont);
293             return null;
294         }
295 
c_getSchemaClassDefinition(Name name, Continuation cont)296     protected DirContext c_getSchemaClassDefinition(Name name, Continuation cont)
297         throws NamingException  {
298             if (resolve_to_context(name, cont))
299                 return a_getSchemaClassDefinition(cont);
300             return null;
301         }
302 
303     /* equivalent to methods in DirContext interface for nns */
304 
c_getAttributes_nns(Name name, String[] attrIds, Continuation cont)305     protected Attributes c_getAttributes_nns(Name name, String[] attrIds,
306                                            Continuation cont)
307         throws NamingException  {
308             if (resolve_to_penultimate_context_nns(name, cont))
309                 return a_getAttributes_nns(name.toString(), attrIds, cont);
310             return null;
311         }
312 
c_modifyAttributes_nns(Name name, int mod_op, Attributes attrs, Continuation cont)313     protected void c_modifyAttributes_nns(Name name, int mod_op,
314                                           Attributes attrs, Continuation cont)
315         throws NamingException {
316             if (resolve_to_penultimate_context_nns(name, cont))
317                 a_modifyAttributes_nns(name.toString(), mod_op, attrs, cont);
318         }
319 
c_modifyAttributes_nns(Name name, ModificationItem[] mods, Continuation cont)320     protected void c_modifyAttributes_nns(Name name, ModificationItem[] mods,
321                                       Continuation cont)
322         throws NamingException {
323             if (resolve_to_penultimate_context_nns(name, cont))
324                 a_modifyAttributes_nns(name.toString(), mods, cont);
325         }
326 
c_bind_nns(Name name, Object obj, Attributes attrs, Continuation cont)327     protected void c_bind_nns(Name name, Object obj,
328                               Attributes attrs, Continuation cont)
329         throws NamingException  {
330             if (resolve_to_penultimate_context_nns(name, cont))
331                 a_bind_nns(name.toString(), obj, attrs, cont);
332         }
333 
c_rebind_nns(Name name, Object obj, Attributes attrs, Continuation cont)334     protected void c_rebind_nns(Name name, Object obj,
335                                 Attributes attrs, Continuation cont)
336         throws NamingException  {
337             if (resolve_to_penultimate_context_nns(name, cont))
338                 a_rebind_nns(name.toString(), obj, attrs, cont);
339         }
340 
c_createSubcontext_nns(Name name, Attributes attrs, Continuation cont)341     protected DirContext c_createSubcontext_nns(Name name,
342                                                Attributes attrs,
343                                                Continuation cont)
344         throws NamingException  {
345             if (resolve_to_penultimate_context_nns(name, cont))
346                 return a_createSubcontext_nns(name.toString(), attrs, cont);
347             return null;
348         }
349 
c_search_nns( Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)350     protected NamingEnumeration<SearchResult> c_search_nns(
351                                          Name name,
352                                          Attributes matchingAttributes,
353                                          String[] attributesToReturn,
354                                          Continuation cont)
355         throws NamingException  {
356             resolve_to_nns_and_continue(name, cont);
357             return null;
358         }
359 
c_search_nns(Name name, String filter, SearchControls cons, Continuation cont)360     protected NamingEnumeration<SearchResult> c_search_nns(Name name,
361                                                            String filter,
362                                                            SearchControls cons,
363                                                            Continuation cont)
364         throws NamingException {
365             if (resolve_to_penultimate_context_nns(name, cont))
366                 return a_search_nns(name.toString(), filter, cons, cont);
367             return null;
368         }
369 
c_search_nns(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)370     protected NamingEnumeration<SearchResult> c_search_nns(Name name,
371                                                            String filterExpr,
372                                                            Object[] filterArgs,
373                                                            SearchControls cons,
374                                                            Continuation cont)
375         throws NamingException  {
376             if (resolve_to_penultimate_context_nns(name, cont))
377                 return a_search_nns(name.toString(), filterExpr, filterArgs,
378                                     cons, cont);
379             return null;
380         }
381 
c_getSchema_nns(Name name, Continuation cont)382     protected DirContext c_getSchema_nns(Name name, Continuation cont)
383         throws NamingException  {
384             resolve_to_nns_and_continue(name, cont);
385             return null;
386         }
387 
c_getSchemaClassDefinition_nns(Name name, Continuation cont)388     protected DirContext c_getSchemaClassDefinition_nns(Name name, Continuation cont)
389         throws NamingException  {
390             resolve_to_nns_and_continue(name, cont);
391             return null;
392         }
393 }
394