X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FConfigImpl.java;h=0324e78f8353b1dd58598e49b66ecca786b6552d;hb=75f42f00e16ceee9ea333e598c9287de20ede1c3;hp=c561e364b287958a169a90eb611baa58769ed3fc;hpb=e52385618670b54a5c6a4f2fbfab381bef43a905;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java index c561e36..0324e78 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java @@ -15,6 +15,8 @@ */ package org.wamblee.xmlrouter.impl; +import static org.wamblee.xmlrouter.impl.MessageUtil.*; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -24,6 +26,9 @@ import org.wamblee.xmlrouter.common.Id; import org.wamblee.xmlrouter.config.Config; import org.wamblee.xmlrouter.config.Identifiable; +// TODO think real hard about the prefixing. We want a consistent view for clients. +// perhaps only provide a method to add items and hide all access to the ids. + /** * Default implementation of the {@link Config} interface. * @@ -31,7 +36,9 @@ import org.wamblee.xmlrouter.config.Identifiable; * * @param */ -public abstract class ConfigImpl implements +// TODO make sure that each item inside this config is prefixed with the id of +// the config. +public abstract class ConfigImpl> implements ExtendedConfig { private Id id; @@ -58,9 +65,8 @@ public abstract class ConfigImpl implements */ @Override public synchronized void add(T aT) { - // TODO test duplicate ids. - notNull(aT); - registered.add(wrap(aT)); + notNull("aT", aT); + registered.add(wrap(id.getId() + ".", aT)); } /** @@ -70,7 +76,7 @@ public abstract class ConfigImpl implements * Object to wrap. * @return Wrapped object. */ - public abstract T wrap(T aT); + public abstract T wrap(String aPrefix, T aT); /* * (non-Javadoc) @@ -81,7 +87,7 @@ public abstract class ConfigImpl implements */ @Override public synchronized boolean remove(Id aId) { - notNull(aId); + notNull("aId", aId); Iterator i = registered.iterator(); while (i.hasNext()) { T t = i.next(); @@ -97,16 +103,4 @@ public abstract class ConfigImpl implements public List values() { return Collections.unmodifiableList(registered); } - - private void notNull(T aT) { - if (aT == null) { - throw new NullPointerException("Object is null"); - } - } - - private void notNull(Id aId) { - if (aId == null) { - throw new NullPointerException("Id is null"); - } - } }