KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > spi > ContinuationDirContext


1 /*
2  * @(#)ContinuationDirContext.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.naming.spi;
9
10 import java.util.Hashtable JavaDoc;
11
12 import javax.naming.Name JavaDoc;
13 import javax.naming.NamingEnumeration JavaDoc;
14 import javax.naming.CompositeName JavaDoc;
15 import javax.naming.NamingException JavaDoc;
16 import javax.naming.CannotProceedException JavaDoc;
17 import javax.naming.OperationNotSupportedException JavaDoc;
18 import javax.naming.Context JavaDoc;
19
20 import javax.naming.directory.DirContext JavaDoc;
21 import javax.naming.directory.Attributes JavaDoc;
22 import javax.naming.directory.SearchControls JavaDoc;
23 import javax.naming.directory.ModificationItem JavaDoc;
24
25 /**
26   * This class is the continuation context for invoking DirContext methods.
27   *
28   * @author Rosanna Lee
29   * @author Scott Seligman
30   * @version 1.8 03/12/19
31   * @since 1.3
32   */

33
34 class ContinuationDirContext extends ContinuationContext JavaDoc implements DirContext JavaDoc {
35
36     ContinuationDirContext(CannotProceedException JavaDoc cpe, Hashtable JavaDoc env) {
37     super(cpe, env);
38     }
39
40     protected DirContextNamePair getTargetContext(Name JavaDoc name)
41         throws NamingException JavaDoc {
42
43     if (cpe.getResolvedObj() == null)
44         throw (NamingException JavaDoc)cpe.fillInStackTrace();
45
46     Context JavaDoc ctx = NamingManager.getContext(cpe.getResolvedObj(),
47                            cpe.getAltName(),
48                            cpe.getAltNameCtx(),
49                            env);
50     if (ctx == null)
51         throw (NamingException JavaDoc)cpe.fillInStackTrace();
52
53     if (ctx instanceof DirContext JavaDoc)
54         return new DirContextNamePair((DirContext JavaDoc)ctx, name);
55
56     if (ctx instanceof Resolver JavaDoc) {
57         Resolver JavaDoc res = (Resolver JavaDoc)ctx;
58         ResolveResult JavaDoc rr = res.resolveToClass(name, DirContext JavaDoc.class);
59
60         // Reached a DirContext; return result.
61
DirContext JavaDoc dctx = (DirContext JavaDoc)rr.getResolvedObj();
62         return (new DirContextNamePair(dctx, rr.getRemainingName()));
63     }
64
65     // Resolve all the way using lookup(). This may allow the operation
66
// to succeed if it doesn't require the penultimate context.
67
Object JavaDoc ultimate = ctx.lookup(name);
68     if (ultimate instanceof DirContext JavaDoc) {
69         return (new DirContextNamePair((DirContext JavaDoc)ultimate,
70                       new CompositeName JavaDoc()));
71     }
72
73     throw (NamingException JavaDoc)cpe.fillInStackTrace();
74     }
75
76     protected DirContextStringPair getTargetContext(String JavaDoc name)
77         throws NamingException JavaDoc {
78
79     if (cpe.getResolvedObj() == null)
80         throw (NamingException JavaDoc)cpe.fillInStackTrace();
81
82     Context JavaDoc ctx = NamingManager.getContext(cpe.getResolvedObj(),
83                            cpe.getAltName(),
84                            cpe.getAltNameCtx(),
85                            env);
86
87     if (ctx instanceof DirContext JavaDoc)
88         return new DirContextStringPair((DirContext JavaDoc)ctx, name);
89
90     if (ctx instanceof Resolver JavaDoc) {
91         Resolver JavaDoc res = (Resolver JavaDoc)ctx;
92         ResolveResult JavaDoc rr = res.resolveToClass(name, DirContext JavaDoc.class);
93
94         // Reached a DirContext; return result.
95
DirContext JavaDoc dctx = (DirContext JavaDoc)rr.getResolvedObj();
96         Name JavaDoc tmp = rr.getRemainingName();
97         String JavaDoc remains = (tmp != null) ? tmp.toString() : "";
98         return (new DirContextStringPair(dctx, remains));
99     }
100
101     // Resolve all the way using lookup(). This may allow the operation
102
// to succeed if it doesn't require the penultimate context.
103
Object JavaDoc ultimate = ctx.lookup(name);
104     if (ultimate instanceof DirContext JavaDoc) {
105         return (new DirContextStringPair((DirContext JavaDoc)ultimate, ""));
106     }
107
108     throw (NamingException JavaDoc)cpe.fillInStackTrace();
109     }
110
111     public Attributes JavaDoc getAttributes(String JavaDoc name) throws NamingException JavaDoc {
112     DirContextStringPair res = getTargetContext(name);
113     return res.getDirContext().getAttributes(res.getString());
114     }
115
116     public Attributes JavaDoc getAttributes(String JavaDoc name, String JavaDoc[] attrIds)
117     throws NamingException JavaDoc {
118         DirContextStringPair res = getTargetContext(name);
119         return res.getDirContext().getAttributes(res.getString(), attrIds);
120     }
121
122     public Attributes JavaDoc getAttributes(Name JavaDoc name) throws NamingException JavaDoc {
123     DirContextNamePair res = getTargetContext(name);
124     return res.getDirContext().getAttributes(res.getName());
125     }
126
127     public Attributes JavaDoc getAttributes(Name JavaDoc name, String JavaDoc[] attrIds)
128     throws NamingException JavaDoc {
129         DirContextNamePair res = getTargetContext(name);
130         return res.getDirContext().getAttributes(res.getName(), attrIds);
131     }
132
133     public void modifyAttributes(Name JavaDoc name, int mod_op, Attributes JavaDoc attrs)
134     throws NamingException JavaDoc {
135         DirContextNamePair res = getTargetContext(name);
136         res.getDirContext().modifyAttributes(res.getName(), mod_op, attrs);
137     }
138     public void modifyAttributes(String JavaDoc name, int mod_op, Attributes JavaDoc attrs)
139     throws NamingException JavaDoc {
140         DirContextStringPair res = getTargetContext(name);
141         res.getDirContext().modifyAttributes(res.getString(), mod_op, attrs);
142     }
143
144     public void modifyAttributes(Name JavaDoc name, ModificationItem JavaDoc[] mods)
145     throws NamingException JavaDoc {
146         DirContextNamePair res = getTargetContext(name);
147         res.getDirContext().modifyAttributes(res.getName(), mods);
148     }
149     public void modifyAttributes(String JavaDoc name, ModificationItem JavaDoc[] mods)
150     throws NamingException JavaDoc {
151         DirContextStringPair res = getTargetContext(name);
152         res.getDirContext().modifyAttributes(res.getString(), mods);
153     }
154
155     public void bind(Name JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs)
156     throws NamingException JavaDoc {
157         DirContextNamePair res = getTargetContext(name);
158         res.getDirContext().bind(res.getName(), obj, attrs);
159     }
160     public void bind(String JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs)
161     throws NamingException JavaDoc {
162         DirContextStringPair res = getTargetContext(name);
163         res.getDirContext().bind(res.getString(), obj, attrs);
164     }
165
166     public void rebind(Name JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs)
167         throws NamingException JavaDoc {
168         DirContextNamePair res = getTargetContext(name);
169         res.getDirContext().rebind(res.getName(), obj, attrs);
170     }
171     public void rebind(String JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs)
172         throws NamingException JavaDoc {
173         DirContextStringPair res = getTargetContext(name);
174         res.getDirContext().rebind(res.getString(), obj, attrs);
175     }
176     
177     public DirContext JavaDoc createSubcontext(Name JavaDoc name, Attributes JavaDoc attrs)
178         throws NamingException JavaDoc {
179         DirContextNamePair res = getTargetContext(name);
180         return res.getDirContext().createSubcontext(res.getName(), attrs);
181     }
182
183     public DirContext JavaDoc createSubcontext(String JavaDoc name, Attributes JavaDoc attrs)
184         throws NamingException JavaDoc {
185         DirContextStringPair res = getTargetContext(name);
186         return
187         res.getDirContext().createSubcontext(res.getString(), attrs);
188     }
189
190     public NamingEnumeration JavaDoc search(Name JavaDoc name,
191                     Attributes JavaDoc matchingAttributes,
192                     String JavaDoc[] attributesToReturn)
193     throws NamingException JavaDoc {
194         DirContextNamePair res = getTargetContext(name);
195         return res.getDirContext().search(res.getName(), matchingAttributes,
196                          attributesToReturn);
197     }
198
199     public NamingEnumeration JavaDoc search(String JavaDoc name,
200                     Attributes JavaDoc matchingAttributes,
201                     String JavaDoc[] attributesToReturn)
202     throws NamingException JavaDoc {
203         DirContextStringPair res = getTargetContext(name);
204         return res.getDirContext().search(res.getString(),
205                          matchingAttributes,
206                          attributesToReturn);
207     }
208
209     public NamingEnumeration JavaDoc search(Name JavaDoc name,
210                     Attributes JavaDoc matchingAttributes)
211     throws NamingException JavaDoc {
212         DirContextNamePair res = getTargetContext(name);
213         return res.getDirContext().search(res.getName(), matchingAttributes);
214     }
215     public NamingEnumeration JavaDoc search(String JavaDoc name,
216                     Attributes JavaDoc matchingAttributes)
217     throws NamingException JavaDoc {
218         DirContextStringPair res = getTargetContext(name);
219         return res.getDirContext().search(res.getString(),
220                          matchingAttributes);
221     }
222
223     public NamingEnumeration JavaDoc search(Name JavaDoc name,
224                     String JavaDoc filter,
225                     SearchControls JavaDoc cons)
226     throws NamingException JavaDoc {
227         DirContextNamePair res = getTargetContext(name);
228         return res.getDirContext().search(res.getName(), filter, cons);
229     }
230
231     public NamingEnumeration JavaDoc search(String JavaDoc name,
232                     String JavaDoc filter,
233                     SearchControls JavaDoc cons)
234     throws NamingException JavaDoc {
235         DirContextStringPair res = getTargetContext(name);
236         return res.getDirContext().search(res.getString(), filter, cons);
237     }
238
239     public NamingEnumeration JavaDoc search(Name JavaDoc name,
240                     String JavaDoc filterExpr,
241                     Object JavaDoc[] args,
242                     SearchControls JavaDoc cons)
243     throws NamingException JavaDoc {
244         DirContextNamePair res = getTargetContext(name);
245         return res.getDirContext().search(res.getName(), filterExpr, args,
246                          cons);
247     }
248
249     public NamingEnumeration JavaDoc search(String JavaDoc name,
250                     String JavaDoc filterExpr,
251                     Object JavaDoc[] args,
252                     SearchControls JavaDoc cons)
253     throws NamingException JavaDoc {
254         DirContextStringPair res = getTargetContext(name);
255         return res.getDirContext().search(res.getString(), filterExpr, args,
256                          cons);
257     }
258
259     public DirContext JavaDoc getSchema(String JavaDoc name) throws NamingException JavaDoc {
260     DirContextStringPair res = getTargetContext(name);
261     return res.getDirContext().getSchema(res.getString());
262     }
263
264     public DirContext JavaDoc getSchema(Name JavaDoc name) throws NamingException JavaDoc {
265     DirContextNamePair res = getTargetContext(name);
266     return res.getDirContext().getSchema(res.getName());
267     }
268
269     public DirContext JavaDoc getSchemaClassDefinition(String JavaDoc name)
270         throws NamingException JavaDoc {
271     DirContextStringPair res = getTargetContext(name);
272     return res.getDirContext().getSchemaClassDefinition(res.getString());
273     }
274
275     public DirContext JavaDoc getSchemaClassDefinition(Name JavaDoc name)
276         throws NamingException JavaDoc {
277     DirContextNamePair res = getTargetContext(name);
278     return res.getDirContext().getSchemaClassDefinition(res.getName());
279     }
280 }
281
282 class DirContextNamePair {
283     DirContext JavaDoc ctx;
284     Name JavaDoc name;
285
286     DirContextNamePair(DirContext JavaDoc ctx, Name JavaDoc name) {
287         this.ctx = ctx;
288         this.name = name;
289     }
290
291     DirContext JavaDoc getDirContext() {
292         return ctx;
293     }
294
295     Name JavaDoc getName() {
296         return name;
297     }
298 }
299
300 class DirContextStringPair {
301     DirContext JavaDoc ctx;
302     String JavaDoc str;
303
304     DirContextStringPair(DirContext JavaDoc ctx, String JavaDoc str) {
305         this.ctx = ctx;
306         this.str = str;
307     }
308
309     DirContext JavaDoc getDirContext() {
310         return ctx;
311     }
312
313     String JavaDoc getString() {
314         return str;
315     }
316 }
317
Popular Tags