package org.argeo.slc.core.structure.tree;
import org.argeo.slc.core.structure.SimpleSElement;
import org.argeo.slc.structure.StructureAware;
import org.argeo.slc.structure.StructureElement;
import org.argeo.slc.structure.StructureRegistry;
/**
* Provides default implementations of some methods of TreeSRelated
* .
*/
public abstract class TreeSRelatedHelper implements TreeSRelated {
private TreeSPath basePath;
private StructureRegistry registry;
// private ThreadLocal basePath = new ThreadLocal();
// private ThreadLocal> registry = new
// ThreadLocal>();
public TreeSPath getBasePath() {
return basePath;
}
public StructureRegistry getRegistry() {
return registry;
}
public void notifyCurrentPath(StructureRegistry registry,
TreeSPath path) {
this.basePath = path;
this.registry = registry;
}
public StructureElement getStructureElement(String key) {
return new SimpleSElement(key);
}
/**
* Checks wether the object is {@link StructureAware} and forward path and
* registry. null safe for both arguments.
*/
@SuppressWarnings(value = { "unchecked" })
protected void forwardPath(Object obj, String childName) {
if (obj == null)
return;
if (obj instanceof StructureAware && basePath != null) {
TreeSPath path;
if (childName != null)
path = basePath.createChild(childName);
else
path = basePath;
((StructureAware) obj).notifyCurrentPath(registry, path);
}
}
}