View Javadoc
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.ldap;
27  
28  import javax.naming.*;
29  import javax.naming.directory.*;
30  
31  import com.sun.jndi.toolkit.ctx.Continuation;
32  import java.util.Vector;
33  import javax.naming.ldap.Control;
34  
35  
36  final class LdapNamingEnumeration
37          extends AbstractLdapNamingEnumeration<NameClassPair> {
38  
39      private static final String defaultClassName = DirContext.class.getName();
40  
41      LdapNamingEnumeration(LdapCtx homeCtx, LdapResult answer, Name listArg,
42                                   Continuation cont) throws NamingException {
43          super(homeCtx, answer, listArg, cont);
44      }
45  
46      @Override
47      protected NameClassPair createItem(String dn, Attributes attrs,
48              Vector<Control> respCtls) throws NamingException {
49  
50          Attribute attr;
51          String className = null;
52  
53          // use the Java classname if present
54          if ((attr = attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME])) != null) {
55              className = (String)attr.get();
56          } else {
57              className = defaultClassName;
58          }
59          CompositeName cn = new CompositeName();
60          cn.add(getAtom(dn));
61  
62          NameClassPair ncp;
63          if (respCtls != null) {
64              ncp = new NameClassPairWithControls(
65                          cn.toString(), className,
66                          homeCtx.convertControls(respCtls));
67          } else {
68              ncp = new NameClassPair(cn.toString(), className);
69          }
70          ncp.setNameInNamespace(dn);
71          return ncp;
72      }
73  
74      @Override
75      protected LdapNamingEnumeration getReferredResults(
76              LdapReferralContext refCtx) throws NamingException {
77          // repeat the original operation at the new context
78          return (LdapNamingEnumeration)refCtx.list(listArg);
79      }
80  }