X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2FContent.java;h=0fdc14fe30e9f0146afbc8f8dde42187086d0200;hb=43dc6cd030cab486347ffef4d339406bee7a8dec;hp=edcfaea10de9199dd9b6ffb128216766578c60c2;hpb=7d2a002f5dcfe8a8c7b29803b70d4b1aff265ed1;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/Content.java b/org.argeo.api.acr/src/org/argeo/api/acr/Content.java index edcfaea10..0fdc14fe3 100644 --- a/org.argeo.api.acr/src/org/argeo/api/acr/Content.java +++ b/org.argeo.api.acr/src/org/argeo/api/acr/Content.java @@ -1,8 +1,11 @@ package org.argeo.api.acr; +import java.io.Closeable; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.CompletableFuture; import javax.xml.XMLConstants; import javax.xml.namespace.QName; @@ -48,6 +51,7 @@ public interface Content extends Iterable, Map { Optional> getMultiple(QName key, Class clss); + @SuppressWarnings("unchecked") default List getMultiple(QName key) { Class type; try { @@ -68,6 +72,13 @@ public interface Content extends Iterable, Map { /* * CONTENT OPERATIONS */ +// default CompletionStage edit(Consumer work) { +// return CompletableFuture.supplyAsync(() -> { +// work.accept(this); +// return this; +// }).minimalCompletionStage(); +// } + Content add(QName name, QName... classes); default Content add(String name, QName... classes) { @@ -78,23 +89,64 @@ public interface Content extends Iterable, Map { void remove(); + /* + * TYPING + */ + List getContentClasses(); + + /** AND */ + default boolean isContentClass(QName... contentClass) { + List contentClasses = getContentClasses(); + for (QName cClass : contentClass) { + if (!contentClasses.contains(cClass)) + return false; + } + return true; + } + + /** OR */ + default boolean hasContentClass(QName... contentClass) { + List contentClasses = getContentClasses(); + for (QName cClass : contentClass) { + if (contentClasses.contains(cClass)) + return true; + } + return false; + } + /* * DEFAULT METHODS */ - default A adapt(Class clss) throws IllegalArgumentException { - throw new IllegalArgumentException("Cannot adapt content " + this + " to " + clss.getName()); + default A adapt(Class clss) { + throw new UnsupportedOperationException("Cannot adapt content " + this + " to " + clss.getName()); } - default C open(Class clss) throws Exception, IllegalArgumentException { - throw new IllegalArgumentException("Cannot open content " + this + " as " + clss.getName()); + default C open(Class clss) throws IOException { + throw new UnsupportedOperationException("Cannot open content " + this + " as " + clss.getName()); + } + + default CompletableFuture write(Class clss) { + throw new UnsupportedOperationException("Cannot write content " + this + " as " + clss.getName()); } /* * CONVENIENCE METHODS */ -// default String attr(String key) { -// return get(key, String.class); -// } + default String attr(String key) { + Object obj = get(key); + if (obj == null) + return null; + return obj.toString(); + + } + + default String attr(QName key) { + Object obj = get(key); + if (obj == null) + return null; + return obj.toString(); + + } // // default String attr(Object key) { // return key != null ? attr(key.toString()) : attr(null);