/*
 * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
 * Copyright Jayasoft 2005 - All rights reserved
 * 
 * #SNAPSHOT#
 */
package fr.jayasoft.ivy.namespace;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import fr.jayasoft.ivy.ModuleRevisionId;

public class Namespace {
    public static final Namespace SYSTEM_NAMESPACE;
    static {
        SYSTEM_NAMESPACE = new Namespace();
    }
    
    private List _rules = new ArrayList();
    private String _name;
    private NamespaceTransformer _fromSystemTransformer = new NamespaceTransformer() {
        public ModuleRevisionId transform(ModuleRevisionId mrid) {
            for (Iterator iter = _rules.iterator(); iter.hasNext();) {
                NamespaceRule rule = (NamespaceRule)iter.next();
                mrid = rule.getFromSystem().transform(mrid);
            }
            return mrid;
        }
        public boolean isIdentity() {
            return _rules.isEmpty();
        }
    };
    private NamespaceTransformer _toSystemTransformer = new NamespaceTransformer() {
        public ModuleRevisionId transform(ModuleRevisionId mrid) {
            for (Iterator iter = _rules.iterator(); iter.hasNext();) {
                NamespaceRule rule = (NamespaceRule)iter.next();
                mrid = rule.getToSystem().transform(mrid);
            }
            return mrid;
        }
        public boolean isIdentity() {
            return _rules.isEmpty();
        }
    };
    
    public void addRule(NamespaceRule rule) {
        _rules.add(rule);
    }

    public String getName() {
        return _name;
    }

    public void setName(String name) {
        _name = name;
    }
    
    public NamespaceTransformer getFromSystemTransformer() {
        return _fromSystemTransformer;
    }
    public NamespaceTransformer getToSystemTransformer() {
        return _toSystemTransformer;
    }
}

@@ -554,24 +554,66 @@
 ing _name;%0D%0A
+    private boolean _chainRules = false;%0D%0A
     private 
@@ -680,32 +680,32 @@
 ransformer() %7B%0D%0A
-
         public M
@@ -902,32 +902,50 @@
                 
+ModuleRevisionId n
 mrid = rule.getF
@@ -966,32 +966,208 @@
 ansform(mrid);%0D%0A
+                if (_chainRules) %7B%0D%0A                    mrid = nmrid;%0D%0A                %7D else if (!nmrid.equals(mrid)) %7B%0D%0A                    return nmrid;%0D%0A                %7D%0D%0A
             %7D%0D%0A 
@@ -1602,24 +1602,42 @@
             
+ModuleRevisionId n
 mrid = rule.
@@ -1660,32 +1660,208 @@
 ansform(mrid);%0D%0A
+                if (_chainRules) %7B%0D%0A                    mrid = nmrid;%0D%0A                %7D else if (!nmrid.equals(mrid)) %7B%0D%0A                    return nmrid;%0D%0A                %7D%0D%0A
             %7D%0D%0A 
@@ -2381,32 +2381,32 @@
 ransformer() %7B%0D%0A
-
         return _
@@ -2433,12 +2433,184 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    public boolean isChainrules() %7B%0D%0A        return _chainRules;%0D%0A    %7D%0D%0A%0D%0A    public void setChainrules(boolean chainRules) %7B%0D%0A        _chainRules = chainRules;%0D%0A    %7D%0D
 %0A%7D%0D%0A

add chainrules setup