]> 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
Implement kill and process progress
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / structure / tree / TreeSRelatedHelper.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
17 package org.argeo.slc.core.structure.tree;
18
19 import org.argeo.slc.core.structure.SimpleSElement;
20 import org.argeo.slc.structure.StructureAware;
21 import org.argeo.slc.structure.StructureElement;
22 import org.argeo.slc.structure.StructureRegistry;
23
24 /**
25 * Provides default implementations of some methods of <code>TreeSRelated</code>
26 * .
27 */
28 public abstract class TreeSRelatedHelper implements TreeSRelated {
29 private TreeSPath basePath;
30 private StructureRegistry<TreeSPath> registry;
31
32 // private ThreadLocal<TreeSPath> basePath = new ThreadLocal<TreeSPath>();
33 // private ThreadLocal<StructureRegistry<TreeSPath>> registry = new
34 // ThreadLocal<StructureRegistry<TreeSPath>>();
35
36 public TreeSPath getBasePath() {
37 return basePath;
38 }
39
40 public StructureRegistry<TreeSPath> getRegistry() {
41 return registry;
42 }
43
44 public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,
45 TreeSPath path) {
46 this.basePath = path;
47 this.registry = registry;
48 }
49
50 public StructureElement getStructureElement(String key) {
51 return new SimpleSElement(key);
52 }
53
54 /**
55 * Checks wether the object is {@link StructureAware} and forward path and
56 * registry. null safe for both arguments.
57 */
58 @SuppressWarnings(value = { "unchecked" })
59 protected void forwardPath(Object obj, String childName) {
60 if (obj == null)
61 return;
62
63 if (obj instanceof StructureAware && basePath != null) {
64 TreeSPath path;
65 if (childName != null)
66 path = basePath.createChild(childName);
67 else
68 path = basePath;
69
70 ((StructureAware<TreeSPath>) obj).notifyCurrentPath(registry, path);
71 }
72 }
73
74 }