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