/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * %W% %E%
 */

package com.sun.cts.harness.vehicle.ejb;

import com.sun.cts.harness.*;
import com.sun.cts.harness.EETest;
import com.sun.cts.util.*;
import java.io.*;
import java.net.*;
import java.rmi.Remote;
import javax.ejb.*;
import java.util.*;
import javasoft.sqe.javatest.Status;

public class EJBVehicle implements SessionBean
{
	private EETest testObj;
	private Properties properties;
	//private String arguments;
	private String[] arguments; //am trying it now (-- doesn't work -- Vella )
	
	//public void ejbCreate(EETest testImpl, String args, Properties p) throws CreateException
	// The call below does not work because of problems with with passing arraysin J2EE's rmi-iiop??? -- Vella
	public void ejbCreate(EETest testImpl, String[] args, Properties p) throws CreateException
	{
		//Initialize TestUtil Reporting
		try 
		{	
			TestUtil.init(p);
		}
		catch (Exception e) 
		{
		    TestUtil.logErr("initLogging failed in ejb vehicle.", e);
			throw new EJBException();
		}
		
		arguments = args;
		properties = p;
		testObj = testImpl;

	    TestUtil.logTrace( "ejbcreate");
	}
	
	//the run method that we call here will either throw
	//an exception (failed), or return void (pass)
	//we need to somehow return a status to the script...
	public RemoteStatus runTest() 
    {
		RemoteStatus sTestStatus = new RemoteStatus(Status.passed(""));

	    TestUtil.logTrace("in runTest()" );

		try
		{
			//call EETest impl's run method
			//String[] myargs={arguments};
			//sTestStatus = new RemoteStatus(testObj.run(myargs, properties));
			sTestStatus = new RemoteStatus(testObj.run(arguments, properties));
			
			if(sTestStatus.getType() == Status.PASSED)
				TestUtil.logMsg("Test running in ejb vehicle passed");
			else
				TestUtil.logMsg("Test running in ejb vehicle failed");
		}
		catch(Exception e)
		{	
			e.printStackTrace();
			TestUtil.logErr("Test running in ejb vehicle failed", e);
			sTestStatus = new RemoteStatus(Status.failed("Test running in ejb vehicle failed")); 
		}
		finally
		{
			return sTestStatus;
		}
	}
	
	public void setSessionContext(SessionContext sc) 
	{
	}
	
	public void ejbRemove() 
	{
	}
	
	public void ejbActivate() 
	{
	}
	
	public void ejbPassivate() 
	{
	}
}
