package JawinTest;

import com.develop.jawin.*;
import com.develop.jawin.constants.*;
import java.util.Date;
import java.math.*;

public class Test {
    public static void main(String[] args) {
        String[] str = null;
        ObjectRef objRef = null;
        ObjectRef objNew = null;
        _sJawinTest oResult = null;
        ObjectRef currencyRef = null;
        try{
            _sJawinTest oJawinTest = new _sJawinTest("JawinTest.sJawinTest");
            oJawinTest.addEventListener(__sJawinTest.class, new sJawinTestListener());
            oJawinTest.ShowMsgBox();
            oJawinTest.RaiseMyEvent();
            objRef = new ObjectRef(new String[]{});
            oJawinTest.ReturnStringArray(objRef);
            if(objRef.getRef() instanceof String[]) {
                String[] stra = (String[])objRef.getRef();
                System.out.println("Array from VB:");
                for(int i = 0; i < stra.length; i++)
                    System.out.println("("+i+")"+stra[i]);
            }
            Date oJavaDate = new Date();
            System.out.println(oJavaDate.toString());
            oJavaDate.setDate(30);
            oJavaDate.setMonth(3);
            oJavaDate.setYear(75);
            oJavaDate.setHours(4);
            oJavaDate.setMinutes(37);
            oJavaDate.setSeconds(12);
            System.out.println(oJavaDate.toString());
            oJawinTest.TestsOptionalVariants(DispatchConstants.vtMissing, oJavaDate);
            objNew = new ObjectRef(null);
            oJawinTest.GetObject(objNew);
            oResult = new _sJawinTest((DispatchPtr)objNew.getRef());
            oResult.ShowMsgBox();
            _sJawinTest oJawinTest2 = new _sJawinTest("JawinTest.sJawinTest");
            oJawinTest2.CallInside(new ObjectRef(oJawinTest2));
            // Currency Number: 1000000.0000
            oJawinTest.PassCurrency(new BigInteger("10000000000"));
            currencyRef = new ObjectRef(new BigInteger("0"));
            oJawinTest.GetCurrency(currencyRef);
            System.out.println("Currency result from VB:" + ((BigInteger)currencyRef.getRef()).divide(new BigInteger("10000")).toString());
        }
        catch(COMException e){
            System.out.println("oJawinTest failure");
            e.printStackTrace();
            System.out.println(e.toString());
        }
        System.exit(0);
    }
}
class sJawinTestListener implements __sJawinTest {
    public void Start(Object srcObj, ObjectRef  sStartParam) throws COMException {
        try{
            System.out.println("Start event fired: Start(" + sStartParam + ")");
            _sJawinTest oJawinTest2 = new _sJawinTest("JawinTest.sJawinTest");
            int i = 0;
            int iParam = 0;
            ObjectRef oParam = new ObjectRef(iParam);
            int iParam2 = 0;
            ObjectRef oParam2 = new ObjectRef(iParam2);
            ObjectRef strObject = new ObjectRef(new String());
            _sJawinTest source = (_sJawinTest)srcObj;
            i = source.LongReturn(oParam, oParam2, strObject, oJawinTest2);
            System.out.print(i + " == LongReturn(" + oParam.getRef().toString() + ", ");
            System.out.println(oParam2.getRef().toString() + ", \"" + strObject.getRef().toString() + "\", oJawinTest2)");
        }
        catch(Throwable e){
            System.out.println("oJawinTest failure");
            e.printStackTrace();
            System.out.println(e.toString());
        }
    }
}
