]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api/src/org/argeo/api/gcr/Content.java
Introduce BytesUtils
[lgpl/argeo-commons.git] / org.argeo.api / src / org / argeo / api / gcr / Content.java
1 package org.argeo.api.gcr;
2
3 import java.util.Map;
4
5 /**
6 * A semi-structured content, with attributes, within a hierarchical structure.
7 */
8 public interface Content extends Iterable<Content>, Map<String, Object> {
9
10 String getName();
11
12 // Iterable<String> keys();
13
14 <A> A get(String key, Class<A> clss) throws IllegalArgumentException;
15
16 // ContentSession getSession();
17
18 /*
19 * DEFAULT METHODS
20 */
21 default <A> A adapt(Class<A> clss) throws IllegalArgumentException {
22 throw new IllegalArgumentException("Cannot adapt content " + this + " to " + clss.getName());
23 }
24
25 default <C extends AutoCloseable> C open(Class<C> clss) throws Exception, IllegalArgumentException {
26 throw new IllegalArgumentException("Cannot open content " + this + " as " + clss.getName());
27 }
28
29 /*
30 * CONVENIENCE METHODS
31 */
32 default String attr(String key) {
33 return get(key, String.class);
34 }
35
36 default String attr(Object key) {
37 return key != null ? attr(key.toString()) : attr(null);
38 }
39
40 default <A> A get(Object key, Class<A> clss) {
41 return key != null ? get(key.toString(), clss) : get(null, clss);
42 }
43
44 /*
45 * EXPERIMENTAL UNSUPPORTED
46 */
47 default boolean hasText() {
48 return false;
49 }
50
51 default String getText() {
52 throw new UnsupportedOperationException();
53 }
54
55 }