import org.argeo.api.acr.CrName;
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;
}
@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) {
QName name = c.getName();
// FIXME
- if (!CrName.ROOT.get().equals(name))
+ if (!CrName.root.qName().equals(name))
path.append('/').append(name);
}
- return path.toString();
+ _path = path.toString();
+ return _path;
}
private void collectAncestors(List<Content> ancestors, Content content) {
*/
@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();
+ }
}