KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > directory > InitialDirContext


1 /*
2  * @(#)InitialDirContext.java 1.11 04/07/16
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9 package javax.naming.directory;
10
11 import java.util.Hashtable JavaDoc;
12 import javax.naming.spi.NamingManager JavaDoc;
13 import javax.naming.*;
14
15 /**
16  * This class is the starting context for performing
17  * directory operations. The documentation in the class description
18  * of InitialContext (including those for synchronization) apply here.
19  *
20  *
21  * @author Rosanna Lee
22  * @author Scott Seligman
23  * @version 1.11 04/07/16
24  *
25  * @see javax.naming.InitialContext
26  * @since 1.3
27  */

28
29 public class InitialDirContext extends InitialContext implements DirContext JavaDoc {
30
31     /**
32      * Constructs an initial DirContext with the option of not
33      * initializing it. This may be used by a constructor in
34      * a subclass when the value of the environment parameter
35      * is not yet known at the time the <tt>InitialDirContext</tt>
36      * constructor is called. The subclass's constructor will
37      * call this constructor, compute the value of the environment,
38      * and then call <tt>init()</tt> before returning.
39      *
40      * @param lazy
41      * true means do not initialize the initial DirContext; false
42      * is equivalent to calling <tt>new InitialDirContext()</tt>
43      * @throws NamingException if a naming exception is encountered
44      *
45      * @see InitialContext#init(Hashtable)
46      * @since 1.3
47      */

48     protected InitialDirContext(boolean lazy) throws NamingException {
49     super(lazy);
50     }
51
52     /**
53      * Constructs an initial DirContext.
54      * No environment properties are supplied.
55      * Equivalent to <tt>new InitialDirContext(null)</tt>.
56      *
57      * @throws NamingException if a naming exception is encountered
58      *
59      * @see #InitialDirContext(Hashtable)
60      */

61     public InitialDirContext() throws NamingException {
62     super();
63     }
64
65     /**
66      * Constructs an initial DirContext using the supplied environment.
67      * Environment properties are discussed in the
68      * <tt>javax.naming.InitialContext</tt> class description.
69      *
70      * <p> This constructor will not modify <tt>environment</tt>
71      * or save a reference to it, but may save a clone.
72      *
73      * @param environment
74      * environment used to create the initial DirContext.
75      * Null indicates an empty environment.
76      *
77      * @throws NamingException if a naming exception is encountered
78      */

79     public InitialDirContext(Hashtable JavaDoc<?,?> environment)
80     throws NamingException
81     {
82     super(environment);
83     }
84
85     private DirContext JavaDoc getURLOrDefaultInitDirCtx(String JavaDoc name)
86         throws NamingException {
87     Context answer = getURLOrDefaultInitCtx(name);
88     if (!(answer instanceof DirContext JavaDoc)) {
89         if (answer == null) {
90         throw new NoInitialContextException();
91         } else {
92         throw new NotContextException(
93             "Not an instance of DirContext");
94         }
95     }
96     return (DirContext JavaDoc)answer;
97     }
98
99     private DirContext JavaDoc getURLOrDefaultInitDirCtx(Name name)
100         throws NamingException {
101     Context answer = getURLOrDefaultInitCtx(name);
102     if (!(answer instanceof DirContext JavaDoc)) {
103         if (answer == null) {
104         throw new NoInitialContextException();
105         } else {
106         throw new NotContextException(
107             "Not an instance of DirContext");
108         }
109     }
110     return (DirContext JavaDoc)answer;
111     }
112
113 // DirContext methods
114
// Most Javadoc is deferred to the DirContext interface.
115

116     public Attributes JavaDoc getAttributes(String JavaDoc name)
117         throws NamingException {
118     return getAttributes(name, null);
119     }
120
121     public Attributes JavaDoc getAttributes(String JavaDoc name, String JavaDoc[] attrIds)
122         throws NamingException {
123     return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
124     }
125
126     public Attributes JavaDoc getAttributes(Name name)
127         throws NamingException {
128     return getAttributes(name, null);
129     }
130
131     public Attributes JavaDoc getAttributes(Name name, String JavaDoc[] attrIds)
132         throws NamingException {
133     return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
134     }
135
136     public void modifyAttributes(String JavaDoc name, int mod_op, Attributes JavaDoc attrs)
137         throws NamingException {
138     getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
139     }
140
141     public void modifyAttributes(Name name, int mod_op, Attributes JavaDoc attrs)
142         throws NamingException {
143     getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
144     }
145
146     public void modifyAttributes(String JavaDoc name, ModificationItem JavaDoc[] mods)
147         throws NamingException {
148     getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
149     }
150
151     public void modifyAttributes(Name name, ModificationItem JavaDoc[] mods)
152         throws NamingException {
153     getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
154     }
155
156     public void bind(String JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs)
157         throws NamingException {
158     getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
159     }
160
161     public void bind(Name name, Object JavaDoc obj, Attributes JavaDoc attrs)
162         throws NamingException {
163     getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
164     }
165
166     public void rebind(String JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs)
167         throws NamingException {
168     getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
169     }
170
171     public void rebind(Name name, Object JavaDoc obj, Attributes JavaDoc attrs)
172         throws NamingException {
173     getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
174     }
175
176     public DirContext JavaDoc createSubcontext(String JavaDoc name, Attributes JavaDoc attrs)
177         throws NamingException {
178     return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
179     }
180
181     public DirContext JavaDoc createSubcontext(Name name, Attributes JavaDoc attrs)
182         throws NamingException {
183     return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
184     }
185
186     public DirContext JavaDoc getSchema(String JavaDoc name) throws NamingException {
187     return getURLOrDefaultInitDirCtx(name).getSchema(name);
188     }
189
190     public DirContext JavaDoc getSchema(Name name) throws NamingException {
191     return getURLOrDefaultInitDirCtx(name).getSchema(name);
192     }
193
194     public DirContext JavaDoc getSchemaClassDefinition(String JavaDoc name)
195         throws NamingException {
196     return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
197     }
198
199     public DirContext JavaDoc getSchemaClassDefinition(Name name)
200         throws NamingException {
201     return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
202     }
203
204 // -------------------- search operations
205

206     public NamingEnumeration<SearchResult JavaDoc>
207     search(String JavaDoc name, Attributes JavaDoc matchingAttributes)
208     throws NamingException
209     {
210     return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
211     }
212
213     public NamingEnumeration<SearchResult JavaDoc>
214     search(Name name, Attributes JavaDoc matchingAttributes)
215     throws NamingException
216     {
217     return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
218     }
219
220     public NamingEnumeration<SearchResult JavaDoc>
221     search(String JavaDoc name,
222            Attributes JavaDoc matchingAttributes,
223            String JavaDoc[] attributesToReturn)
224     throws NamingException
225     {
226     return getURLOrDefaultInitDirCtx(name).search(name,
227                               matchingAttributes,
228                               attributesToReturn);
229     }
230
231     public NamingEnumeration<SearchResult JavaDoc>
232     search(Name name,
233            Attributes JavaDoc matchingAttributes,
234            String JavaDoc[] attributesToReturn)
235     throws NamingException
236     {
237     return getURLOrDefaultInitDirCtx(name).search(name,
238                         matchingAttributes,
239                         attributesToReturn);
240     }
241
242     public NamingEnumeration<SearchResult JavaDoc>
243     search(String JavaDoc name,
244            String JavaDoc filter,
245            SearchControls JavaDoc cons)
246     throws NamingException
247     {
248     return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
249     }
250
251     public NamingEnumeration<SearchResult JavaDoc>
252     search(Name name,
253            String JavaDoc filter,
254            SearchControls JavaDoc cons)
255     throws NamingException
256     {
257     return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
258     }
259
260     public NamingEnumeration<SearchResult JavaDoc>
261     search(String JavaDoc name,
262            String JavaDoc filterExpr,
263            Object JavaDoc[] filterArgs,
264            SearchControls JavaDoc cons)
265     throws NamingException
266     {
267     return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
268                               filterArgs, cons);
269     }
270
271     public NamingEnumeration<SearchResult JavaDoc>
272     search(Name name,
273            String JavaDoc filterExpr,
274            Object JavaDoc[] filterArgs,
275            SearchControls JavaDoc cons)
276     throws NamingException
277     {
278     return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
279                               filterArgs, cons);
280     }
281 }
282
Popular Tags