package com.eactive.eai.transformer.message;

import com.eactive.eai.transformer.util.CommonLib;
import com.eactive.eai.transformer.util.Constants;

public class MessageSetDataException extends MessageException {
    private Message m;
    private Object data;

    public MessageSetDataException(String message) {
        super(message);
    }

    public MessageSetDataException(String message, Message m, Object data) {
        super(message);
        this.m = m;
        this.data = data;
    }
    
    public MessageSetDataException(String message, Message m, Object data, Throwable cause) {
        super(message, cause);
        this.m = m;
        this.data = data;
    }

    public String getMessage() {
//        return super.getMessage() + " - cannot set data to message(" + (m==null ? "" : m.getName()) + ")";
        return super.getMessage();
    }
    
    public String toString() {
    	StringBuffer sb = new StringBuffer(); 
    	//sb.append(getClass().getName() + ": ");
    	sb.append(getMessage());
    	
    	sb.append(dumpMessage(m));
    	
    	if (data == null) {
    	} else if (data instanceof byte[]){
    		sb.append("\ndata to set : ");
            sb.append("\n" + Constants.TAB + " +--------------------------------------------------------------------------------------------------+");
            sb.append("\n" + Constants.TAB + " | data=");
            sb.append(CommonLib.hexDumpTab((byte[]) data));
            sb.append("\n" + Constants.TAB + " +--------------------------------------------------------------------------------------------------+");
    	} else {
    		sb.append("\ndata to set : ");
    		sb.append(data.toString());
    	}
    	
    	return sb.toString();
    }
}
