001/* InitialDirContext.java -- 002 Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package javax.naming.directory; 040 041import java.util.Hashtable; 042 043import javax.naming.Context; 044import javax.naming.InitialContext; 045import javax.naming.Name; 046import javax.naming.NamingEnumeration; 047import javax.naming.NamingException; 048import javax.naming.NoInitialContextException; 049import javax.naming.NotContextException; 050 051/** 052 * @author Tom Tromey (tromey@redhat.com) 053 * @date June 25, 2001 054 */ 055public class InitialDirContext extends InitialContext implements DirContext 056{ 057 public InitialDirContext () 058 throws NamingException 059 { 060 this (null); 061 } 062 063 protected InitialDirContext (boolean lazy) 064 throws NamingException 065 { 066 super (lazy); 067 } 068 069 public InitialDirContext (Hashtable<?, ?> environment) 070 throws NamingException 071 { 072 super (environment); 073 } 074 075 // The InitialContext docs suggest that this exist. And it does 076 // seem like a good idea. but the InitialDirContext docs indicate 077 // it cannot be non-private. 078 private DirContext getURLOrDefaultInitDirCtx (Name name) 079 throws NamingException 080 { 081 Context c = getURLOrDefaultInitCtx (name); 082 if (c == null) 083 throw new NoInitialContextException (); 084 else if (! (c instanceof DirContext)) 085 throw new NotContextException (); 086 return (DirContext) c; 087 } 088 089 private DirContext getURLOrDefaultInitDirCtx (String name) 090 throws NamingException 091 { 092 Context c = getURLOrDefaultInitCtx (name); 093 if (c == null) 094 throw new NoInitialContextException (); 095 else if (! (c instanceof DirContext)) 096 throw new NotContextException (); 097 return (DirContext) c; 098 } 099 100 public Attributes getAttributes (String name) 101 throws NamingException 102 { 103 return getURLOrDefaultInitDirCtx (name).getAttributes (name); 104 } 105 106 public Attributes getAttributes (String name, String[] attrIds) 107 throws NamingException 108 { 109 return getURLOrDefaultInitDirCtx (name).getAttributes (name, attrIds); 110 } 111 112 public Attributes getAttributes (Name name) 113 throws NamingException 114 { 115 return getURLOrDefaultInitDirCtx (name).getAttributes (name); 116 } 117 118 public Attributes getAttributes(Name name, String[] attrIds) 119 throws NamingException 120 { 121 return getURLOrDefaultInitDirCtx (name).getAttributes (name, attrIds); 122 } 123 124 public void modifyAttributes(Name name, int mod_op, Attributes attrs) 125 throws NamingException 126 { 127 getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mod_op, attrs); 128 } 129 130 public void modifyAttributes(String name, int mod_op, Attributes attrs) 131 throws NamingException 132 { 133 getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mod_op, attrs); 134 } 135 136 public void modifyAttributes(Name name, ModificationItem[] mods) 137 throws NamingException 138 { 139 getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mods); 140 } 141 142 public void modifyAttributes(String name, ModificationItem[] mods) 143 throws NamingException 144 { 145 getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mods); 146 } 147 148 public void bind(Name name, Object obj, Attributes attrs) 149 throws NamingException 150 { 151 getURLOrDefaultInitDirCtx (name).bind (name, obj, attrs); 152 } 153 154 public void bind(String name, Object obj, Attributes attrs) 155 throws NamingException 156 { 157 getURLOrDefaultInitDirCtx (name).bind (name, obj, attrs); 158 } 159 160 public void rebind(Name name, Object obj, Attributes attrs) 161 throws NamingException 162 { 163 getURLOrDefaultInitDirCtx (name).rebind (name, obj, attrs); 164 } 165 166 public void rebind(String name, Object obj, Attributes attrs) 167 throws NamingException 168 { 169 getURLOrDefaultInitDirCtx (name).rebind (name, obj, attrs); 170 } 171 172 public DirContext createSubcontext(Name name, Attributes attrs) 173 throws NamingException 174 { 175 return getURLOrDefaultInitDirCtx (name).createSubcontext (name, attrs); 176 } 177 178 public DirContext createSubcontext(String name, Attributes attrs) 179 throws NamingException 180 { 181 return getURLOrDefaultInitDirCtx (name).createSubcontext (name, attrs); 182 } 183 184 public DirContext getSchema(Name name) 185 throws NamingException 186 { 187 return getURLOrDefaultInitDirCtx (name).getSchema (name); 188 } 189 190 public DirContext getSchema(String name) 191 throws NamingException 192 { 193 return getURLOrDefaultInitDirCtx (name).getSchema (name); 194 } 195 196 public DirContext getSchemaClassDefinition(Name name) 197 throws NamingException 198 { 199 return getURLOrDefaultInitDirCtx (name).getSchemaClassDefinition (name); 200 } 201 202 public DirContext getSchemaClassDefinition(String name) 203 throws NamingException 204 { 205 return getURLOrDefaultInitDirCtx (name).getSchemaClassDefinition (name); 206 } 207 208 public NamingEnumeration<SearchResult> search(Name name, 209 Attributes matchingAttributes, 210 String[] attributesToReturn) 211 throws NamingException 212 { 213 return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes, 214 attributesToReturn); 215 } 216 217 public NamingEnumeration<SearchResult> search(String name, 218 Attributes matchingAttributes, 219 String[] attributesToReturn) 220 throws NamingException 221 { 222 return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes, 223 attributesToReturn); 224 } 225 226 public NamingEnumeration<SearchResult> search(Name name, 227 Attributes matchingAttributes) 228 throws NamingException 229 { 230 return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes); 231 } 232 233 public NamingEnumeration<SearchResult> search(String name, 234 Attributes matchingAttributes) 235 throws NamingException 236 { 237 return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes); 238 } 239 240 public NamingEnumeration<SearchResult> search(Name name, String filter, 241 SearchControls cons) 242 throws NamingException 243 { 244 return getURLOrDefaultInitDirCtx (name).search (name, filter, cons); 245 } 246 247 public NamingEnumeration<SearchResult> search(String name, String filter, 248 SearchControls cons) 249 throws NamingException 250 { 251 return getURLOrDefaultInitDirCtx (name).search (name, filter, cons); 252 } 253 254 public NamingEnumeration<SearchResult> search(Name name, String filterExpr, 255 Object[] filterArgs, 256 SearchControls cons) 257 throws NamingException 258 { 259 return getURLOrDefaultInitDirCtx (name).search (name, filterExpr, 260 filterArgs, cons); 261 } 262 263 public NamingEnumeration<SearchResult> search(String name, 264 String filterExpr, 265 Object[] filterArgs, 266 SearchControls cons) 267 throws NamingException 268 { 269 return getURLOrDefaultInitDirCtx (name).search (name, filterExpr, 270 filterArgs, cons); 271 } 272}