2 * Copyright 2005-2011 the original author or authors.
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.
16 package org.wamblee.xmlrouter.impl;
18 import static org.wamblee.xmlrouter.impl.MessageUtil.*;
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
25 import org.wamblee.xmlrouter.common.Id;
26 import org.wamblee.xmlrouter.config.Config;
27 import org.wamblee.xmlrouter.config.ConfigException;
28 import org.wamblee.xmlrouter.config.Identifiable;
31 * Composite config. The composite config
33 * @author Erik Brakkee
37 public class CompositeConfig<T extends Identifiable<T>> implements
40 private static final Id<Config> ID = new Id<Config>("compositeconfig");
41 private static final String READ_ONLY_INSTANCE = "read only instance";
42 private Set<Id<Config>> ids;
43 private List<Id<T>> valueIds;
44 private List<T> values;
46 public CompositeConfig() {
47 ids = new HashSet<Id<Config>>();
48 valueIds = new ArrayList<Id<T>>();
49 values = new ArrayList<T>();
53 public Id<Config> getId() {
57 public void addConfig(Config<T> aConfig) {
58 notNull("aConfig", aConfig);
59 if (ids.contains(aConfig.getId())) {
60 throw new ConfigException("duplicate id '" +
61 aConfig.getId().toString() + "'");
63 for (T item : aConfig.values()) {
64 if (valueIds.contains(item.getId())) {
65 throw new ConfigException("duplicate id '" +
66 item.getId().toString() + "'");
70 ids.add(aConfig.getId());
71 for (T item : aConfig.values()) {
72 valueIds.add(item.getId());
78 public List<T> values() {
83 public boolean remove(Id<T> aId) {
84 notSupported(READ_ONLY_INSTANCE);
89 public void add(T aT) {
90 notSupported(READ_ONLY_INSTANCE);