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