1 package net.simya.ldap.beans; 2 3 import javax.naming.*; 4 import javax.naming.directory.*; 5 import java.util.Enumeration ; 6 import java.util.Hashtable ; 7 8 13 public class LdapAddEntryBean { 14 15 private DirContext ctx = null; 16 17 private Attributes attrList = new BasicAttributes(true); 19 private Hashtable attrTable = new Hashtable (); 20 21 private String DN; 22 23 24 public void setContext (DirContext ctx) 25 { 26 this.ctx = ctx; 27 } 28 29 30 public void setDN ( String dn) 31 { 32 this.DN = dn ; 33 } 34 35 36 public void setAddAttribute ( String name, Object value) 37 { 38 Attribute tmp = (Attribute) attrTable.get(name); 40 if (tmp == null) 42 { 43 attrTable.put ( name, new BasicAttribute(name)); 44 45 tmp = (Attribute) attrTable.get(name); 46 tmp.add ( value); 47 48 attrTable.put (name, tmp); 49 } 50 else 52 { 53 tmp = (Attribute) attrTable.get(name); 54 tmp.add ( value); 55 } 56 } 57 58 public void addEntry () 59 throws NamingException 60 { 61 Enumeration en= attrTable.keys(); 63 while (en.hasMoreElements()) 65 { 66 String name = (String ) en.nextElement(); 67 attrList.put((Attribute) attrTable.get(name)); 69 } 70 71 ctx.createSubcontext(DN, attrList); 73 } 74 75 } 77 | Popular Tags |