]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java
Restructure modules
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / structure / tree / TreeSRelatedHelper.java
1 package org.argeo.slc.core.structure.tree;
2
3 import org.argeo.slc.core.structure.SimpleSElement;
4 import org.argeo.slc.structure.StructureAware;
5 import org.argeo.slc.structure.StructureElement;
6 import org.argeo.slc.structure.StructureRegistry;
7
8 /**
9 * Provides default implementations of some methods of <code>TreeSRelated</code>
10 * .
11 */
12 public abstract class TreeSRelatedHelper implements TreeSRelated {
13 private TreeSPath basePath;
14 private StructureRegistry<TreeSPath> registry;
15
16 // private ThreadLocal<TreeSPath> basePath = new ThreadLocal<TreeSPath>();
17 // private ThreadLocal<StructureRegistry<TreeSPath>> registry = new
18 // ThreadLocal<StructureRegistry<TreeSPath>>();
19
20 public TreeSPath getBasePath() {
21 return basePath;
22 }
23
24 public StructureRegistry<TreeSPath> getRegistry() {
25 return registry;
26 }
27
28 public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,
29 TreeSPath path) {
30 this.basePath = path;
31 this.registry = registry;
32 }
33
34 public StructureElement getStructureElement(String key) {
35 return new SimpleSElement(key);
36 }
37
38 /**
39 * Checks wether the object is {@link StructureAware} and forward path and
40 * registry. null safe for both arguments.
41 */
42 @SuppressWarnings(value = { "unchecked" })
43 protected void forwardPath(Object obj, String childName) {
44 if (obj == null)
45 return;
46
47 if (obj instanceof StructureAware && basePath != null) {
48 TreeSPath path;
49 if (childName != null)
50 path = basePath.createChild(childName);
51 else
52 path = basePath;
53
54 ((StructureAware<TreeSPath>) obj).notifyCurrentPath(registry, path);
55 }
56 }
57
58 }