X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fstructure%2Ftree%2FTreeSRelatedHelper.java;h=b0cc87bf9c8a6d96b7f930455c44dba31504fb30;hb=719f374a748e531ae706115252978e06ad72c308;hp=8dc00784e8dfc7ba5e97d5834016fd02f1192d19;hpb=8328dc992e509741b6b9a5036cc7c10089c116f2;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java index 8dc00784e..b0cc87bf9 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java @@ -1,16 +1,22 @@ 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. + * 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; } @@ -21,7 +27,7 @@ public abstract class TreeSRelatedHelper implements TreeSRelated { public void notifyCurrentPath(StructureRegistry registry, TreeSPath path) { - basePath = path; + this.basePath = path; this.registry = registry; } @@ -29,4 +35,24 @@ public abstract class TreeSRelatedHelper implements TreeSRelated { 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); + } + } + }