You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2007/08/31 17:33:17 UTC

svn commit: r571494 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: NodeImpl.java SessionImpl.java

Author: stefan
Date: Fri Aug 31 08:33:16 2007
New Revision: 571494

URL: http://svn.apache.org/viewvc?rev=571494&view=rev
Log:
JCR-1104: JSR 283 support

work in (slow) progress...

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=571494&r1=571493&r2=571494&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Fri Aug 31 08:33:16 2007
@@ -4261,4 +4261,20 @@
         }
         session.getLockManager().checkLock(this);
     }
+
+    //--------------------------------------------------< new JSR 283 methods >
+    /**
+     * Returns the identifier of this node. Applies to both referenceable and
+     * non-referenceable nodes.
+     * <p/>
+     * A <code>RepositoryException</code> is thrown if an error occurs.
+     *
+     * @return the identifier of this node
+     * @throws RepositoryException If an error occurs.
+     * @since JCR 2.0
+     */
+    public String getIdentifier() throws RepositoryException {
+        return ((NodeId) id).toString();
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=571494&r1=571493&r2=571494&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java Fri Aug 31 08:33:16 2007
@@ -50,6 +50,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
+import javax.jcr.Property;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -1424,6 +1425,121 @@
      */
     public LockManager getLockManager() throws RepositoryException {
         return wsp.getLockManager();
+    }
+
+    //--------------------------------------------------< new JSR 283 methods >
+    /**
+     * Returns the node specified by the given identifier. Applies to both
+     * referenceable and non-referenceable nodes.
+     * <p/>
+     * An <code>ItemNotFoundException</code> is thrown if no node with the
+     * specified identifier exists. This exception is also thrown if this
+     * <code>Session<code> does not have read access to the node with the
+     * specified identifier.
+     * <p/>
+     * A <code>RepositoryException</code> is thrown if another error occurs.
+     *
+     * @param id An identifier.
+     * @return A <code>Node</code>.
+     * @throws ItemNotFoundException if the specified identifier is not found.
+     * @throws RepositoryException if another error occurs.
+     * @since JCR 2.0
+     */
+    public Node getNodeByIdentifier(String id)
+            throws ItemNotFoundException, RepositoryException {
+        NodeId nodeId;
+        try {
+            nodeId = NodeId.valueOf(id);
+        } catch (IllegalArgumentException iae) {
+            throw new RepositoryException("invalid identifier: " + id);
+        }
+        return getNodeById(nodeId);
+    }
+
+    /**
+     * Returns the node at the specified absolute path in the workspace.
+     * If no node exists, then a <code>PathNotFoundException</code> is thrown.
+     *
+     * @param absPath An absolute path.
+     * @return the specified <code>Node</code>.
+     * @throws PathNotFoundException If no node exists.
+     * @throws RepositoryException If another error occurs.
+     * @since JCR 2.0
+     */
+    public Node getNode(String absPath)
+            throws PathNotFoundException, RepositoryException {
+        Item item  = getItem(absPath);
+        if (!item.isNode()) {
+            throw new PathNotFoundException(absPath);
+        }
+        return (Node) item;
+    }
+
+    /**
+     * Returns the property at the specified absolute path in the workspace.
+     * If no property exists, then a <code>PathNotFoundException</code> is thrown.
+     *
+     * @param absPath An absolute path.
+     * @return the specified <code>Property</code>.
+     * @throws PathNotFoundException If no property exists.
+     * @throws RepositoryException if another error occurs.
+     * @since JCR 2.0
+     */
+    public Property getProperty(String absPath)
+            throws PathNotFoundException, RepositoryException {
+        Item item  = getItem(absPath);
+        if (item.isNode()) {
+            throw new PathNotFoundException(absPath);
+        }
+        return (Property) item;
+    }
+
+    /**
+     * Returns <code>true</code> if a node exists at <code>absPath</code>
+     * and this <code>Session</code> has read access to it; otherwise returns
+     * <code>false</code>.
+     * <p/>
+     * Throws a <code>RepositoryException</code> if <code>absPath</code>
+     * is not a well-formed absolute path.
+     *
+     * @param absPath An absolute path.
+     * @return a <code>boolean</code>
+     * @throws RepositoryException if <code>absPath</code> is not a well-formed
+     *         absolute path.
+     * @since JCR 2.0
+     */
+    public boolean nodeExists(String absPath) throws RepositoryException {
+        // TODO: optimize...
+        try {
+            getNode(absPath);
+            return true;
+        } catch (PathNotFoundException pnfe) {
+            return false;
+        }
+    }
+
+    /**
+     * Returns <code>true</code> if a property exists at <code>absPath</code>
+     * and this <code>Session</code> has read access to it; otherwise returns
+     * <code>false</code>.
+     * <p/>
+     * Throws a <code>RepositoryException</code> if <code>absPath</code>
+     * is not a well-formed absolute path.
+     *
+     * @param absPath An absolute path.
+     * @return a <code>boolean</code>
+     * @throws RepositoryException if <code>absPath</code> is not a well-formed
+     *         absolute path.
+     * @since JCR 2.0
+     */
+    boolean propertyExists(String absPath) throws RepositoryException {
+        // TODO: optimize...
+        try {
+            getProperty(absPath);
+            return true;
+        } catch (PathNotFoundException pnfe) {
+            return false;
+        }
     }
 
     //-------------------------------------------------------------< Dumpable >