public final Item getPrimaryItem() throws RepositoryException {
// Get the primary item name from this node's type ...
NodeType primaryType = getPrimaryNodeType();
String primaryItemNameString = primaryType.getPrimaryItemName();
if (primaryItemNameString == null) {
I18n msg = JcrI18n.noPrimaryItemNameDefinedOnPrimaryType;
throw new ItemNotFoundException(msg.text(primaryType.getName(), getPath(), cache.workspaceName()));
}
try {
Path primaryItemPath = context().getValueFactories().getPathFactory().create(primaryItemNameString);
if (primaryItemPath.size() != 1 || primaryItemPath.isAbsolute()) {
I18n msg = JcrI18n.primaryItemNameForPrimaryTypeIsNotValid;
throw new ItemNotFoundException(msg.text(primaryType.getName(),
primaryItemNameString,
getPath(),
cache.workspaceName()));
}
return cache.findJcrItem(nodeId, location.getPath(), primaryItemPath);
} catch (ValueFormatException error) {
I18n msg = JcrI18n.primaryItemNameForPrimaryTypeIsNotValid;
throw new ItemNotFoundException(msg.text(primaryType.getName(),
primaryItemNameString,
getPath(),
cache.workspaceName()));
} catch (PathNotFoundException error) {
I18n msg = JcrI18n.primaryItemDoesNotExist;
throw new ItemNotFoundException(msg.text(primaryType.getName(),
primaryItemNameString,
getPath(),
cache.workspaceName()));
}
}