/********************************************************************************
 *                                                                              *
 *  COPYRIGHT (C) 1997-2002 FUJITSU SOFTWARE CORPORATION.  ALL RIGHTS RESERVED. *
 *                                                                              *
 ********************************************************************************/
package com.fujitsu.iflowqa.testframe;

import java.io.FileOutputStream;
import java.io.PrintWriter;

import com.fujitsu.iflow.server.intf.ActionAgentIntf;
import com.fujitsu.iflow.server.intf.IflowEnactmentContextIntf;

/*
    Objective: To Test The functionality of Action Agent.
    Return the first choice.       
                
*/
public class TestFrameAgent implements ActionAgentIntf {
    
    public TestFrameAgent() 
    {
        print("********* AgentTest(" + this.hashCode() + ")**********\n", null);
    }
    
    public String invokeService(
            IflowEnactmentContextIntf iec,
            String configFile) throws Exception
    {  
        try {
              String choices[] = iec.getChoices();
              return choices[0];      
        }
        catch(Exception e){
            print("Exception in InvokeService" + e.getMessage(), e);
            throw e;
        }
       
    }
   
    
    private
    void
    print(String text, Exception e){
         String outFile = null;
         try{
            outFile = "AgentLog.log";
            FileOutputStream fout = new java.io.FileOutputStream(outFile, true);
            PrintWriter outStream = new java.io.PrintWriter (fout, true);
            if(text != null)
                outStream.print(text);
            if(e != null)
                e.printStackTrace(outStream);
            outStream.close();
            fout.close();
        }
        catch(Exception e1){
            System.out.println("Failed to write in File: " + outFile + "\n Result: " 
                        + text);
        }
    }
}