minor
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / ConfigImpl.java
index c561e364b287958a169a90eb611baa58769ed3fc..75b8222c04363038f3ed289eb5386a9c7843aded 100644 (file)
@@ -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;
@@ -31,7 +33,9 @@ import org.wamblee.xmlrouter.config.Identifiable;
  * 
  * @param <T>
  */
-public abstract class ConfigImpl<T extends Identifiable> implements
+// TODO make sure that each item inside this config is prefixed with the id of
+// the config.
+public abstract class ConfigImpl<T extends Identifiable<T>> implements
     ExtendedConfig<T> {
 
     private Id<Config> id;
@@ -41,7 +45,7 @@ public abstract class ConfigImpl<T extends Identifiable> implements
      * Constructs the object.
      */
     public ConfigImpl(Id<Config> aId) {
-        // TODO test for null.
+        notNull("id", aId);
         id = aId;
         registered = new ArrayList<T>();
     }
@@ -58,9 +62,8 @@ public abstract class ConfigImpl<T extends Identifiable> 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 +73,7 @@ public abstract class ConfigImpl<T extends Identifiable> 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 +84,7 @@ public abstract class ConfigImpl<T extends Identifiable> implements
      */
     @Override
     public synchronized boolean remove(Id<T> aId) {
-        notNull(aId);
+        notNull("aId", aId);
         Iterator<T> i = registered.iterator();
         while (i.hasNext()) {
             T t = i.next();
@@ -97,16 +100,4 @@ public abstract class ConfigImpl<T extends Identifiable> implements
     public List<T> values() {
         return Collections.unmodifiableList(registered);
     }
-
-    private void notNull(T aT) {
-        if (aT == null) {
-            throw new NullPointerException("Object is null");
-        }
-    }
-
-    private void notNull(Id<T> aId) {
-        if (aId == null) {
-            throw new NullPointerException("Id is null");
-        }
-    }
 }