// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(ItemResourceConstants.JCR_DEFINITION);
nameSet.add(DavPropertyName.RESOURCETYPE);
DavMethodBase method = null;
try {
String uri = getItemUri(itemId, sessionInfo);
method = new PropFindMethod(uri, nameSet, DEPTH_0);
getClient(sessionInfo).executeMethod(method);
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;
if (propertySet.contains(ItemResourceConstants.JCR_DEFINITION)) {
DavProperty prop = propertySet.get(ItemResourceConstants.JCR_DEFINITION);
Object value = prop.getValue();
if (value != null && value instanceof Element) {
Element idfElem = (Element) value;
if (itemId.denotesNode()) {
definition = new QNodeDefinitionImpl(null, idfElem, resolver);
} else {
definition = new QPropertyDefinitionImpl(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();
}
}
}