1 16 17 package org.apache.naming.core; 18 19 import java.util.Hashtable; 20 21 import javax.naming.Name; 22 import javax.naming.NameAlreadyBoundException; 23 import javax.naming.NamingEnumeration; 24 import javax.naming.NamingException; 25 import javax.naming.OperationNotSupportedException; 26 import javax.naming.directory.Attribute; 27 import javax.naming.directory.Attributes; 28 import javax.naming.directory.DirContext; 29 import javax.naming.directory.ModificationItem; 30 import javax.naming.directory.SearchControls; 31 32 33 35 38 65 public class BaseDirContext extends BaseContext implements DirContext { 66 67 public BaseDirContext() 68 { 69 super(); 70 } 71 72 public BaseDirContext(Hashtable env) 73 { 74 super(env); 75 } 76 77 78 80 88 public Attributes getAttributes(Name name) 89 throws NamingException 90 { 91 return getAttributes(name, null); 92 } 93 94 95 102 public Attributes getAttributes(String name) 103 throws NamingException 104 { 105 return getAttributes(string2Name(name)); 106 } 107 108 120 public Attributes getAttributes(String name, String[] attrIds) 121 throws NamingException 122 { 123 return getAttributes(string2Name(name), attrIds); 124 } 125 126 public Attributes getAttributes(Name name, String[] attrIds) 127 throws NamingException 128 { 129 if( attrIds==null ) { 130 attrIds= super.getAttributeNames(name); 131 } 132 Attributes res=new ServerAttributes(); 133 if( attrIds==null ) return res; 134 135 for( int i=0; i<attrIds.length; i++ ) { 136 Object val=super.getAttribute(name, attrIds[i]); 137 res.put( attrIds[i], val ); 138 } 139 return res; 140 } 141 142 143 157 public void modifyAttributes(Name name, int mod_op, Attributes attrs) 158 throws NamingException 159 { 160 NamingEnumeration enum=attrs.getAll(); 161 while( enum.hasMoreElements() ) { 162 Attribute att=(Attribute)enum.nextElement(); 163 switch( mod_op ) { 164 case ADD_ATTRIBUTE: 165 case REPLACE_ATTRIBUTE: 166 for( int i=0; i< att.size(); i++ ) { 167 super.setAttribute(name, att.getID(), att.get(i)); 168 } 169 break; 170 case REMOVE_ATTRIBUTE: 171 break; 172 } 173 } 174 } 175 176 public void modifyAttributes(String name, int mod_op, Attributes attrs) 177 throws NamingException 178 { 179 modifyAttributes(string2Name(name), mod_op, attrs); 180 } 181 182 183 197 public void modifyAttributes(Name name, ModificationItem[] mods) 198 throws NamingException 199 { 200 if (mods==null) return; 201 for (int i=0; i<mods.length; i++) { 202 203 switch( mods[i].getModificationOp() ) { 204 case ADD_ATTRIBUTE: 205 case REPLACE_ATTRIBUTE: 206 case REMOVE_ATTRIBUTE: 207 }; 208 } 209 } 210 211 212 public void modifyAttributes(String name, ModificationItem[] mods) 213 throws NamingException 214 { 215 modifyAttributes(string2Name(name), mods); 216 } 217 218 219 234 public void bind(Name name, Object obj, Attributes attrs) 235 throws NamingException 236 { 237 super.bind( name, obj ); 238 239 NamingEnumeration enum=attrs.getAll(); 240 while( enum.hasMoreElements() ) { 241 Attribute att=(Attribute)enum.nextElement(); 242 243 Object val=getAttribute(name, att.getID() ); 244 if( val != null ) { 245 throw new NameAlreadyBoundException(name.toString() + " : " + 246 att.getID()); 247 } 248 249 int size=att.size(); 250 for( int i=0; i<size; i++ ) { 251 setAttribute( name, att.getID(), att.get(i)); 253 } 254 } 255 } 256 257 public void bind( String name, Object obj, Attributes attrs ) 258 throws NamingException 259 { 260 bind(string2Name(name), obj, attrs); 261 } 262 263 264 282 public void rebind(Name name, Object obj, Attributes attrs) 283 throws NamingException 284 { 285 bind(name, obj, attrs, true); 286 } 287 288 public void rebind(String name, Object obj, Attributes attrs) 289 throws NamingException 290 { 291 bind(string2Name(name), obj, attrs, true); 292 } 293 294 295 312 public DirContext createSubcontext(String name, Attributes attrs) 313 throws NamingException 314 { 315 return createSubcontext(string2Name(name), attrs); 316 } 317 318 319 332 public DirContext getSchema(Name name) 333 throws NamingException 334 { 335 return getSchema(name.toString()); 336 } 337 338 339 347 public DirContext getSchema(String name) 348 throws NamingException 349 { 350 throw new OperationNotSupportedException(); 351 } 352 353 354 365 public DirContext getSchemaClassDefinition(Name name) 366 throws NamingException 367 { 368 return getSchemaClassDefinition(name.toString()); 369 } 370 371 372 383 public DirContext getSchemaClassDefinition(String name) 384 throws NamingException 385 { 386 throw new OperationNotSupportedException(); 387 } 388 389 390 407 public NamingEnumeration search(Name name, Attributes matchingAttributes, 408 String[] attributesToReturn) 409 throws NamingException 410 { 411 return search(name.toString(), matchingAttributes, attributesToReturn); 412 } 413 414 415 431 public NamingEnumeration search(String name, Attributes matchingAttributes, 432 String[] attributesToReturn) 433 throws NamingException 434 { 435 throw new OperationNotSupportedException(); 436 } 437 438 439 454 public NamingEnumeration search(Name name, Attributes matchingAttributes) 455 throws NamingException 456 { 457 return search(name.toString(), matchingAttributes); 458 } 459 460 461 474 public NamingEnumeration search(String name, Attributes matchingAttributes) 475 throws NamingException 476 { 477 throw new OperationNotSupportedException(); 478 } 479 480 499 public NamingEnumeration search(Name name, String filter, 500 SearchControls cons) 501 throws NamingException 502 { 503 return search(name.toString(), filter, cons); 504 } 505 506 507 526 public NamingEnumeration search(String name, String filter, 527 SearchControls cons) 528 throws NamingException 529 { 530 throw new OperationNotSupportedException(); 531 } 532 533 534 558 public NamingEnumeration search(Name name, String filterExpr, 559 Object[] filterArgs, SearchControls cons) 560 throws NamingException 561 { 562 return search(name.toString(), filterExpr, filterArgs, cons); 563 } 564 565 566 590 public NamingEnumeration search(String name, String filterExpr, 591 Object[] filterArgs, 592 SearchControls cons) 593 throws NamingException 594 { 595 throw new OperationNotSupportedException(); 596 } 597 598 } 599 600 | Popular Tags |