package com.eactive.eai.transformer.engine;

import com.eactive.eai.transformer.TransformerException;
import com.eactive.eai.transformer.message.Message;


public class TransformException extends TransformerException {
    private String transformName;
    private Message resultMessage;
    private Message[] sourceMessages;
    private TransformOption option;

    public TransformException(String message, String transformName,
        Message resultMessage, Message[] sourceMessages, TransformOption option) {
        this(message, transformName, resultMessage, sourceMessages, option, null);
    }

    public TransformException(String message, String transformName,
        Message resultMessage, Message[] sourceMessages,
        TransformOption option, Throwable cause) {
        super(message, cause);
        this.transformName = transformName;
        this.resultMessage = resultMessage;
        this.sourceMessages = sourceMessages;
        this.option = option;
    }

    public String getTransformName() {
        return transformName;
    }

    public boolean hasResultMessage() {
        return (resultMessage != null);
    }

    public Message getResultMessage() {
        return resultMessage;
    }

    public Message[] getSourceMessages() {
        return sourceMessages;
    }

    public boolean hasTransformOption() {
        return (option != null);
    }

    public TransformOption getTransformOption() {
        return option;
    }
    
    @Override
    public String getMessage() {
    	StringBuilder sb = new StringBuilder();
    	sb.append("\n전문레이아웃매핑=" + transformName);
    	sb.append(", 원천전문레이아웃=");
    	for (int i=0; i<sourceMessages.length; i++) {
    		sb.append("|" + sourceMessages[i].getName());
    	}
    	if (resultMessage != null) {
    		sb.append(", 타겟전문레이아웃=" + resultMessage.getName());
    	}
    	sb.append(super.getMessage());
    	return sb.toString();
    }
}
