]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java
Start adding enhancement toward v0.8.1
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / structure / tree / TreeSRegistry.java
1 package org.argeo.slc.core.structure.tree;
2
3 import java.util.List;
4 import java.util.Map;
5 import java.util.TreeMap;
6 import java.util.Vector;
7
8 import org.argeo.slc.core.UnsupportedException;
9 import org.argeo.slc.core.structure.SimpleSElement;
10 import org.argeo.slc.core.structure.StructureElement;
11 import org.argeo.slc.core.structure.StructureRegistry;
12
13 /** Tree based implementation of a structure registry. */
14 public class TreeSRegistry implements StructureRegistry<TreeSPath> {
15 public final static String STATUS_ACTIVE = "STATUS_ACTIVE";
16
17 /** For ORM */
18 private Long tid;
19 private String status;
20 private Map<TreeSPath, SimpleSElement> elements = new TreeMap<TreeSPath, SimpleSElement>();
21
22 private String mode = StructureRegistry.ALL;
23
24 private List<TreeSPath> activePaths;
25
26 public <T extends StructureElement> T getElement(TreeSPath path) {
27 return (T)elements.get(path);
28 }
29
30 public List<StructureElement> listElements() {
31 return new Vector<StructureElement>(elements.values());
32 }
33
34 public List<TreeSPath> listPaths() {
35 return new Vector<TreeSPath>(elements.keySet());
36 }
37
38 public void register(TreeSPath path, StructureElement element) {
39 final SimpleSElement simpleSElement;
40 if (element instanceof SimpleSElement) {
41 simpleSElement = (SimpleSElement) element;
42 } else {
43 simpleSElement = new SimpleSElement(element.getLabel());
44 }
45
46 if (path == null)
47 throw new UnsupportedException("Path cannot be null.");
48
49 elements.put(path, simpleSElement);
50
51 }
52
53 public String getMode() {
54 return mode;
55 }
56
57 public void setMode(String mode) {
58 this.mode = mode;
59 }
60
61 public List<TreeSPath> getActivePaths() {
62 return activePaths;
63 }
64
65 public void setActivePaths(List<TreeSPath> activePaths) {
66 this.activePaths = activePaths;
67 }
68
69 public String getStatus() {
70 return status;
71 }
72
73 public void setStatus(String status) {
74 this.status = status;
75 }
76
77 /** Gets the elements. */
78 public Map<TreeSPath, SimpleSElement> getElements() {
79 return elements;
80 }
81
82 /** Sets the elements (for ORM). */
83 public void setElements(Map<TreeSPath, SimpleSElement> elements) {
84 this.elements = elements;
85 }
86
87 Long getTid() {
88 return tid;
89 }
90
91 void setTid(Long tid) {
92 this.tid = tid;
93 }
94
95 }