/*
 * Created on January 27, 2004
 *
 * WorkAdapter.java is used to test JCA 1.5 as implemented by 
 * JOnAS. This class implements the WorkListener Interface
 *  
 */
package ersatz.resourceadapter;

import javax.resource.spi.work.WorkEvent;
import javax.resource.spi.work.WorkAdapter;
import javax.resource.spi.work.WorkException;

/**
 * @author Bob Kruse
 *
 * JCA1.5 WorkAdapter interface
 *
 * used to test the J2EE Connector as implemented by JOnAS.
 *
 *           This is the "WorkListener"
 *
 */
public class WorkAdapterImpl extends WorkAdapter
{
    String cName = "WorkAdapterImpl";
    WorkImpl wi;
    WorkException wex;
    /*   
        e.getType() returns these values
        
        int WORK_ACCEPTED = 1;
        int WORK_REJECTED = 2;
        int WORK_STARTED = 3;
        int WORK_COMPLETED = 4;
    */

    public void workStarted(WorkEvent e)
    { 
        wex=e.getException();
        if (wex==null) {
            // no exception occurred
            wi=(WorkImpl)e.getWork();
            Utility.log(cName+".workStarted for WorkEvent Work content="
                             +wi.getWorkType()+", "+e.getType());
        } else {
            Utility.log(cName+".workStarted WorkException="+wex);
        }
    }
    public void workAccepted(WorkEvent e)
    { 
        wex=e.getException();
        if (wex==null) {
            // no exception occurred
            wi=(WorkImpl)e.getWork();
            Utility.log(cName+".workAccepted for WorkEvent Work content="
                             +wi.getWorkType()+", "+e.getType());
        } else {
            Utility.log(cName+".workAccepted WorkException="+wex);
        }
    }
    public void workRejected(WorkEvent e)
    { 
        wex=e.getException();
        if (wex==null) {
            // no exception occurred
            wi=(WorkImpl)e.getWork();
            Utility.log(cName+".workRejected for WorkEvent Work content="
                             +wi.getWorkType()+", "+e.getType());
        } else {
            Utility.log(cName+".workRejected WorkException="+wex);
        }
    }
    public void workCompleted(WorkEvent e)
    { 
        wex=e.getException();
        if (wex==null) {
            // no exception occurred
            wi=(WorkImpl)e.getWork();
            Utility.log(cName+".workCompleted for WorkEvent Work content="
                             +wi.getWorkType()+", "+e.getType());
        } else {
            Utility.log(cName+".workCompleted WorkException="+wex);
        }
    }
}