package com.eactive.eai.inbound.processor;

import org.apache.commons.lang3.StringUtils;

import com.eactive.eai.common.server.Keys;
import com.eactive.eai.message.StandardMessageUtil;

@SuppressWarnings("unchecked")
public class ProcessorFactory 
{ 
    private static Processor processor ;
    static{
        Class<Processor> processorClass = null;
        try {
        	if (Keys.EAI_SYSTEM_TYPE_GW.equals(System.getProperty(Keys.EAI_SYSTEM_TYPE))) {
        		processorClass = (Class<Processor>) Class.forName("com.eactive.eai.inbound.processor.GWRequestProcessor");
        	} else if (StringUtils.isBlank(StandardMessageUtil.requestProcessorClass)) {
        		processorClass = (Class<Processor>) Class.forName("com.eactive.eai.inbound.processor.RequestProcessor");
        	} else {
        		processorClass = (Class<Processor>) Class.forName(StandardMessageUtil.requestProcessorClass);
        	}
            
            processor = processorClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private ProcessorFactory() {
    }
    
    public static Processor newInstance() {
        return processor;
    }
} 
