]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java
Implement kill and process progress
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / structure / tree / TreeSRegistry.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 java.util.List;
20 import java.util.Map;
21 import java.util.TreeMap;
22 import java.util.Vector;
23
24 import org.argeo.slc.UnsupportedException;
25 import org.argeo.slc.core.structure.SimpleSElement;
26 import org.argeo.slc.structure.StructureElement;
27 import org.argeo.slc.structure.StructureRegistry;
28
29 /** Tree based implementation of a structure registry. */
30 public class TreeSRegistry implements StructureRegistry<TreeSPath> {
31 /** For ORM */
32 private Long tid;
33 private Map<TreeSPath, SimpleSElement> elements = new TreeMap<TreeSPath, SimpleSElement>();
34
35 private String mode = StructureRegistry.ALL;
36
37 private List<TreeSPath> activePaths;
38
39 @SuppressWarnings("unchecked")
40 public <T extends StructureElement> T getElement(TreeSPath path) {
41 return (T) elements.get(path);
42 }
43
44 public List<StructureElement> listElements() {
45 return new Vector<StructureElement>(elements.values());
46 }
47
48 public List<TreeSPath> listPaths() {
49 return new Vector<TreeSPath>(elements.keySet());
50 }
51
52 public void register(TreeSPath path, StructureElement element) {
53 if (path == null)
54 throw new UnsupportedException("Cannot register under a null path.");
55 if (element == null)
56 throw new UnsupportedException(
57 "Cannot register null element for path " + path);
58 if (element.getLabel() == null)
59 throw new UnsupportedException(
60 "Cannot register an element with null label for path "
61 + path);
62
63 final SimpleSElement simpleSElement;
64 if (element instanceof SimpleSElement) {
65 simpleSElement = (SimpleSElement) element;
66 } else {
67 simpleSElement = new SimpleSElement(element.getLabel());
68 }
69
70 elements.put(path, simpleSElement);
71 }
72
73 public String getMode() {
74 return mode;
75 }
76
77 public void setMode(String mode) {
78 this.mode = mode;
79 }
80
81 public List<TreeSPath> getActivePaths() {
82 return activePaths;
83 }
84
85 public void setActivePaths(List<TreeSPath> activePaths) {
86 this.activePaths = activePaths;
87 }
88
89 /** Gets the elements. */
90 public Map<TreeSPath, SimpleSElement> getElements() {
91 return elements;
92 }
93
94 /** Sets the elements (for ORM). */
95 public void setElements(Map<TreeSPath, SimpleSElement> elements) {
96 this.elements = elements;
97 }
98
99 Long getTid() {
100 return tid;
101 }
102
103 void setTid(Long tid) {
104 this.tid = tid;
105 }
106
107 }