package com.eactive.eai.transformer.function.crypto;

import java.util.Stack;

import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;

import com.eactive.eai.transformer.function.util.XdbCrypto;


public class XdbEncrypt extends PostfixMathCommand {
    public XdbEncrypt() {
        numberOfParameters = 1;
    }

    public void run(Stack inStack) throws ParseException {
        checkStack(inStack);

        Object text = inStack.pop();
        
        /**
         * check text
         */
        if (!(text instanceof String))
        	throw new ParseException("1st parameter (data) must be String data type");
        
        String value = (String)text;

        /**
         * encrypt
         */
        try {
        	inStack.push(XdbCrypto.getInstance().encrypt(value));
        } catch (Exception e) {
            throw new ParseException(e.getMessage(), e);
        }    	
    }    
}