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