jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r774702 - in /jackrabbit/trunk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/sp...
Date Thu, 14 May 2009 09:20:54 GMT
Author: angela
Date: Thu May 14 09:20:52 2009
New Revision: 774702

URL: http://svn.apache.org/viewvc?rev=774702&view=rev
Log:
JCR-2111: JSR 283 Node Identifier

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
Thu May 14 09:20:52 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());
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Thu May 14 09:20:52 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 + "'.");
             }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
Thu May 14 09:20:52 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 <code>PathFactory</code>.
-     */
-    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 <code>PathFactory</code>.
+     */
+    protected abstract PathFactory getPathFactory();
+
     //------------------------------------------------------< Inner classes >---
 
     private static abstract class ItemIdImpl implements ItemId, Serializable {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/IdFactoryLogger.java
Thu May 14 09:20:52 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});
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/IdFactory.java
Thu May 14 09:20:52 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 <code>nodeId</code>.
+     *
+     * @return a JCR node identifier string.
+     * @see #fromJcrIdentifier(String)
+     */
+    public String toJcrIdentifier(NodeId nodeId);
+
+    /**
+     * Create a new <code>NodeId</code> from the given JCR string representation.
+     *
+     * @param jcrIdentifier
+     * @return a new <code>NodeId</code>.
+     * @see #toJcrIdentifier(NodeId)
+     */
+    public NodeId fromJcrIdentifier(String jcrIdentifier);
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
Thu May 14 09:20:52 2009
@@ -29,7 +29,6 @@
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Property;
 
 /**
@@ -61,39 +60,8 @@
             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 {
-            return createNodeId(uniqueId);
-        }
+        String uniqueId = node.getIdentifier();
+        return createNodeId(uniqueId);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=774702&r1=774701&r2=774702&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Thu May 14 09:20:52 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();
         }



Mime
View raw message