MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
if (responses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve the item definition for " + saveGetIdString(itemId, sessionInfo));
}
if (responses.length > 1) {
throw new RepositoryException("Internal error: ambigous item definition found '" + saveGetIdString(itemId, sessionInfo) + "'.");
}
DavPropertySet propertySet = responses[0].getProperties(DavServletResponse.SC_OK);
// check if definition matches the type of the id
DavProperty<?> rType = propertySet.get(DavPropertyName.RESOURCETYPE);
if (rType.getValue() == null && itemId.denotesNode()) {
throw new RepositoryException("Internal error: requested node definition and got property definition.");
}
NamePathResolver resolver = getNamePathResolver(sessionInfo);
// build the definition
QItemDefinition definition = null;
DavProperty<?> prop = propertySet.get(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
if (prop != null) {
Object value = prop.getValue();
if (value != null && value instanceof Element) {
Element idfElem = (Element) value;
if (itemId.denotesNode()) {
definition = DefinitionUtil.createQNodeDefinition(null, idfElem, resolver);
} else {
definition = DefinitionUtil.createQPropertyDefinition(null, idfElem, resolver, getQValueFactory());
}
}
}
if (definition == null) {
throw new RepositoryException("Unable to retrieve definition for item with id '" + saveGetIdString(itemId, resolver) + "'.");
}
return definition;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (method != null) {
method.releaseConnection();