]> 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
Update headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / structure / tree / TreeSRelatedHelper.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.core.structure.tree;
17
18 import org.argeo.slc.core.structure.SimpleSElement;
19 import org.argeo.slc.structure.StructureAware;
20 import org.argeo.slc.structure.StructureElement;
21 import org.argeo.slc.structure.StructureRegistry;
22
23 /**
24 * Provides default implementations of some methods of <code>TreeSRelated</code>
25 * .
26 */
27 public abstract class TreeSRelatedHelper implements TreeSRelated {
28 private TreeSPath basePath;
29 private StructureRegistry<TreeSPath> registry;
30
31 // private ThreadLocal<TreeSPath> basePath = new ThreadLocal<TreeSPath>();
32 // private ThreadLocal<StructureRegistry<TreeSPath>> registry = new
33 // ThreadLocal<StructureRegistry<TreeSPath>>();
34
35 public TreeSPath getBasePath() {
36 return basePath;
37 }
38
39 public StructureRegistry<TreeSPath> getRegistry() {
40 return registry;
41 }
42
43 public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,
44 TreeSPath path) {
45 this.basePath = path;
46 this.registry = registry;
47 }
48
49 public StructureElement getStructureElement(String key) {
50 return new SimpleSElement(key);
51 }
52
53 /**
54 * Checks wether the object is {@link StructureAware} and forward path and
55 * registry. null safe for both arguments.
56 */
57 @SuppressWarnings(value = { "unchecked" })
58 protected void forwardPath(Object obj, String childName) {
59 if (obj == null)
60 return;
61
62 if (obj instanceof StructureAware && basePath != null) {
63 TreeSPath path;
64 if (childName != null)
65 path = basePath.createChild(childName);
66 else
67 path = basePath;
68
69 ((StructureAware<TreeSPath>) obj).notifyCurrentPath(registry, path);
70 }
71 }
72
73 }