try {
driver.getLDAPConnection().createEntry(dn, attributes);
} catch (OperationNotSupportedException e) {
// Unwilling to perform.
if (e.getMessage() == null) {
throw new OperationRejectedException(OperationType.CREATE, d
.getUserFriendlyName());
} else {
Message m = Message.raw("%s", e.getMessage());
throw new OperationRejectedException(OperationType.CREATE, d
.getUserFriendlyName(), m);
}
} catch (NamingException e) {
driver.adaptNamingException(e);
}
}
}
// Now add the entry representing this new managed object.
LdapName dn = LDAPNameBuilder.create(path, driver.getLDAPProfile());
Attributes attributes = new BasicAttributes(true);
// Create the object class attribute.
Attribute oc = new BasicAttribute("objectclass");
ManagedObjectDefinition<?, ?> definition = getManagedObjectDefinition();
for (String objectClass : driver.getLDAPProfile().getObjectClasses(
definition)) {
oc.add(objectClass);
}
attributes.put(oc);
// Create the naming attribute if there is not naming property.
PropertyDefinition<?> npd = getNamingPropertyDefinition();
if (npd == null) {
Rdn rdn = dn.getRdn(dn.size() - 1);
attributes.put(rdn.getType(), rdn.getValue().toString());
}
// Create the remaining attributes.
for (PropertyDefinition<?> pd : definition.getAllPropertyDefinitions()) {
String attrID = driver.getLDAPProfile().getAttributeName(definition, pd);
Attribute attribute = new BasicAttribute(attrID);
encodeProperty(attribute, pd);
if (attribute.size() != 0) {
attributes.put(attribute);
}
}
try {
// Create the entry.
driver.getLDAPConnection().createEntry(dn, attributes);
} catch (NameAlreadyBoundException e) {
throw new ManagedObjectAlreadyExistsException();
} catch (OperationNotSupportedException e) {
// Unwilling to perform.
if (e.getMessage() == null) {
throw new OperationRejectedException(OperationType.CREATE, d
.getUserFriendlyName());
} else {
Message m = Message.raw("%s", e.getMessage());
throw new OperationRejectedException(OperationType.CREATE, d
.getUserFriendlyName(), m);
}
} catch (NamingException e) {
driver.adaptNamingException(e);
}