X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FCompositeConfig.java;h=3b45a3ef25b5d35d395e8703bafec1db0f1946cd;hb=3b2c669b25bfcb5a3c3f06ff9180d85143bebb2a;hp=5166315e7640504643c80307c42ea782a0902a9c;hpb=e52385618670b54a5c6a4f2fbfab381bef43a905;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java index 5166315..3b45a3e 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java @@ -15,52 +15,89 @@ */ package org.wamblee.xmlrouter.impl; +import static org.wamblee.xmlrouter.impl.MessageUtil.*; + import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.wamblee.xmlrouter.common.Id; -import org.wamblee.xmlrouter.config.Config; +import org.wamblee.xmlrouter.config.Identifiable; + +/** + * Composite config. The composite config + * + * @author Erik Brakkee + * + * @param + */ +public class CompositeConfig> implements + ExtendedConfig { + + private static final String PREFIX = "compositeconfig"; + private static final String READ_ONLY_INSTANCE = "read only instance"; -public class CompositeConfig implements ExtendedConfig { + private Class type; + private Set prefixes; + private List> valueIds; + private List values; - private Id id; - private List configs; + public CompositeConfig(Class aType) { + type = aType; + prefixes = new HashSet(); + valueIds = new ArrayList>(); + values = new ArrayList(); + } - public CompositeConfig(Id aId) { - id = aId; - configs = new ArrayList(); + @Override + public Class getType() { + return type; } @Override - public Id getId() { - // TODO test id. - return id; + public String getPrefix() { + return PREFIX; } - public void add(Config aConfig) { - // TODO check duplicate config. + public void addConfig(Config aConfig) { + notNull("aConfig", aConfig); + if (prefixes.contains(aConfig.getPrefix())) { + throw new ConfigException("duplicate prefix '" + + aConfig.getPrefix() + "'"); + } + String prefix = aConfig.getPrefix() + "."; for (T item : aConfig.values()) { - configs.add(item); + Id newId = new Id(prefix + item.getId()); + if (valueIds.contains(newId)) { + throw new ConfigException("duplicate id '" + + item.getId().toString() + "'"); + } + } + + prefixes.add(aConfig.getPrefix()); + + for (T item : aConfig.values()) { + Id newId = new Id(prefix + item.getId()); + valueIds.add(newId); + values.add(IdentifiablePrefixProxyFactory.getProxy(prefix, item, + Identifiable.class, aConfig.getType())); } } @Override public List values() { - return configs; + return values; } @Override public boolean remove(Id aId) { - notSupported(); + notSupported(READ_ONLY_INSTANCE); return false; } @Override public void add(T aT) { - notSupported(); - } - - private void notSupported() { - throw new RuntimeException("readonly instance"); + notSupported(READ_ONLY_INSTANCE); } }