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