equality based on the ids of the contents of SingleRouterConfig.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / SingleRouterConfig.java
index 36016ca302ee8df806e1264e690555a72d70ee9e..8eab34b708996198b73c4cbfd271462937ff1119 100644 (file)
  */
 package org.wamblee.xmlrouter.impl;
 
-import java.util.concurrent.atomic.AtomicLong;
-
 import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Config;
 import org.wamblee.xmlrouter.config.DocumentType;
 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.
@@ -30,7 +31,8 @@ import org.wamblee.xmlrouter.config.Transformation;
  * @author Erik Brakkee
  */
 public class SingleRouterConfig implements ExtendedRouterConfig {
-    private AtomicLong sequenceNumbers;
+    private Id<RouterConfig> id;
+
     private ExtendedConfig<DocumentType> documentTypes;
     private ExtendedConfig<Transformation> transformations;
     private ExtendedConfig<Filter> filters;
@@ -38,32 +40,40 @@ public class SingleRouterConfig implements ExtendedRouterConfig {
     /**
      * Constructs a router configuration.
      * 
-     * @param aSequenceNumberGenerator
-     *            Sequence number generator to use.
+     * @param aId
+     *            Unique id for this configuration.
      */
-    public SingleRouterConfig(AtomicLong aSequenceNumberGenerator) {
-        sequenceNumbers = aSequenceNumberGenerator;
-        documentTypes = new ConfigImpl<DocumentType>(sequenceNumbers) {
+    public SingleRouterConfig(Id<RouterConfig> aId) {
+        id = aId;
+        documentTypes = new ConfigImpl<DocumentType>(new Id<Config>(
+            aId.getId() + ".documenttypes")) {
             @Override
-            public DocumentType wrap(Id<DocumentType> aId, DocumentType aT) {
-                return new RobustDocumentType(aId, aT);
+            public DocumentType wrap(String aPrefix, DocumentType aT) {
+                return new RobustDocumentType(aPrefix, aT);
             }
         };
-        transformations = new ConfigImpl<Transformation>(sequenceNumbers) {
+        transformations = new ConfigImpl<Transformation>(new Id<Config>(
+            aId.getId() + ".transformations")) {
             @Override
-            public Transformation wrap(Id<Transformation> aId,
+            public Transformation wrap(String aPrefix,
                 Transformation aTransformation) {
-                return new RobustTransformation(aId, aTransformation);
+                return new RobustTransformation(aPrefix, aTransformation);
             }
         };
-        filters = new ConfigImpl<Filter>(sequenceNumbers) {
+        filters = new ConfigImpl<Filter>(new Id<Config>(aId.getId() +
+            ".filters")) {
             @Override
-            public Filter wrap(Id<Filter> aId, Filter aFilter) {
-                return new RobustFilter(aId, aFilter);
+            public Filter wrap(String aPrefix, Filter aFilter) {
+                return new RobustFilter(aPrefix, aFilter);
             }
         };
     }
 
+    @Override
+    public Id<RouterConfig> getId() {
+        return id;
+    }
+
     @Override
     public Config<DocumentType> documentTypeConfig() {
         return documentTypes;
@@ -80,16 +90,23 @@ public class SingleRouterConfig implements ExtendedRouterConfig {
     }
 
     @Override
-    public boolean isDirty() {
-        return documentTypes.isDirty() || transformations.isDirty() ||
-            filters.isDirty();
+    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 void resetDirty() {
-        documentTypes.resetDirty();
-        filters.resetDirty();
-        transformations.resetDirty();
+    public int hashCode() {
+        return documentTypes.hashCode() + transformations.hashCode() +
+            filters.hashCode();
     }
-
 }