Now using RouterConfig internally inside the XML Router.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / Transformations.java
index 7fd3e10e7041efd6173dcc35832b94e67d0cbc46..29e995916e78515fad607eb797ccc7923fd514f1 100644 (file)
@@ -17,41 +17,52 @@ package org.wamblee.xmlrouter.impl;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
 
 import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Transformation;
 
+/**
+ * This class manages transformations and computes the shortest transformations
+ * paths based on the provided transformations.
+ * 
+ * @author Erik Brakkee
+ * 
+ */
 public class Transformations {
 
-    private AtomicLong sequenceNumber;
     private Map<Id<Transformation>, Transformation> transformations;
     private List<String> vertices;
     private TransformationPath[][] matrix;
 
     private Map<String, List<TransformationPath>> sequences;
 
+    /**
+     * Construct the transformations.
+     */
     public Transformations() {
-        sequenceNumber = new AtomicLong(1);
         transformations = new LinkedHashMap<Id<Transformation>, Transformation>();
         vertices = new ArrayList<String>();
         matrix = new TransformationPath[0][0];
     }
 
-    public Id<Transformation> addTransformation(Transformation aTransformation) {
-        long seqno = sequenceNumber.getAndIncrement();
-        Id<Transformation> id = new Id<Transformation>(seqno);
-        transformations.put(id, new RobustTransformation(id, aTransformation));
+    public void replaceTransformations(
+        Map<Id<Transformation>, Transformation> aTransformations) {
+        transformations = aTransformations;
         computeTransformationSequences();
-        return id;
     }
 
+    /**
+     * Gets the possible target types based on an input type.
+     * 
+     * @param aType
+     *            Input type.
+     * @return Possible target types.
+     */
     public Collection<String> getPossibleTargetTypes(String aType) {
         int index = vertices.indexOf(aType);
         Set<String> res = new HashSet<String>();
@@ -93,6 +104,9 @@ public class Transformations {
         return matrix[i][j];
     }
 
+    /**
+     * Computest the transformation sequences using Floyd's algorithm.
+     */
     private void computeTransformationSequences() {
         vertices = new ArrayList<String>();
 
@@ -143,19 +157,6 @@ public class Transformations {
             .size();
     }
 
-    public void removeTransformation(Id<Transformation> aId) {
-        transformations.remove(aId);
-        computeTransformationSequences();
-    }
-
-    public Collection<Id<Transformation>> getTransformations() {
-        return Collections.unmodifiableCollection(transformations.keySet());
-    }
-
-    public Transformation getTransformation(Id<Transformation> aId) {
-        return transformations.get(aId);
-    }
-
     @Override
     public String toString() {
         StringBuffer buf = new StringBuffer();