Index: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java =================================================================== --- jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java (revision 774406) +++ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java Wed May 13 19:03:41 CEST 2009 @@ -74,4 +74,18 @@ }}, "createNodeId(String)", new Object[]{uniqueID}); } + public String toJcrIdentifier(final NodeId nodeId) { + return (String) execute(new SafeCallable() { + public Object call() { + return idFactory.toJcrIdentifier(nodeId); + }}, "toJcrIdentifier(String)", new Object[]{nodeId}); -} + } + + public NodeId fromJcrIdentifier(final String jcrIdentifier) { + return (NodeId) execute(new SafeCallable() { + public Object call() { + return idFactory.fromJcrIdentifier(jcrIdentifier); + }}, "fromJcrIdentifier(String)", new Object[]{jcrIdentifier}); + } + +} Index: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java =================================================================== --- jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java (revision 774408) +++ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java Wed May 13 18:28:54 CEST 2009 @@ -502,8 +502,7 @@ * @see Session#getNodeByIdentifier(String) */ public Node getNodeByIdentifier(String id) throws RepositoryException { - // TODO: implementation missing - throw new UnsupportedRepositoryOperationException("JCR-1104"); + return getNodeById(getIdFactory().fromJcrIdentifier(id)); } /** @@ -985,7 +984,7 @@ */ public Path getPath(String identifier) throws MalformedPathException { try { - NodeId id = getIdFactory().createNodeId(identifier); + NodeId id = getIdFactory().fromJcrIdentifier(identifier); return getHierarchyManager().getNodeEntry(id).getPath(); } catch (RepositoryException e) { throw new MalformedPathException("Invalid identifier '" + identifier + "'."); @@ -997,7 +996,7 @@ */ public void checkFormat(String identifier) throws MalformedPathException { try { - NodeId id = getIdFactory().createNodeId(identifier); + NodeId id = getIdFactory().fromJcrIdentifier(identifier); } catch (Exception e) { throw new MalformedPathException("Invalid identifier '" + identifier + "'."); } Index: jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java =================================================================== --- jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java (revision 774406) +++ jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java Thu May 14 08:57:43 CEST 2009 @@ -1490,7 +1490,7 @@ Session session = sessionInfo.getSession(); StringBuffer path = new StringBuffer(); if (id.getUniqueID() != null) { - path.append(session.getNodeByUUID(id.getUniqueID()).getPath()); + path.append(session.getNodeByIdentifier(id.getUniqueID()).getPath()); } else { path.append("/"); } @@ -1522,6 +1522,10 @@ // if the parent of an batch operation is not available, this indicates // that it has been destroyed by another session. throw new InvalidItemStateException(e); + } catch (ItemNotFoundException e) { + // if the parent of an batch operation is not available, this indicates + // that it has been destroyed by another session. + throw new InvalidItemStateException(e); } } @@ -1529,7 +1533,7 @@ Session session = sessionInfo.getSession(); Node n; if (id.getUniqueID() != null) { - n = session.getNodeByUUID(id.getUniqueID()); + n = session.getNodeByIdentifier(id.getUniqueID()); } else { n = session.getRootNode(); } @@ -1554,7 +1558,7 @@ Session session = sessionInfo.getSession(); Node n; if (id.getUniqueID() != null) { - n = session.getNodeByUUID(id.getUniqueID()); + n = session.getNodeByIdentifier(id.getUniqueID()); } else { n = session.getRootNode(); } Index: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java =================================================================== --- jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java (revision 774406) +++ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Wed May 13 18:42:40 CEST 2009 @@ -562,8 +562,7 @@ */ public String getIdentifier() throws RepositoryException { checkStatus(); - // TODO: check again and add SPI method to create Node-Identifier from String - return getNodeEntry().getId().toString(); + return session.getIdFactory().toJcrIdentifier(getNodeEntry().getId()); } /** Index: jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java =================================================================== --- jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java (revision 774406) +++ jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java Thu May 14 08:58:17 CEST 2009 @@ -29,7 +29,6 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; -import javax.jcr.UnsupportedRepositoryOperationException; import javax.jcr.Property; /** @@ -61,40 +60,9 @@ throws RepositoryException { PathBuilder builder = new PathBuilder(); int pathElements = 0; - String uniqueId = null; - while (uniqueId == null) { - try { - uniqueId = node.getUUID(); - } catch (UnsupportedRepositoryOperationException e) { - // not referenceable - pathElements++; - String jcrName = node.getName(); - if (jcrName.equals("")) { - // root node - builder.addRoot(); - break; - } else { - Name name; - try { - name = resolver.getQName(node.getName()); - } catch (NameException ex) { - throw new RepositoryException(ex.getMessage(), ex); - } - if (node.getIndex() == 1) { - builder.addFirst(name); - } else { - builder.addFirst(name, node.getIndex()); - } - } - node = node.getParent(); - } - } - if (pathElements > 0) { - return createNodeId(uniqueId, builder.getPath()); - } else { + String uniqueId = node.getIdentifier(); - return createNodeId(uniqueId); - } + return createNodeId(uniqueId); + } - } /** * Creates a PropertyId for the given property. Index: jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java =================================================================== --- jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java (revision 774406) +++ jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java Thu May 14 10:54:55 CEST 2009 @@ -68,5 +68,22 @@ * @see ItemId ItemId for a description of the uniqueID defined by the SPI * item identifiers. */ - public NodeId createNodeId(String uniqueID); + public NodeId createNodeId(String uniqueID); + + /** + * Returns the JCR string representation of the given nodeId. + * + * @return a JCR node identifier string. + * @see #fromJcrIdentifier(String) + */ + public String toJcrIdentifier(NodeId nodeId); + + /** + * Create a new NodeId from the given JCR string representation. + * + * @param jcrIdentifier + * @return a new NodeId. + * @see #toJcrIdentifier(NodeId) + */ + public NodeId fromJcrIdentifier(String jcrIdentifier); } \ No newline at end of file Index: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java =================================================================== --- jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java (revision 774406) +++ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java Thu May 14 10:55:05 CEST 2009 @@ -23,6 +23,7 @@ import org.apache.jackrabbit.spi.Name; import org.apache.jackrabbit.spi.Path; import org.apache.jackrabbit.spi.PathFactory; +import org.apache.jackrabbit.util.Text; import javax.jcr.RepositoryException; import java.io.Serializable; @@ -32,13 +33,9 @@ */ public abstract class AbstractIdFactory implements IdFactory { - /** - * Subclassed need to define a PathFactory used to create IDs - * - * @return a implementation of PathFactory. - */ - protected abstract PathFactory getPathFactory(); + private static final char DELIMITER = '@'; + //----------------------------------------------------------< IdFactory >--- /** * {@inheritDoc} * @see IdFactory#createNodeId(NodeId, Path) @@ -79,6 +76,52 @@ } } + /** + * @see IdFactory#toJcrIdentifier(NodeId) + */ + public String toJcrIdentifier(NodeId nodeId) { + // TODO improve + String uniqueId = nodeId.getUniqueID(); + Path path = nodeId.getPath(); + if (path == null) { + return uniqueId; + } else if (uniqueId == null) { + return DELIMITER + path.toString(); + } else { + StringBuffer bf = new StringBuffer(); + bf.append(Text.escape(uniqueId, DELIMITER)); + bf.append(DELIMITER); + bf.append(path.toString()); + return bf.toString(); + } + } + + /** + * @see IdFactory#fromJcrIdentifier(String) + */ + public NodeId fromJcrIdentifier(String jcrIdentifier) { + // TODO improve + int pos = jcrIdentifier.indexOf(DELIMITER); + switch (pos) { + case -1: + return createNodeId(jcrIdentifier); + case 0: + return createNodeId((String) null, getPathFactory().create(jcrIdentifier.substring(1))); + default: + String uniqueId = Text.unescape(jcrIdentifier.substring(0, pos), DELIMITER); + Path path = getPathFactory().create(jcrIdentifier.substring(pos+1)); + return createNodeId(uniqueId, path); + } + } + + //-------------------------------------------------------------------------- + /** + * Subclassed need to define a PathFactory used to create IDs + * + * @return a implementation of PathFactory. + */ + protected abstract PathFactory getPathFactory(); + //------------------------------------------------------< Inner classes >--- private static abstract class ItemIdImpl implements ItemId, Serializable {