/*
 * Created on January 12, 2004
 *
 * ActivationSpecImpl.java is used to test JCA 1.5
 * as implemented by JOnAS. This class implements the ActivationSpec Interface
 *  
 *  An ActivationSpec JavaBean represents inbound connectivity information from 
 *  an EIS instance
 */
package ersatz.resourceadapter;

import javax.resource.ResourceException;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ActivationSpec;

    // ActivationSpec interface extends ResourceAdapterAssociation interface.

public class ActivationSpecImpl implements ActivationSpec,
                                           java.io.Serializable 
{
    private transient ResourceAdapter ra = null;   // loaded by Application Server
    private boolean raLoaded;
    private String messageObjectType;
    String cName = "ActivationSpecImpl";
    ResourceAdapterImpl rai;
    
    public ActivationSpecImpl()
    {
        Utility.log(cName+".constructor");
    }
    public void validate() 
	    throws javax.resource.spi.InvalidPropertyException 
    { 
        Utility.log(cName+".validate. eis="+rai.EIS_URL);
    }
    public ResourceAdapter getResourceAdapter()
    {
        return ra;
    }
    /** Set the ResourceAdapter association.
     *
     *  @param   ra    ResourceAdapter passed in by Application Server (JOnAS)
     *  @exception     javax.resource.ResourceException                
    **/
    public void setResourceAdapter(ResourceAdapter ra) throws ResourceException
    {
        Utility.log(cName+".setResourceAdapter arg="+ra);
        rai = (ResourceAdapterImpl)ra;
        if (ra==null) {
            String s = "Application Server cannot set ResourceAdapter to null";
            Utility.log(cName+".setResourceAdapter error: "+s);
            throw new ResourceException(s);
        }
        if (this.ra==null)  {
            this.ra = ra;
        } else if (this.ra != ra) {
            String s = "ResourceAdapter already set to "+this.ra
                       +". Must not change association";
            Utility.log(cName+".setResourceAdapter error: "+s);
            throw new ResourceException(s);
        }    
    }
    
    // test "setter" methods in Message Driven Bean MessageTakerMD.java
    // as specified in deployment descriptor 
    //
    public void setFormat(String f) {
        messageObjectType=f;  // f="String"
    }
    public String getFormat() {
        return messageObjectType;
    }
     // TODO ...other methods
}