/* * Copyright (C) 2007-2012 Mathieu Baudier * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.argeo.slc.core.structure.tree; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.Vector; import org.argeo.slc.UnsupportedException; import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.structure.StructureElement; import org.argeo.slc.structure.StructureRegistry; /** Tree based implementation of a structure registry. */ public class TreeSRegistry implements StructureRegistry { /** For ORM */ private Long tid; private Map elements = new TreeMap(); private String mode = StructureRegistry.ALL; private List activePaths; @SuppressWarnings("unchecked") public T getElement(TreeSPath path) { return (T) elements.get(path); } public List listElements() { return new Vector(elements.values()); } public List listPaths() { return new Vector(elements.keySet()); } public void register(TreeSPath path, StructureElement element) { if (path == null) throw new UnsupportedException("Cannot register under a null path."); if (element == null) throw new UnsupportedException( "Cannot register null element for path " + path); if (element.getLabel() == null) throw new UnsupportedException( "Cannot register an element with null label for path " + path); final SimpleSElement simpleSElement; if (element instanceof SimpleSElement) { simpleSElement = (SimpleSElement) element; } else { simpleSElement = new SimpleSElement(element.getLabel()); } elements.put(path, simpleSElement); } public String getMode() { return mode; } public void setMode(String mode) { this.mode = mode; } public List getActivePaths() { return activePaths; } public void setActivePaths(List activePaths) { this.activePaths = activePaths; } /** Gets the elements. */ public Map getElements() { return elements; } /** Sets the elements (for ORM). */ public void setElements(Map elements) { this.elements = elements; } Long getTid() { return tid; } void setTid(Long tid) { this.tid = tid; } }