Improve ACR, introduce migration from JCR.
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / Content.java
index 0fdc14fe30e9f0146afbc8f8dde42187086d0200..4aac92de75b2317f78b83bea56329535c630ff81 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.api.acr;
 
 import java.io.Closeable;
 import java.io.IOException;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -129,6 +130,34 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
                throw new UnsupportedOperationException("Cannot write content " + this + " as " + clss.getName());
        }
 
+       /*
+        * CHILDREN
+        */
+
+       default boolean hasChild(QName name) {
+               for (Content child : this) {
+                       if (child.getName().equals(name))
+                               return true;
+               }
+               return false;
+       }
+
+       default Content anyOrAddChild(QName name, QName... classes) {
+               Content child = anyChild(name);
+               if (child != null)
+                       return child;
+               return this.add(name, classes);
+       }
+
+       /** Any child with this name, or null if there is none */
+       default Content anyChild(QName name) {
+               for (Content child : this) {
+                       if (child.getName().equals(name))
+                               return child;
+               }
+               return null;
+       }
+
        /*
         * CONVENIENCE METHODS
         */