id prefixes are now done at the very last moment instead of when an item is added.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / SingleRouterConfig.java
index b069215b102731099ee88f6a22384af64a5ac886..4ecaad4a35d633679620f791426242f868784b35 100644 (file)
@@ -22,6 +22,8 @@ import org.wamblee.xmlrouter.config.Filter;
 import org.wamblee.xmlrouter.config.RouterConfig;
 import org.wamblee.xmlrouter.config.Transformation;
 
+// TODO implement copying of routerconfig. 
+
 /**
  * Represents a single configuration set of a single configuration client of the
  * XML router.
@@ -29,43 +31,82 @@ import org.wamblee.xmlrouter.config.Transformation;
  * @author Erik Brakkee
  */
 public class SingleRouterConfig implements ExtendedRouterConfig {
+
+    public static final class DocumentConfig extends ConfigImpl<DocumentType> {
+        public DocumentConfig(Id<Config> aId) {
+            super(DocumentType.class, aId);
+        }
+
+        public DocumentConfig(DocumentConfig aConfig) {
+            super(aConfig);
+        }
+
+        @Override
+        public DocumentType wrap(String aPrefix, DocumentType aT) {
+            return new RobustDocumentType("", aT);
+        }
+    }
+
+    public static final class TransformationConfig extends
+        ConfigImpl<Transformation> {
+        public TransformationConfig(Id<Config> aId) {
+            super(Transformation.class, aId);
+        }
+
+        public TransformationConfig(TransformationConfig aConfig) {
+            super(aConfig);
+        }
+
+        @Override
+        public Transformation wrap(String aPrefix,
+            Transformation aTransformation) {
+            return new RobustTransformation("", aTransformation);
+        }
+    }
+
+    public static final class FilterConfig extends ConfigImpl<Filter> {
+        public FilterConfig(Id<Config> aId) {
+            super(Filter.class, aId);
+        }
+
+        public FilterConfig(FilterConfig aConfig) {
+            super(aConfig);
+        }
+
+        @Override
+        public Filter wrap(String aPrefix, Filter aFilter) {
+            return new RobustFilter("", aFilter);
+        }
+    }
+
     private Id<RouterConfig> id;
-    private ExtendedConfig<DocumentType> documentTypes;
-    private ExtendedConfig<Transformation> transformations;
-    private ExtendedConfig<Filter> filters;
+
+    private DocumentConfig documentTypes;
+    private TransformationConfig transformations;
+    private FilterConfig filters;
 
     /**
      * Constructs a router configuration.
      * 
-     * @param aSequenceNumberGenerator
-     *            Sequence number generator to use.
+     * @param aId
+     *            Unique id for this configuration.
      */
     public SingleRouterConfig(Id<RouterConfig> aId) {
         id = aId;
-        documentTypes = new ConfigImpl<DocumentType>(new Id<Config>(
-            "documentTypes")) {
-            @Override
-            public DocumentType wrap(String aPrefix, DocumentType aT) {
-                return new RobustDocumentType(aPrefix, aT);
-            }
-        };
-        transformations = new ConfigImpl<Transformation>(new Id<Config>(
-            "transformations")) {
-            @Override
-            public Transformation wrap(String aPrefix,
-                Transformation aTransformation) {
-                return new RobustTransformation(aPrefix, aTransformation);
-            }
-        };
-        filters = new ConfigImpl<Filter>(new Id<Config>("filters")) {
-            @Override
-            public Filter wrap(String aPrefix, Filter aFilter) {
-                return new RobustFilter(aPrefix, aFilter);
-            }
-        };
+        documentTypes = new DocumentConfig(new Id<Config>(aId.getId() +
+            ".documenttypes"));
+        transformations = new TransformationConfig(new Id<Config>(aId.getId() +
+            ".transformations"));
+        filters = new FilterConfig(new Id<Config>(aId.getId() + ".filters"));
+    }
+
+    public SingleRouterConfig(SingleRouterConfig aConfig) {
+        id = aConfig.id;
+        documentTypes = new DocumentConfig(aConfig.documentTypes);
+        transformations = new TransformationConfig(aConfig.transformations);
+        filters = new FilterConfig(aConfig.filters);
     }
 
-    // TODO test getId.
     @Override
     public Id<RouterConfig> getId() {
         return id;
@@ -85,4 +126,25 @@ public class SingleRouterConfig implements ExtendedRouterConfig {
     public Config<Filter> filterConfig() {
         return filters;
     }
+
+    @Override
+    public boolean equals(Object aObj) {
+        if (aObj == null) {
+            return false;
+        }
+        if (!(aObj instanceof SingleRouterConfig)) {
+            return false;
+        }
+        SingleRouterConfig obj = (SingleRouterConfig) aObj;
+
+        return documentTypes.equals(obj.documentTypes) &&
+            transformations.equals(obj.transformations) &&
+            filters.equals(obj.filters);
+    }
+
+    @Override
+    public int hashCode() {
+        return documentTypes.hashCode() + transformations.hashCode() +
+            filters.hashCode();
+    }
 }