package com.eactive.eai.flowcontrol.action;

import com.eactive.eai.common.util.Logger;

public class RouteActionSupport implements RouteAction {
	static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
    
	public String[] getRouteKeys(byte[] message) throws Exception {
		
		String[] keys = null;
        
        return keys;        
	}
	
	public int strncmp(String src, String value, int length) {
		int result = -1;
		
		if(src == null || value == null) {
			return -1;
		}
		
		if(src.length() < length) {
			return -1;
		}
		
		if(src.startsWith(value)) {
			result = 0;
		}
		return result;
	}
	
	public String strncpy(String src, String value, int startPos) {

		if(value == null || value.length() < 1) {
			return src;
		}
		StringBuffer sb = new StringBuffer();
		sb.append(src.substring(0,startPos));
		sb.append(value);
		sb.append( src.substring(startPos+value.length()) );
		return sb.toString();
	}
	
	public String strncpy(byte[] src, int startPos, int length) {
		
		
		if(src == null || src.length <(startPos + length)) {
			return "";
		}
		
		byte[] resBytes = new byte[length];
		
		System.arraycopy(src, startPos, resBytes, 0, resBytes.length );
		
		return new String(resBytes);
	}

	public boolean bytesncmp(byte[] src, int startPos, String value) {
		
		if(value == null || value.length() < 1) {
			return false;
		}

		byte[] valueBytes = value.getBytes();
		int valueBytesLength = valueBytes.length;
		
		if(src == null || src.length <(startPos + valueBytesLength)) {
			return false;
		}
		
		byte[] cmpareBytes = new byte[valueBytesLength];
		
		System.arraycopy(src, startPos, cmpareBytes, 0, cmpareBytes.length );
		if(value.equals(new String(cmpareBytes))) {
			return true;
		}
		
		return false;
	}
	
	public String getDescription() {
		return "";
	}
}
