Config no longer implements Identifiable because this was in violation of the contrac...
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / ConfigImpl.java
index a1733ab41bf84a9b84cb3986f460586871bd763e..ae2351f97d37c2e4ae08c5dd0d7a7d5ea090352a 100644 (file)
@@ -23,8 +23,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
-import org.wamblee.xmlrouter.config.ConfigException;
 import org.wamblee.xmlrouter.config.Identifiable;
 
 /**
@@ -37,21 +35,44 @@ import org.wamblee.xmlrouter.config.Identifiable;
 public abstract class ConfigImpl<T extends Identifiable<T>> implements
     ExtendedConfig<T> {
 
-    private Id<Config> id;
+    private Class<T> type;
+    private String prefix;
     private Map<Id<T>, T> registered;
 
     /**
      * Constructs the object.
      */
-    public ConfigImpl(Id<Config> aId) {
-        notNull("id", aId);
-        id = aId;
+    public ConfigImpl(Class<T> aType, String aPrefix) {
+        notNull("type", aType);
+        notNull("id", aPrefix);
+        type = aType;
+        prefix = aPrefix;
         registered = new HashMap<Id<T>, T>();
     }
 
     @Override
-    public Id<Config> getId() {
-        return id;
+    public Class<T> getType() {
+        return type;
+    }
+
+    /**
+     * Copies the config object.
+     * 
+     * @param aConfig
+     *            Config to copy.
+     */
+    public ConfigImpl(ConfigImpl<T> aConfig) {
+        notNull("config", aConfig);
+        prefix = aConfig.prefix;
+        registered = new HashMap<Id<T>, T>();
+        for (Map.Entry<Id<T>, T> entry : aConfig.registered.entrySet()) {
+            registered.put(entry.getKey(), entry.getValue());
+        }
+    }
+
+    @Override
+    public String getPrefix() {
+        return prefix;
     }
 
     /*
@@ -65,7 +86,7 @@ public abstract class ConfigImpl<T extends Identifiable<T>> implements
         if (registered.containsKey(aT.getId())) {
             throw new ConfigException("Duplicate id '" + aT.getId() + "'");
         }
-        registered.put(aT.getId(), wrap(id.getId() + ".", aT));
+        registered.put(aT.getId(), wrap(aT));
     }
 
     /**
@@ -75,7 +96,7 @@ public abstract class ConfigImpl<T extends Identifiable<T>> implements
      *            Object to wrap.
      * @return Wrapped object.
      */
-    public abstract T wrap(String aPrefix, T aT);
+    public abstract T wrap(T aT);
 
     /*
      * (non-Javadoc)