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