]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java
Persist path and registry
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / core / structure / tree / TreeSRegistry.java
index 38c12add23f614285d1b75a4474319567d1e41a5..c7945cebf61ebf0edd274064f2aded990f418fb7 100644 (file)
@@ -1,58 +1,51 @@
 package org.argeo.slc.core.structure.tree;\r
 \r
 import java.util.List;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
 import java.util.Vector;\r
 \r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-\r
-import org.argeo.slc.core.structure.StructureAware;\r
+import org.argeo.slc.core.UnsupportedException;\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
 import org.argeo.slc.core.structure.StructureElement;\r
 import org.argeo.slc.core.structure.StructurePath;\r
 import org.argeo.slc.core.structure.StructureRegistry;\r
 \r
 public class TreeSRegistry implements StructureRegistry {\r
-       private static Log log = LogFactory.getLog(TreeSRegistry.class);\r
+       /** For ORM */\r
+       private Long tid;\r
+       private TreeSPath root;\r
+       private Map<TreeSPath, SimpleSElement> elements = new TreeMap<TreeSPath, SimpleSElement>();\r
 \r
-       private List<TreeSElement> elements = new Vector<TreeSElement>();\r
-       private List<TreeSPath> paths = new Vector<TreeSPath>();\r
        private String mode = StructureRegistry.ALL;\r
 \r
        private List<StructurePath> activePaths;\r
 \r
-       public List<StructureElement> listElements() {\r
-               return new Vector<StructureElement>(elements);\r
+       public StructureElement getElement(StructurePath path) {\r
+               return elements.get(path);\r
        }\r
 \r
-       public void register(StructureElement element) {\r
-               TreeSElement treeSElement = checkElement(element);\r
-               elements.add(treeSElement);\r
-               paths.add((TreeSPath) treeSElement.getPath());\r
-               log.debug("Registered " + treeSElement.getPath() + " (desc: "\r
-                               + treeSElement.getDescription() + " position: "\r
-                               + elements.size() + ")");\r
+       public List<StructureElement> listElements() {\r
+               return new Vector<StructureElement>(elements.values());\r
        }\r
 \r
-       public void register(StructureAware structureAware) {\r
-               register(structureAware.getElement());\r
-               structureAware.onRegister(this);\r
+       public List<StructurePath> listPaths() {\r
+               return new Vector<StructurePath>(elements.keySet());\r
        }\r
 \r
-       public StructureElement getElement(StructurePath path) {\r
-               int index = paths.indexOf(path);\r
-               if (index >= 0) {\r
-                       return elements.get(index);\r
-               } else {// not found\r
-                       return null;\r
+       public void register(StructurePath path, StructureElement element) {\r
+               final SimpleSElement simpleSElement;\r
+               if (element instanceof SimpleSElement){\r
+                       simpleSElement = (SimpleSElement)element;\r
+               }else{\r
+                       simpleSElement = new SimpleSElement(element.getDescription());\r
                }\r
-       }\r
+               \r
+               if (!(path instanceof TreeSPath))\r
+                       throw new UnsupportedException("path", path);\r
+\r
+               elements.put((TreeSPath) path, simpleSElement);\r
 \r
-       protected TreeSElement checkElement(StructureElement element) {\r
-               if (!(element instanceof TreeSElement)) {\r
-                       throw new RuntimeException("Element class " + element.getClass()\r
-                                       + " is not supported.");\r
-               }\r
-               return (TreeSElement) element;\r
        }\r
 \r
        public String getMode() {\r
@@ -70,6 +63,29 @@ public class TreeSRegistry implements StructureRegistry {
        public void setActivePaths(List<StructurePath> activePaths) {\r
                this.activePaths = activePaths;\r
        }\r
-       \r
-       \r
+\r
+       public TreeSPath getRoot() {\r
+               return root;\r
+       }\r
+\r
+       public void setRoot(TreeSPath root) {\r
+               this.root = root;\r
+       }\r
+\r
+       public Map<TreeSPath, SimpleSElement> getElements() {\r
+               return elements;\r
+       }\r
+\r
+       public void setElements(Map<TreeSPath, SimpleSElement> elements) {\r
+               this.elements = elements;\r
+       }\r
+\r
+       Long getTid() {\r
+               return tid;\r
+       }\r
+\r
+       void setTid(Long tid) {\r
+               this.tid = tid;\r
+       }\r
+\r
 }\r