jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r890818 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Date Tue, 15 Dec 2009 15:13:36 GMT
Author: jukka
Date: Tue Dec 15 15:13:36 2009
New Revision: 890818

URL: http://svn.apache.org/viewvc?rev=890818&view=rev
Log:
JCR-2439: More utility methods in JcrUtils

Add simple getOrAddNode() methods

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=890818&r1=890817&r2=890818&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Tue Dec 15 15:13:36 2009
@@ -346,6 +346,55 @@
     }
 
     /**
+     * Returns the named child of the given node, creating the child if
+     * it does not already exist. If the child node gets added, then its
+     * type will be determined by the child node definitions associated
+     * with the parent node. The caller is expected to take care of saving
+     * or discarding any transient changes.
+     *
+     * @see Node#getNode(String)
+     * @see Node#addNode(String)
+     * @param parent parent node
+     * @param name name of the child node
+     * @return child node
+     * @throws RepositoryException if the child node can not be
+     *                             accessed or created
+     */
+    public static Node getOrAddNode(Node parent, String name)
+            throws RepositoryException {
+        if (parent.hasNode(name)) {
+            return parent.getNode(name);
+        } else {
+            return parent.addNode(name);
+        }
+    }
+
+    /**
+     * Returns the named child of the given node, creating the child if
+     * it does not already exist. If the child node gets added, then it
+     * is created with the given node type. The caller is expected to take
+     * care of saving or discarding any transient changes.
+     *
+     * @see Node#getNode(String)
+     * @see Node#addNode(String)
+     * @param parent parent node
+     * @param name name of the child node
+     * @param type the node type to use for the child node in case
+     *             it needs to be created, ignored otherwise
+     * @return child node
+     * @throws RepositoryException if the child node can not be
+     *                             accessed or created
+     */
+    public static Node getOrAddNode(Node parent, String name, String type)
+            throws RepositoryException {
+        if (parent.hasNode(name)) {
+            return parent.getNode(name);
+        } else {
+            return parent.addNode(name, type);
+        }
+    }
+
+    /**
      * Returns a string representation of the given item. The returned string
      * is designed to be easily readable while providing maximum amount of
      * information for logging and debugging purposes.



Mime
View raw message