]> 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
First working GPS position provider
[gpl/argeo-slc.git] / runtime / 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.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 @SuppressWarnings("unchecked")
24 public <T extends StructureElement> T getElement(TreeSPath path) {
25 return (T) elements.get(path);
26 }
27
28 public List<StructureElement> listElements() {
29 return new Vector<StructureElement>(elements.values());
30 }
31
32 public List<TreeSPath> listPaths() {
33 return new Vector<TreeSPath>(elements.keySet());
34 }
35
36 public void register(TreeSPath path, StructureElement element) {
37 if (path == null)
38 throw new UnsupportedException("Cannot register under a null path.");
39 if (element == null)
40 throw new UnsupportedException(
41 "Cannot register null element for path " + path);
42 if (element.getLabel() == null)
43 throw new UnsupportedException(
44 "Cannot register an element with null label for path "
45 + path);
46
47 final SimpleSElement simpleSElement;
48 if (element instanceof SimpleSElement) {
49 simpleSElement = (SimpleSElement) element;
50 } else {
51 simpleSElement = new SimpleSElement(element.getLabel());
52 }
53
54 elements.put(path, simpleSElement);
55 }
56
57 public String getMode() {
58 return mode;
59 }
60
61 public void setMode(String mode) {
62 this.mode = mode;
63 }
64
65 public List<TreeSPath> getActivePaths() {
66 return activePaths;
67 }
68
69 public void setActivePaths(List<TreeSPath> activePaths) {
70 this.activePaths = activePaths;
71 }
72
73 /** Gets the elements. */
74 public Map<TreeSPath, SimpleSElement> getElements() {
75 return elements;
76 }
77
78 /** Sets the elements (for ORM). */
79 public void setElements(Map<TreeSPath, SimpleSElement> elements) {
80 this.elements = elements;
81 }
82
83 Long getTid() {
84 return tid;
85 }
86
87 void setTid(Long tid) {
88 this.tid = tid;
89 }
90
91 }