Introduce CRUD to GCR
[lgpl/argeo-commons.git] / org.argeo.api / src / org / argeo / api / gcr / Content.java
index c5cee9f0e6676495acd7f791a98204bec9f6c8d8..9ce6ea4f6b3f70f4add3ac5895c5e603523622de 100644 (file)
@@ -2,21 +2,39 @@ package org.argeo.api.gcr;
 
 import java.util.Map;
 
+/**
+ * A semi-structured content, with attributes, within a hierarchical structure.
+ */
 public interface Content extends Iterable<Content>, Map<String, Object> {
 
        String getName();
 
-//     Iterable<String> keys();
+       String getPath();
 
-       <A> A get(String key, Class<A> clss);
+       Content getParent();
 
-       ContentSession getSession();
+       /*
+        * ATTRIBUTES OPERATIONS
+        */
+
+       <A> A get(String key, Class<A> clss) throws IllegalArgumentException;
+
+       /*
+        * CONTENT OPERATIONS
+        */
+       Content add(String name, ContentName... classes);
+
+       void remove();
 
        /*
         * DEFAULT METHODS
         */
-       default <A> A adapt(Class<A> clss) {
-               return null;
+       default <A> A adapt(Class<A> clss) throws IllegalArgumentException {
+               throw new IllegalArgumentException("Cannot adapt content " + this + " to " + clss.getName());
+       }
+
+       default <C extends AutoCloseable> C open(Class<C> clss) throws Exception, IllegalArgumentException {
+               throw new IllegalArgumentException("Cannot open content " + this + " as " + clss.getName());
        }
 
        /*
@@ -26,12 +44,12 @@ public interface Content extends Iterable<Content>, Map<String, Object> {
                return get(key, String.class);
        }
 
-       default String attr(Enum<?> key) {
-               return attr(key.name());
+       default String attr(Object key) {
+               return key != null ? attr(key.toString()) : attr(null);
        }
 
-       default <A> A get(Enum<?> key, Class<A> clss) {
-               return get(key.name(), clss);
+       default <A> A get(Object key, Class<A> clss) {
+               return key != null ? get(key.toString(), clss) : get(null, clss);
        }
 
        /*