import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.Config;
-import org.wamblee.xmlrouter.config.DuplicateException;
+import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
/**
public class CompositeConfig<T extends Identifiable<T>> implements
ExtendedConfig<T> {
+ private static final Id<Config> ID = new Id<Config>("compositeconfig");
private static final String READ_ONLY_INSTANCE = "read only instance";
+
+ private Class<T> type;
private Set<Id<Config>> ids;
- private Id<Config> id;
private List<Id<T>> valueIds;
private List<T> values;
- public CompositeConfig(Id<Config> aId) {
- notNull("aId", aId);
+ public CompositeConfig(Class<T> aType) {
+ type = aType;
ids = new HashSet<Id<Config>>();
- id = aId;
valueIds = new ArrayList<Id<T>>();
values = new ArrayList<T>();
}
+ @Override
+ public Class<T> getType() {
+ return type;
+ }
+
@Override
public Id<Config> getId() {
- return id;
+ return ID;
}
public void addConfig(Config<T> aConfig) {
notNull("aConfig", aConfig);
if (ids.contains(aConfig.getId())) {
- throw new DuplicateException(aConfig.getId().toString());
+ throw new ConfigException("duplicate id '" +
+ aConfig.getId().toString() + "'");
}
+ String prefix = aConfig.getId().getId() + ".";
for (T item : aConfig.values()) {
- if (valueIds.contains(item.getId())) {
- throw new DuplicateException(item.getId().toString());
+ Id<T> newId = new Id<T>(prefix + item.getId());
+ if (valueIds.contains(newId)) {
+ throw new ConfigException("duplicate id '" +
+ item.getId().toString() + "'");
}
}
ids.add(aConfig.getId());
+
for (T item : aConfig.values()) {
- valueIds.add(item.getId());
- values.add(item);
+ Id<T> newId = new Id<T>(prefix + item.getId());
+ valueIds.add(newId);
+ values.add(IdentifiablePrefixProxyFactory.getProxy(prefix, item,
+ Identifiable.class, aConfig.getType()));
}
}