/*
 * Created on December 11, 2003
 *
 * ConnectionRequestInfoImpl.java is used to test the J2EE Connector 1.5
 * as implemented by JOnAS. 
 */
package ersatz.resourceadapter;

import javax.naming.Reference;
import javax.resource.spi.ConnectionRequestInfo;

/**
 * @author Bob Kruse
 *
 * used to test the J2EE Connector as implemented by JOnAS.
 *
 */
public class ConnectionRequestInfoImpl implements ConnectionRequestInfo
{
	Reference reference;
	// Resource adapter name form EIS_URL <config-property>
	public String raName="";
    // Managed Connection Factory <config-property>s
    String serverName="";
    String portNumber="";
    String userName="";  
    String password="";
    String protocol="";
    
    String Id="";  // used in hashcode() for ConnectionRequestInfo
    String cName = "ConnectionRequestInfoImpl";
    //
    // constructor  
    public ConnectionRequestInfoImpl()
    {
        Id="";
        Utility.log(cName+"() "+this ); 
    }
    public ConnectionRequestInfoImpl(ConnectionRequestInfoImpl crii)
    {
        raName=crii.raName;
        serverName=crii.serverName;
        portNumber=crii.portNumber;
        userName  =crii.userName ; 
        password  =crii.password ; 
        protocol  =crii.protocol ;
        Id        ="";
        Utility.log(cName+"(crii) "+this); 
        
    }

    //          module to add additional connection properties than   
    //          the ones configured for the ConnectionFactory.  This  
    //          class is passed to the App Server and will be used    
    //          on matchManagedConnections or createConnection        
    //          methods by the App Server.                            
    //                                                                
    //
    public void setUserName(String u) {
        userName=u;
        Utility.log(cName+".setUserName="+u);
    }
    public void setPassword(String p) {
        password=p;
        Utility.log(cName+".setPassword="+p);
    }
    public  String getUserName() {
        Utility.log(cName+".getUserName="+userName);
        return userName;
    }
    public String getPassword() {
        Utility.log(cName+".getPassword="+password);
        return password;
    }
    public void setRaName(String s) {
        raName=s;
    }    
    public void setServerName(String s) {
        serverName=s;
    }    
    public void setPortNumber(String s) {
        portNumber=s;
    }    
    public void setProtocol(String s) {
        protocol=s;
    }    
    public String getRaName() {
        return raName;
    }    
    public String getServerName() {
        return serverName;
    }    
    public String getPortNumber() {
        return portNumber;
    }    
    public String getProtocol() {
        return protocol;
    }    
    private void setId()
    {
        if (Id == null || Id.length() == 0)
            Id=raName + serverName + portNumber + userName + password + protocol;
        
    }
    public String getId()
    {
        setId();
        return Id;
        
    }
    //
    // hashCode and equals method used in ConnectionRequestInfo,
    //                                    ManagedConnectionFactory
    public int hashCode() 
    {
        setId();
        int hash = Id.hashCode();
        return hash;
    }
    public boolean equals(Object obj) 
    {
        boolean ret = false;
        if (obj!=null) {
            if ( obj instanceof ConnectionRequestInfoImpl) {
                ConnectionRequestInfoImpl other = (ConnectionRequestInfoImpl)obj;
                try {
                   ret= raName.equalsIgnoreCase(other.raName) &&
                        serverName.equalsIgnoreCase(other.serverName) &&
                        portNumber.equalsIgnoreCase(other.portNumber) &&
                        userName.equalsIgnoreCase(other.userName) &&
                        password.equalsIgnoreCase(other.password) &&
                        protocol.equalsIgnoreCase(other.protocol);
                } catch (Exception e) {
                    ret=false;
                }
            }
        }
        Utility.log(cName+".equals "+ret);
        return ret;
    }

}