Introduce open closeable method
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 26 Dec 2021 06:25:33 +0000 (07:25 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 26 Dec 2021 06:25:33 +0000 (07:25 +0100)
org.argeo.api/src/org/argeo/api/gcr/Content.java

index b032aa7b888020dce1779b34d0434ee36613fd28..b2fc3c9063a37f156135f5efb078e7a7eb18a850 100644 (file)
@@ -11,15 +11,19 @@ public interface Content extends Iterable<Content>, Map<String, Object> {
 
 //     Iterable<String> keys();
 
-       <A> A get(String key, Class<A> clss);
+       <A> A get(String key, Class<A> clss) throws IllegalArgumentException;
 
 //     ContentSession getSession();
 
        /*
         * 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());
        }
 
        /*