import org.argeo.api.acr.Content;
import org.argeo.api.acr.CrName;
+import org.argeo.api.acr.NamespaceUtils;
import org.argeo.api.acr.spi.ProvidedContent;
import org.argeo.api.acr.spi.ProvidedSession;
+import org.argeo.util.LangUtils;
/** Partial reference implementation of a {@link ProvidedContent}. */
public abstract class AbstractContent extends AbstractMap<QName, Object> implements ProvidedContent {
private final ProvidedSession session;
+ // cache
+// private String _path = null;
+
public AbstractContent(ProvidedSession session) {
this.session = session;
}
public <A> Optional<List<A>> getMultiple(QName key, Class<A> clss) {
Object value = get(key);
if (value == null)
- return null;
+ return Optional.empty();
if (value instanceof List) {
try {
List<A> res = (List<A>) value;
@Override
public String getPath() {
+// if (_path != null)
+// return _path;
List<Content> ancestors = new ArrayList<>();
collectAncestors(ancestors, this);
StringBuilder path = new StringBuilder();
- for (Content c : ancestors) {
+ ancestors: for (Content c : ancestors) {
QName name = c.getName();
- // FIXME
- if (!CrName.ROOT.get().equals(name))
- path.append('/').append(name);
+ if (CrName.root.qName().equals(name))
+ continue ancestors;
+
+ path.append('/');
+ path.append(NamespaceUtils.toPrefixedName(name));
+ int siblingIndex = c.getSiblingIndex();
+ if (siblingIndex != 1)
+ path.append('[').append(siblingIndex).append(']');
}
+// _path = path.toString();
+// return _path;
return path.toString();
}
*/
@Override
- public List<QName> getTypes() {
+ public List<QName> getContentClasses() {
return new ArrayList<>();
}
/*
* DEFAULTS
*/
- // - no children
- // - no attributes
- // - cannot be modified
+ // - no children
+ // - no attributes
+ // - cannot be modified
@Override
public Iterator<Content> iterator() {
return Collections.emptyIterator();
@Override
public int size() {
-
- int count = 0;
- for (Iterator<QName> it = keys().iterator(); it.hasNext();) {
- count++;
- }
- return count;
+ return LangUtils.size(keys());
}
}
+
+ /*
+ * OBJECT METHODS
+ */
+ @Override
+ public String toString() {
+ return "content " + getPath();
+ }
}