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.Identifiable;
29 * Composite config. The composite config
31 * @author Erik Brakkee
35 public class CompositeConfig<T extends Identifiable<T>> implements
38 private static final String PREFIX = "compositeconfig";
39 private static final String READ_ONLY_INSTANCE = "read only instance";
41 private Class<T> type;
42 private Set<String> prefixes;
43 private List<Id<T>> valueIds;
44 private List<T> values;
46 public CompositeConfig(Class<T> aType) {
48 prefixes = new HashSet<String>();
49 valueIds = new ArrayList<Id<T>>();
50 values = new ArrayList<T>();
54 public Class<T> getType() {
59 public String getPrefix() {
63 public void addConfig(Config<T> aConfig) {
64 notNull("aConfig", aConfig);
65 if (prefixes.contains(aConfig.getPrefix())) {
66 throw new ConfigException("duplicate prefix '" +
67 aConfig.getPrefix() + "'");
69 String prefix = aConfig.getPrefix() + ".";
70 for (T item : aConfig.values()) {
71 Id<T> newId = new Id<T>(prefix + item.getId());
72 if (valueIds.contains(newId)) {
73 throw new ConfigException("duplicate id '" +
74 item.getId().toString() + "'");
78 prefixes.add(aConfig.getPrefix());
80 for (T item : aConfig.values()) {
81 Id<T> newId = new Id<T>(prefix + item.getId());
83 values.add(IdentifiablePrefixProxyFactory.getProxy(prefix, item,
84 Identifiable.class, aConfig.getType()));
89 public List<T> values() {
94 public boolean remove(Id<T> aId) {
95 notSupported(READ_ONLY_INSTANCE);
100 public void add(T aT) {
101 notSupported(READ_ONLY_INSTANCE);