2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.core
.structure
.tree
;
19 import java
.util
.List
;
21 import java
.util
.TreeMap
;
22 import java
.util
.Vector
;
24 import org
.argeo
.slc
.UnsupportedException
;
25 import org
.argeo
.slc
.core
.structure
.SimpleSElement
;
26 import org
.argeo
.slc
.structure
.StructureElement
;
27 import org
.argeo
.slc
.structure
.StructureRegistry
;
29 /** Tree based implementation of a structure registry. */
30 public class TreeSRegistry
implements StructureRegistry
<TreeSPath
> {
33 private Map
<TreeSPath
, SimpleSElement
> elements
= new TreeMap
<TreeSPath
, SimpleSElement
>();
35 private String mode
= StructureRegistry
.ALL
;
37 private List
<TreeSPath
> activePaths
;
39 @SuppressWarnings("unchecked")
40 public <T
extends StructureElement
> T
getElement(TreeSPath path
) {
41 return (T
) elements
.get(path
);
44 public List
<StructureElement
> listElements() {
45 return new Vector
<StructureElement
>(elements
.values());
48 public List
<TreeSPath
> listPaths() {
49 return new Vector
<TreeSPath
>(elements
.keySet());
52 public void register(TreeSPath path
, StructureElement element
) {
54 throw new UnsupportedException("Cannot register under a null path.");
56 throw new UnsupportedException(
57 "Cannot register null element for path " + path
);
58 if (element
.getLabel() == null)
59 throw new UnsupportedException(
60 "Cannot register an element with null label for path "
63 final SimpleSElement simpleSElement
;
64 if (element
instanceof SimpleSElement
) {
65 simpleSElement
= (SimpleSElement
) element
;
67 simpleSElement
= new SimpleSElement(element
.getLabel());
70 elements
.put(path
, simpleSElement
);
73 public String
getMode() {
77 public void setMode(String mode
) {
81 public List
<TreeSPath
> getActivePaths() {
85 public void setActivePaths(List
<TreeSPath
> activePaths
) {
86 this.activePaths
= activePaths
;
89 /** Gets the elements. */
90 public Map
<TreeSPath
, SimpleSElement
> getElements() {
94 /** Sets the elements (for ORM). */
95 public void setElements(Map
<TreeSPath
, SimpleSElement
> elements
) {
96 this.elements
= elements
;
103 void setTid(Long tid
) {