Java Reference
In-Depth Information
L ISTING 11.2
11
Continued
public void modify(String dn, HashMap attributes, int modOp)
throws NamingException {
// perform the modification on all of the given attributes
// based on the modOp that was passed in
DirContext ctx = getInitialContext(getEnvironment());
ctx.modifyAttributes(dn, modOp, parseAttributes(attributes));
}
/**
* Adds a new object to the LDAP server with the give attributes.
*/
public void add(String dn, HashMap attributes, String[] objectClass)
throws NamingException {
// parse the attributes that were passed in
Attributes atts = parseAttributes(attributes);
// add objectClass attribute to the list of attributes
Attribute oc = new BasicAttribute(“objectClass”);
for (int i = 0; i < objectClass.length; i++) {
oc.add(objectClass[i]);
}
atts.put(oc);
// perform the addition to the LDAP server
DirContext ctx = getInitialContext(getEnvironment());
ctx.bind(dn, null, atts);
}
/**
* Remove the specified object from the LDAP server.
*/
public void remove(String dn) throws NamingException {
// perform the deletion from the LDAP server based on the objects DN
DirContext ctx = getInitialContext(getEnvironment());
ctx.destroySubcontext(dn);
}
public Attributes parseAttributes(HashMap attributes) {
if (attributes == null) {
 
Search WWH ::




Custom Search