1 2 package net.simya.ldap.beans; 3 4 import javax.naming.*; 5 import javax.naming.directory.*; 6 import java.util.*; 7 8 14 public class LdapModifyEntryBean { 15 16 private DirContext ctx = null; 17 18 private ModificationItem[] item = null; 19 20 private Attributes attrList = new BasicAttributes(true); 22 private Hashtable attrTable = new Hashtable(); 23 24 private Vector vector = new Vector(); 25 26 private String DN; 27 28 29 public void setContext (DirContext ctx) 30 { 31 this.ctx = ctx; 32 } 33 34 35 public void setDN ( String dn) 36 { 37 this.DN = dn ; 38 } 39 40 41 public void setModifyAttribute ( String name, Object value, int operationType) 42 { 43 53 if (operationType != 0 ) 55 { 56 Attribute attr = new BasicAttribute(name,value); 57 vector.add(new ModificationItem(operationType, attr)); 58 } 59 else 60 { 63 Enumeration en= vector.elements(); 64 65 for (int i=0; en.hasMoreElements(); i++) 66 { 67 68 ModificationItem moditem = (ModificationItem) en.nextElement(); 69 Attribute tmpattr = (Attribute) moditem.getAttribute(); 70 if ((tmpattr.getID()).equals(name)); 71 tmpattr.add(value); 72 73 } 74 } 75 77 78 } 79 80 81 public void modifyEntry () 82 throws NamingException 83 { 84 Enumeration en= vector.elements(); 85 86 item = new ModificationItem[vector.size()]; 87 88 for (int i=0; en.hasMoreElements(); i++) 89 { 90 91 item[i] = (ModificationItem) en.nextElement(); 92 } 93 94 ctx.modifyAttributes(DN, item); 95 96 } 97 98 } 100 | Popular Tags |