]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.api.acr/src/org/argeo/api/acr/Content.java
Improve ACR
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / Content.java
index d48f583fd7c84e4fc33c5f97f8493664c609f3b6..df5c149e6fc1fc696187d197766ad5f9cf0c2c52 100644 (file)
@@ -16,6 +16,8 @@ import javax.xml.namespace.QName;
  * A semi-structured content, with attributes, within a hierarchical structure.
  */
 public interface Content extends Iterable<Content>, Map<QName, Object> {
+       /** The base of a repository path. */
+       String ROOT_PATH = "/";
 
        QName getName();
 
@@ -82,25 +84,11 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
                }
                List<A> res = getMultiple(key, type);
                return res;
-//             if (res == null)
-//                     return null;
-//             else {
-//                     if (res.isEmpty())
-//                             throw new IllegalStateException("Metadata " + key + " is not availabel as list of type " + type);
-//                     return res.get();
-//             }
        }
 
        /*
         * CONTENT OPERATIONS
         */
-//     default CompletionStage<Content> edit(Consumer<Content> work) {
-//             return CompletableFuture.supplyAsync(() -> {
-//                     work.accept(this);
-//                     return this;
-//             }).minimalCompletionStage();
-//     }
-
        Content add(QName name, QName... classes);
 
        default Content add(String name, QName... classes) {
@@ -222,6 +210,14 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
                return res;
        }
 
+       default List<Content> children(QNamed name) {
+               return children(name.qName());
+       }
+
+       default Optional<Content> soleChild(QNamed name) {
+               return soleChild(name.qName());
+       }
+
        default Optional<Content> soleChild(QName name) {
                List<Content> res = children(name);
                if (res.isEmpty())
@@ -251,11 +247,7 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
         * @see Object#toString()
         */
        default String attr(QName key) {
-               // TODO check String type?
-               Object obj = get(key);
-               if (obj == null)
-                       return null;
-               return obj.toString();
+               return get(key, String.class).orElse(null);
        }
 
        /**
@@ -282,6 +274,16 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
                return attr(unqualified(key));
        }
 
+       /*
+        * CONTEXT
+        */
+       /**
+        * A content within this repository
+        * 
+        * @param path either an absolute path or a path relative to this content
+        */
+       Optional<Content> getContent(String path);
+
        /*
         * EXPERIMENTAL UNSUPPORTED
         */