]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java
Improve SystemCall
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / structure / tree / TreeSRelatedHelper.java
index 8dc00784e8dfc7ba5e97d5834016fd02f1192d19..b0cc87bf9c8a6d96b7f930455c44dba31504fb30 100644 (file)
@@ -1,16 +1,22 @@
 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
+ * 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
@@ -21,7 +27,7 @@ public abstract class TreeSRelatedHelper implements TreeSRelated {
 \r
        public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
                        TreeSPath path) {\r
-               basePath = path;\r
+               this.basePath = path;\r
                this.registry = registry;\r
        }\r
 \r
@@ -29,4 +35,24 @@ public abstract class TreeSRelatedHelper implements TreeSRelated {
                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