package org.openas2.processor.sender;

import java.util.HashMap;
import java.util.Map;

import org.openas2.message.Message;
import org.openas2.OpenAS2Exception;
import org.openas2.processor.BaseProcessorModule;
import org.openas2.processor.resender.ResenderModule;


public abstract class BaseSenderModule extends BaseProcessorModule implements SenderModule {
	
	// How many times should this message be sent?
	protected int retries (Map<Object,Object> options) {
		String left;
		if (options == null || (left = (String) options.get(SenderModule.SOPT_RETRIES)) == null) {
			try {
				left = getParameter (SenderModule.SOPT_RETRIES, false);
			}
			catch (OpenAS2Exception e) {
				// Can't actualy happen, but try convincing Java of that.
				// *FIXME* should have two versions of getParameter, one that can't throw.
				left = null;
			}
			
			if (left == null) left = SenderModule.DEFAULT_RETRIES;
		}
		
		return Integer.parseInt(left);	
	}
	
    protected boolean resend(String how, Message msg, OpenAS2Exception cause, int tries) throws OpenAS2Exception {
    	if (tries >= 0 && tries -- <= 0) return false;
        Map<Object,Object> options = new HashMap<Object,Object>();
        options.put(ResenderModule.OPTION_CAUSE, cause);
        options.put(ResenderModule.OPTION_INITIAL_SENDER, this);
        options.put(ResenderModule.OPTION_RESEND_METHOD, how);
        options.put(ResenderModule.OPTION_RETRIES, "" + tries);
        getSession().getProcessor().handle(ResenderModule.DO_RESEND, msg, options);
        return true;
    }
}

@@ -45,1543 +45,150 @@
 ort 
-java.util.HashMap;%0D%0Aimport java.util.Map;%0D%0A%0D%0Aimport org.openas2.message.Message;%0D%0Aimport org.openas2.OpenAS2Exception;%0D%0Aimport org.openas2.processor.BaseProcessorModule;%0D%0Aimport org.openas2.processor.resender.ResenderModule;%0D%0A%0D%0A%0D%0Apublic abstract class BaseSenderModule extends BaseProcessorModule implements SenderModule %7B%0D%0A%09%0D%0A%09// How many times should this message be sent?%0D%0A%09protected int retries (Map%3CObject,Object%3E options) %7B%0D%0A%09%09String left;%0D%0A%09%09if (options == null %7C%7C (left = (String) options.get(SenderModule.SOPT_RETRIES)) == null) %7B%0D%0A%09%09%09try %7B%0D%0A%09%09%09%09left = getParameter (SenderModule.SOPT_RETRIES, false);%0D%0A%09%09%09%7D%0D%0A%09%09%09catch (OpenAS2Exception e) %7B%0D%0A%09%09%09%09// Can't actualy happen, but try convincing Java of that.%0D%0A%09%09%09%09// *FIXME* should have two versions of getParameter, one that can't throw.%0D%0A%09%09%09%09left = null;%0D%0A%09%09%09%7D%0D%0A%09%09%09%0D%0A%09%09%09if (left == null) left = SenderModule.DEFAULT_RETRIES;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09return Integer.parseInt(left);%09%0D%0A%09%7D%0D%0A%09%0D%0A    protected boolean resend(String how, Message msg, OpenAS2Exception cause, int tries) throws OpenAS2Exception %7B%0D%0A    %09if (tries %3E= 0 && tries -- %3C= 0) return false;%0D%0A        Map%3CObject,Object%3E options = new HashMap%3CObject,Object%3E();%0D%0A        options.put(ResenderModule.OPTION_CAUSE, cause);%0D%0A        options.put(ResenderModule.OPTION_INITIAL_SENDER, this);%0D%0A        options.put(ResenderModule.OPTION_RESEND_METHOD, how);%0D%0A        options.put(ResenderModule.OPTION_RETRIES, %22%22 + tries);%0D%0A        getSession().getProcessor().handle(ResenderModule.DO_RESEND, msg, options);%0D%0A        return true;%0D%0A    %7D
+org.openas2.processor.BaseProcessorModule;%0D%0A%0D%0Apublic abstract class BaseSenderModule extends BaseProcessorModule implements SenderModule %7B%0D%0A%09%09
 %0D%0A%7D%0D

Support configurable resend retry