ManagedObject<? extends C> getManagedObject(
ManagedObjectPath<C, S> path) throws DefinitionDecodingException,
ManagedObjectDecodingException, ManagedObjectNotFoundException,
AuthorizationException, CommunicationException {
if (!managedObjectExists(path)) {
throw new ManagedObjectNotFoundException();
}
try {
// Read the entry associated with the managed object.
LdapName dn = LDAPNameBuilder.create(path, profile);
AbstractManagedObjectDefinition<C, S> d = path
.getManagedObjectDefinition();
ManagedObjectDefinition<? extends C, ? extends S> mod =
getEntryDefinition(d, dn);
ArrayList<String> attrIds = new ArrayList<String>();
for (PropertyDefinition<?> pd : mod.getAllPropertyDefinitions()) {
String attrId = profile.getAttributeName(mod, pd);
attrIds.add(attrId);
}
Attributes attributes = connection.readEntry(dn, attrIds);
// Build the managed object's properties.
List<PropertyException> exceptions = new LinkedList<PropertyException>();
PropertySet newProperties = new PropertySet();
for (PropertyDefinition<?> pd : mod.getAllPropertyDefinitions()) {
String attrID = profile.getAttributeName(mod, pd);
Attribute attribute = attributes.get(attrID);
try {
decodeProperty(newProperties, path, pd, attribute);
} catch (PropertyException e) {
exceptions.add(e);
}
}
// If there were no decoding problems then return the object,
// otherwise throw an operations exception.
ManagedObject<? extends C> mo = createExistingManagedObject(mod, path,
newProperties);
if (exceptions.isEmpty()) {
return mo;
} else {
throw new ManagedObjectDecodingException(mo, exceptions);
}
} catch (NameNotFoundException e) {
throw new ManagedObjectNotFoundException();
} catch (NoPermissionException e) {
throw new AuthorizationException(e);
} catch (NamingException e) {
throw new CommunicationException(e);
}