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();
- <A> A get(String key, Class<A> clss);
+ <A> A get(String key, Class<A> clss) throws IllegalArgumentException;
- ContentSession getSession();
+// 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());
}
/*
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);
}
/*