001 /*
002 * Copyright 2008 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package org.springframework.richclient.application.support;
017
018 import java.util.HashMap;
019 import java.util.List;
020 import java.util.Map;
021
022 import org.springframework.richclient.application.ViewDescriptor;
023 import org.springframework.richclient.application.ViewDescriptorRegistry;
024 import org.springframework.util.Assert;
025
026 /**
027 * Very simple {@link ViewDescriptorRegistry} implementation, mostly for testing purposes.
028 *
029 * @author Peter De Bruycker
030 */
031 public class SimpleViewDescriptorRegistry implements ViewDescriptorRegistry {
032
033 private Map<String, ViewDescriptor> descriptors = new HashMap<String, ViewDescriptor>();
034
035 public SimpleViewDescriptorRegistry() {
036
037 }
038
039 public SimpleViewDescriptorRegistry(List<ViewDescriptor> descriptors) {
040 Assert.notNull(descriptors, "descriptors cannot be null");
041
042 for (ViewDescriptor descriptor : descriptors) {
043 addViewDescriptor(descriptor);
044 }
045 }
046
047 public void addViewDescriptor(ViewDescriptor descriptor) {
048 Assert.notNull(descriptor, "descriptor cannot be null");
049
050 descriptors.put(descriptor.getId(), descriptor);
051 }
052
053 public void removeViewDescriptor(ViewDescriptor descriptor) {
054 Assert.notNull(descriptor, "descriptor cannot be null");
055
056 descriptors.remove(descriptor.getId());
057 }
058
059 public ViewDescriptor getViewDescriptor(String viewDescriptorId) {
060 Assert.hasText(viewDescriptorId, "viewDescriptorId cannot be empty");
061
062 return descriptors.get(viewDescriptorId);
063 }
064
065 public ViewDescriptor[] getViewDescriptors() {
066 return descriptors.values().toArray(new ViewDescriptor[descriptors.size()]);
067 }
068
069 }