X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api%2Fsrc%2Forg%2Fargeo%2Fapi%2Fgcr%2FContent.java;fp=org.argeo.api%2Fsrc%2Forg%2Fargeo%2Fapi%2Fgcr%2FContent.java;h=fa4d5071330d87f08b3eca2c984a9ee0e229c3b4;hb=865fc51900459b888938cc0d6943673ee6f20d09;hp=e35f42f27ab7519d1122790b009ac3b65121d6ff;hpb=212a43ed44ffc186b69e838d65a1421fd5e1f3a5;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api/src/org/argeo/api/gcr/Content.java b/org.argeo.api/src/org/argeo/api/gcr/Content.java index e35f42f27..fa4d50713 100644 --- a/org.argeo.api/src/org/argeo/api/gcr/Content.java +++ b/org.argeo.api/src/org/argeo/api/gcr/Content.java @@ -1,6 +1,8 @@ package org.argeo.api.gcr; +import java.util.List; import java.util.Map; +import java.util.Optional; import javax.xml.XMLConstants; import javax.xml.namespace.QName; @@ -20,7 +22,7 @@ public interface Content extends Iterable, Map { * ATTRIBUTES OPERATIONS */ - A get(QName key, Class clss) throws IllegalArgumentException; + Optional get(QName key, Class clss); default Object get(String key) { if (key.indexOf(':') >= 0) @@ -40,6 +42,29 @@ public interface Content extends Iterable, Map { return remove(new QName(XMLConstants.NULL_NS_URI, key, XMLConstants.DEFAULT_NS_PREFIX)); } + Class getType(QName key); + + boolean isMultiple(QName key); + + Optional> getMultiple(QName key, Class clss); + + default List getMultiple(QName key) { + Class type; + try { + type = (Class) getType(key); + } catch (ClassCastException e) { + throw new IllegalArgumentException("Requested type is not the default type"); + } + Optional> res = getMultiple(key, type); + 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 */